git-push-time 1.1.0 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/ui.js CHANGED
@@ -1,844 +1,1063 @@
1
- import chalk from "chalk";
2
- import stringWidth from "string-width";
3
-
4
- /**
5
- * Tự động tính toán chiều rộng card linh hoạt theo Terminal (68 - 80 ký tự)
6
- */
7
- export function getW() {
8
- const cols = process.stdout.columns || 72;
9
- return Math.min(80, Math.max(66, cols - 4));
10
- }
11
-
12
- function hexToRgb(hex) {
13
- const n = parseInt(hex.replace("#", ""), 16);
14
- return [(n >> 16) & 255, (n >> 8) & 255, n & 255];
15
- }
16
-
17
- /**
18
- * Tạo gradient màu mượt mà theo chuẩn RGB Interpolation
19
- */
20
- export function multiGradient(
21
- text,
22
- colors = ["#C084FC", "#6366F1", "#38BDF8", "#34D399"],
23
- ) {
24
- const chars = [...text];
25
- const len = chars.length || 1;
26
- const rgbColors = colors.map(hexToRgb);
27
-
28
- return chars
29
- .map((c, i) => {
30
- const t = (i / (len - 1 || 1)) * (rgbColors.length - 1);
31
- const idx = Math.min(Math.floor(t), rgbColors.length - 2);
32
- const localT = t - idx;
33
- const [r1, g1, b1] = rgbColors[idx];
34
- const [r2, g2, b2] = rgbColors[idx + 1];
35
- const r = Math.round(r1 + (r2 - r1) * localT);
36
- const g = Math.round(g1 + (g2 - g1) * localT);
37
- const b = Math.round(b1 + (b2 - b1) * localT);
38
- return chalk.rgb(r, g, b)(c);
39
- })
40
- .join("");
41
- }
42
-
43
- export function pad(str, len) {
44
- const vLen = stringWidth(str);
45
- if (vLen >= len) return str;
46
- return str + " ".repeat(len - vLen);
47
- }
48
-
49
- export function truncateVisual(str, maxLen) {
50
- if (stringWidth(str) <= maxLen) return str;
51
- let res = "";
52
- for (const ch of str) {
53
- if (stringWidth(res + ch + "…") > maxLen) {
54
- return res + "…";
55
- }
56
- res += ch;
57
- }
58
- return res + "…";
59
- }
60
-
61
- /* ==========================================================================
62
- BOX ENGINE CHUẨN (Bo góc mềm & Căn lề pixel-perfect)
63
- ========================================================================== */
64
-
65
- export function boxTop(title = "", borderColor = chalk.hex("#334155")) {
66
- const W = getW();
67
- if (!title) return borderColor("╭" + "─".repeat(W - 2) + "╮");
68
-
69
- const titleWidth = stringWidth(title);
70
- const leftDash = "─".repeat(3);
71
- const rightDashLen = Math.max(0, W - 2 - 3 - titleWidth);
72
- return (
73
- borderColor("╭" + leftDash) +
74
- title +
75
- borderColor("─".repeat(rightDashLen) + "╮")
76
- );
77
- }
78
-
79
- export function boxBottom(borderColor = chalk.hex("#334155")) {
80
- const W = getW();
81
- return borderColor("╰" + "─".repeat(W - 2) + "╯");
82
- }
83
-
84
- export function boxRow(content = "", borderColor = chalk.hex("#334155")) {
85
- const W = getW();
86
- return borderColor("│ ") + pad(content, W - 4) + borderColor(" │");
87
- }
88
-
89
- export function boxDivider(borderColor = chalk.hex("#334155")) {
90
- const W = getW();
91
- return borderColor("├" + "─".repeat(W - 2) + "┤");
92
- }
93
-
94
- /**
95
- * Hàng Key-Value có đường nối bằng dấu chấm ․ ․ ․
96
- */
97
- export function boxKvDot(
98
- label,
99
- value,
100
- labelWidth = 16,
101
- borderColor = chalk.hex("#334155"),
102
- ) {
103
- const W = getW();
104
- const maxValWidth = Math.max(10, W - 6 - labelWidth);
105
- const truncatedVal = truncateVisual(value, maxValWidth);
106
- const valWidth = stringWidth(truncatedVal);
107
-
108
- const dotsLen = Math.max(1, W - 6 - labelWidth - valWidth);
109
- const dots = chalk.hex("#1E293B")("․".repeat(dotsLen));
110
- const formattedLabel = chalk.hex("#94A3B8")(pad(label, labelWidth));
111
-
112
- return boxRow(`${formattedLabel}${dots}${truncatedVal}`, borderColor);
113
- }
114
-
115
- /* ==========================================================================
116
- PUBLIC INTERFACE & BANNER
117
- ========================================================================== */
118
-
119
- /**
120
- * Banner DevTools sắc nét, hiện đại
121
- */
122
- export function printBanner(version = "1.1.0") {
123
- const ascii = [
124
- " ____ _ _ ____ _ _____ _ ",
125
- " / ___(_) |_ | _ \\ _ _ ___| |__ |_ _(_)_ __ ___ ___ ",
126
- " | | _| | __| | |_) | | | / __| '_ \\ | | | | '_ ` _ \\ / _ \\ ",
127
- " | |_| | | |_ | __/| |_| \\__ \\ | | | | | | | | | | | | __/ ",
128
- " \\____|_|\\__| |_| \\__,_|___/_| |_| |_| |_|_| |_| |_|\\___| ",
129
- ];
130
-
131
- console.log("");
132
- const colors = ["#818CF8", "#38BDF8", "#34D399", "#A7F3D0"];
133
- ascii.forEach((l) => console.log(multiGradient(l, colors)));
134
-
135
- const badgeVer = chalk.bgHex("#1E1B4B").hex("#818CF8").bold(` v${version} `);
136
- const badgeGit = chalk.bgHex("#064E3B").hex("#34D399").bold(" SMART GIT ");
137
- const badgeHub = chalk.bgHex("#4338CA").hex("#C7D2FE").bold(" GITHUB SYNC ");
138
- const badgeShield = chalk.bgHex("#0F172A").hex("#38BDF8").bold(" SECRET SHIELD ");
139
- const badgeDate = chalk.bgHex("#78350F").hex("#FDE047").bold(" BACKDATE ");
140
-
141
- console.log(`\n ${badgeVer} ${badgeGit} ${badgeHub} ${badgeShield} ${badgeDate}\n`);
142
- }
143
-
144
- /**
145
- * Hiển thị Dashboard trạng thái ngắn gọn ở đầu menu
146
- */
147
- export function printDashboardStatus({ targetDir = process.cwd(), currentBranch = 'main', githubUser = null }) {
148
- const border = chalk.hex("#1E293B");
149
- const W = getW();
150
-
151
- const dirName = truncateVisual(targetDir, 32);
152
- const branchText = chalk.hex("#38BDF8").bold(currentBranch);
153
-
154
- let ghStatusText;
155
- if (githubUser) {
156
- ghStatusText = chalk.hex("#34D399").bold(`@${githubUser.login}`) + chalk.hex("#64748B")(' (Đã kết nối)');
157
- } else {
158
- ghStatusText = chalk.hex("#94A3B8")('Chưa kết nối') + chalk.hex("#64748B")(' [chọn mục GITHUB để login]');
159
- }
160
-
161
- console.log(boxTop(chalk.hex("#475569")(" [ TRẠNG THÁI ] "), border));
162
- console.log(boxKvDot("Thư mục", chalk.hex("#F8FAFC")(dirName), 14, border));
163
- console.log(boxKvDot("Nhánh (Branch)", branchText, 14, border));
164
- console.log(boxKvDot("GitHub Account", ghStatusText, 14, border));
165
- console.log(boxBottom(border));
166
- }
167
-
168
- /**
169
- * Tiêu đề phân đoạn với điểm nhấn màu sắc
170
- */
171
- export function printSection(title) {
172
- const W = getW();
173
- const clean = String(title || "").toUpperCase();
174
- const marker = chalk.hex("#38BDF8").bold("»");
175
- const titleStyled = chalk.bold.hex("#F8FAFC")(` ${clean} `);
176
- const prefix = chalk.hex("#334155")("── ") + marker + titleStyled;
177
- const remaining = Math.max(0, W - stringWidth(prefix));
178
- console.log("");
179
- console.log(prefix + chalk.hex("#334155")("─".repeat(remaining)));
180
- }
181
-
182
- /**
183
- * Pill Step Badge (Ví dụ: 1/6)
184
- */
185
- export function stepLabel(current, total, text) {
186
- const pill = chalk
187
- .bgHex("#2563EB")
188
- .hex("#FFFFFF")
189
- .bold(` ${current}/${total} `);
190
- return `${pill} ` + chalk.hex("#F1F5F9").bold(text);
191
- }
192
-
193
- /**
194
- * Bảng tóm tắt thông tin trước khi Push
195
- */
196
- export function printSummary({
197
- repoUrl,
198
- commitMsg,
199
- dateDisplay,
200
- branch,
201
- force,
202
- sourceDir,
203
- }) {
204
- const border = chalk.hex("#475569");
205
- const title = chalk.bold.bgHex("#4338CA").hex("#FFFFFF")(
206
- " XÁC NHẬN THÔNG TIN ĐẨY DỰ ÁN ",
207
- );
208
-
209
- console.log("");
210
- console.log(boxTop(title, border));
211
-
212
- if (sourceDir) {
213
- console.log(
214
- boxKvDot("Thư mục nguồn", chalk.hex("#34D399")(sourceDir), 16, border),
215
- );
216
- }
217
- console.log(
218
- boxKvDot(
219
- "Git Repository",
220
- chalk.hex("#38BDF8").underline(repoUrl),
221
- 16,
222
- border,
223
- ),
224
- );
225
- console.log(
226
- boxKvDot("Commit Message", chalk.hex("#FBBF24").bold(commitMsg), 16, border),
227
- );
228
- console.log(
229
- boxKvDot("Thời gian", chalk.hex("#C084FC")(dateDisplay), 16, border),
230
- );
231
-
232
- const branchPill = chalk
233
- .bgHex("#065F46")
234
- .hex("#6EE7B7")
235
- .bold(` ${branch} `);
236
- console.log(boxKvDot("Nhánh đẩy lên", branchPill, 16, border));
237
-
238
- const forceText = force
239
- ? chalk.bgHex("#991B1B").hex("#FCA5A5").bold(" BẬT (--force) [!] ")
240
- : chalk.hex("#64748B")("Tắt (chế độ an toàn)");
241
- console.log(boxKvDot("Ghi đè (Force)", forceText, 16, border));
242
-
243
- console.log(boxBottom(border));
244
- }
245
-
246
- export function printTargetDir(dir = "") {
247
- const W = getW();
248
- console.log(
249
- chalk.hex("#64748B")(
250
- ` » Folder: ${truncateVisual(String(dir || ""), W - 13)}`,
251
- ),
252
- );
253
- }
254
-
255
- /**
256
- * Hiển thị thẻ Profile thông tin tài khoản GitHub
257
- */
258
- export function printGitHubProfile(user, source = '') {
259
- const border = chalk.hex("#4F46E5");
260
- const title = chalk.bold.bgHex("#4F46E5").hex("#FFFFFF")(
261
- " TÀI KHOẢN GITHUB KẾT NỐI ",
262
- );
263
-
264
- console.log("");
265
- console.log(boxTop(title, border));
266
-
267
- console.log(
268
- boxKvDot("Username", chalk.hex("#38BDF8").bold(`@${user.login}`), 16, border)
269
- );
270
- if (user.name) {
271
- console.log(boxKvDot("Tên hiển thị", chalk.hex("#F8FAFC")(user.name), 16, border));
272
- }
273
- if (user.email) {
274
- console.log(boxKvDot("Email", chalk.hex("#94A3B8")(user.email), 16, border));
275
- }
276
- if (user.bio) {
277
- console.log(boxKvDot("Tiểu sử", chalk.hex("#CBD5E1")(truncateVisual(user.bio, 40)), 16, border));
278
- }
279
-
280
- const repoStats = `${user.public_repos || 0} public • ${user.total_private_repos || 0} private`;
281
- console.log(boxKvDot("Repositories", chalk.hex("#34D399").bold(repoStats), 16, border));
282
-
283
- if (source) {
284
- const srcDesc = source === 'gh-cli' ? 'GitHub CLI (gh)' : source === 'env' ? 'Biến môi trường' : 'Lưu trữ cá nhân';
285
- console.log(boxKvDot("Nguồn xác thực", chalk.hex("#A78BFA")(srcDesc), 16, border));
286
- }
287
-
288
- console.log(boxDivider(border));
289
- console.log(boxRow(chalk.hex("#64748B")(`» Trang cá nhân: ${user.html_url}`), border));
290
- console.log(boxBottom(border));
291
- console.log("");
292
- }
293
-
294
- /**
295
- * Hiển thị mã xác thực GitHub Device Flow cho người dùng
296
- */
297
- export function printDeviceCodePrompt({ userCode, verificationUri }) {
298
- const border = chalk.hex("#6366F1");
299
- const title = chalk.bold.bgHex("#4F46E5").hex("#FFFFFF")(
300
- " GITHUB OAUTH / DEVICE FLOW ",
301
- );
302
-
303
- console.log("");
304
- console.log(boxTop(title, border));
305
- console.log(boxRow("", border));
306
- console.log(boxRow(chalk.hex("#F8FAFC").bold("Bước 1: Mở trình duyệt và truy cập liên kết:"), border));
307
- console.log(boxRow(chalk.hex("#38BDF8").bold.underline(` ${verificationUri}`), border));
308
- console.log(boxRow("", border));
309
- console.log(boxRow(chalk.hex("#F8FAFC").bold("Bước 2: Nhập mã xác nhận (User Code):"), border));
310
-
311
- const codeBox = chalk.bgHex("#1E1B4B").hex("#A5B4FC").bold(` >>> ${userCode} <<< `);
312
- console.log(boxRow(` ${codeBox}`, border));
313
- console.log(boxRow("", border));
314
- console.log(boxRow(chalk.hex("#94A3B8")("» Hệ thống đang tự động mở trình duyệt cho bạn..."), border));
315
- console.log(boxRow(chalk.hex("#64748B")("» Nhấn Authorize trên trình duyệt để hoàn tất."), border));
316
- console.log(boxBottom(border));
317
- console.log("");
318
- }
319
-
320
- /**
321
- * Hiển thị thông báo sau khi tạo repository GitHub mới thành công
322
- */
323
- export function printRepoCreatedBox(repo) {
324
- const border = chalk.hex("#059669");
325
- const title = chalk.bold.bgHex("#10B981").hex("#064E3B")(
326
- " TẠO REPOSITORY GITHUB THÀNH CÔNG! ",
327
- );
328
-
329
- console.log("");
330
- console.log(boxTop(title, border));
331
- console.log(boxRow("", border));
332
-
333
- const visibilityPill = repo.isPrivate
334
- ? chalk.bgHex("#7F1D1D").hex("#FCA5A5").bold(" PRIVATE ")
335
- : chalk.bgHex("#065F46").hex("#6EE7B7").bold(" PUBLIC ");
336
-
337
- console.log(boxKvDot("Tên Repo", chalk.hex("#F8FAFC").bold(repo.fullName || repo.name), 14, border));
338
- console.log(boxKvDot("Quyền riêng tư", visibilityPill, 14, border));
339
- if (repo.description) {
340
- console.log(boxKvDot("Mô tả", chalk.hex("#CBD5E1")(truncateVisual(repo.description, 42)), 14, border));
341
- }
342
- console.log(boxKvDot("HTTPS Clone", chalk.hex("#38BDF8").underline(repo.cloneUrl), 14, border));
343
- console.log(boxKvDot("SSH Clone", chalk.hex("#A78BFA")(repo.sshUrl), 14, border));
344
-
345
- console.log(boxRow("", border));
346
- console.log(boxDivider(border));
347
- console.log(boxRow(chalk.hex("#6EE7B7")(`» Xem trên GitHub: ${repo.htmlUrl}`), border));
348
- console.log(boxBottom(border));
349
- console.log("");
350
- }
351
-
352
- /**
353
- * Cảnh báo Folder lồng trong Repo cha
354
- */
355
- export function printNestedRepoWarning({ targetDir = "", topLevel = "" } = {}) {
356
- const border = chalk.hex("#D97706");
357
- const title = chalk.bold.bgHex("#D97706").hex("#FFFFFF")(
358
- " FOLDER NẰM TRONG REPO CHA ",
359
- );
360
-
361
- console.log("");
362
- console.log(boxTop(title, border));
363
- console.log(
364
- boxRow(
365
- chalk.hex("#FDE047")(
366
- "Folder nguồn đang nằm trong Git repo của folder cha:",
367
- ),
368
- border,
369
- ),
370
- );
371
- console.log(boxKvDot(" +- CHA", chalk.hex("#F8FAFC")(topLevel), 10, border));
372
- console.log(
373
- boxKvDot(" +- CON", chalk.hex("#F8FAFC")(targetDir), 10, border),
374
- );
375
- console.log(boxRow("", border));
376
- console.log(
377
- boxRow(
378
- chalk.hex("#94A3B8")(
379
- "Nếu push tiếp, lịch sử/file của folder cha có thể đi kèm.",
380
- ),
381
- border,
382
- ),
383
- );
384
- console.log(
385
- boxRow(
386
- chalk.hex("#34D399")(
387
- "Gợi ý: Tạo repo RIÊNG để chỉ push folder này.",
388
- ),
389
- border,
390
- ),
391
- );
392
- console.log(boxBottom(border));
393
- }
394
-
395
- /**
396
- * Cảnh báo Secret nhạy cảm
397
- */
398
- export function printPrePushSecretWarning({ riskyFiles = [], findings = [] }) {
399
- const border = chalk.hex("#D97706");
400
- const title = chalk.bold.bgHex("#D97706").hex("#FFFFFF")(
401
- " PHÁT HIỆN DỮ LIỆU NHẠY CẢM ",
402
- );
403
-
404
- console.log("");
405
- console.log(boxTop(title, border));
406
- console.log(
407
- boxRow(
408
- chalk.hex("#FDE047")(
409
- "GitHub có thể chặn push nếu phát hiện key bí mật (GH013)",
410
- ),
411
- border,
412
- ),
413
- );
414
- console.log(boxRow("", border));
415
-
416
- if (riskyFiles.length > 0) {
417
- console.log(
418
- boxRow(chalk.bold.hex("#F8FAFC")("File cấu hình nguy cơ:"), border),
419
- );
420
- const showFiles = riskyFiles.slice(0, 4);
421
- showFiles.forEach((f) => {
422
- const tree = chalk.hex("#64748B")(" +- ");
423
- console.log(
424
- boxRow(tree + chalk.hex("#FCD34D")(truncateVisual(f, 46)), border),
425
- );
426
- });
427
- if (riskyFiles.length > 4) {
428
- console.log(
429
- boxRow(
430
- chalk.hex("#64748B")(` +- ...và ${riskyFiles.length - 4} file khác`),
431
- border,
432
- ),
433
- );
434
- }
435
- }
436
-
437
- if (findings.length > 0) {
438
- if (riskyFiles.length > 0) console.log(boxRow("", border));
439
- console.log(
440
- boxRow(
441
- chalk.bold.hex("#F8FAFC")("Vị trí nghi vấn Secret trong code:"),
442
- border,
443
- ),
444
- );
445
- const showFindings = findings.slice(0, 4);
446
- showFindings.forEach((f, idx) => {
447
- const isLast = idx === showFindings.length - 1;
448
- const tree = chalk.hex("#64748B")(" +- ");
449
- const loc = truncateVisual(`${f.file}:${f.line}`, 26);
450
- console.log(
451
- boxRow(
452
- tree +
453
- chalk.hex("#F8FAFC")(loc) +
454
- chalk.hex("#94A3B8")(` [${f.type}]`),
455
- border,
456
- ),
457
- );
458
- if (f.preview) {
459
- const indent = chalk.hex("#64748B")(isLast ? " " : " | ");
460
- console.log(
461
- boxRow(
462
- indent + chalk.hex("#64748B")(`"${truncateVisual(f.preview, 40)}"`),
463
- border,
464
- ),
465
- );
466
- }
467
- });
468
- if (findings.length > 4) {
469
- console.log(
470
- boxRow(
471
- chalk.hex("#64748B")(` +- ...và ${findings.length - 4} vị trí khác`),
472
- border,
473
- ),
474
- );
475
- }
476
- }
477
-
478
- console.log(boxRow("", border));
479
- console.log(
480
- boxRow(
481
- chalk.hex("#34D399")(
482
- 'Gợi ý: Chọn "Tự động fix" để gỡ file + .gitignore an toàn',
483
- ),
484
- border,
485
- ),
486
- );
487
- console.log(boxBottom(border));
488
- }
489
-
490
- /**
491
- * Cảnh báo Push bị chặn bởi GitHub Push Protection (GH013)
492
- */
493
- export function printSecretBlockedBox(rawMessage, details = {}) {
494
- const border = chalk.hex("#E11D48");
495
- const files = details.files || [];
496
- const types = details.secretTypes || [];
497
- const title = chalk.bold.bgHex("#E11D48").hex("#FFFFFF")(
498
- " PUSH BỊ CHẶN — PHÁT HIỆN SECRET (GH013) ",
499
- );
500
-
501
- console.log("");
502
- console.log(boxTop(title, border));
503
- console.log(
504
- boxRow(
505
- chalk.hex("#FDA4AF")(
506
- "GitHub Push Protection đã chặn push vì phát hiện secret!",
507
- ),
508
- border,
509
- ),
510
- );
511
- console.log(boxRow("", border));
512
-
513
- if (types.length > 0) {
514
- console.log(
515
- boxKvDot(
516
- "Loại secret",
517
- chalk.hex("#F8FAFC").bold(types.slice(0, 2).join(", ")),
518
- 14,
519
- border,
520
- ),
521
- );
522
- }
523
- if (files.length > 0) {
524
- files.slice(0, 2).forEach((f) => {
525
- console.log(
526
- boxKvDot("File nguồn", chalk.hex("#FCD34D")(f), 14, border),
527
- );
528
- });
529
- }
530
-
531
- console.log(boxRow("", border));
532
- console.log(
533
- boxRow(chalk.bold.hex("#F8FAFC")("» Các giải pháp khắc phục:"), border),
534
- );
535
- console.log(
536
- boxRow(
537
- chalk.hex("#E2E8F0")(" [1] Thu hồi (revoke) key ngay nếu là token thật"),
538
- border,
539
- ),
540
- );
541
- console.log(
542
- boxRow(
543
- chalk.hex("#38BDF8")(
544
- " [2] Dùng tool tự động gỡ file & squash làm sạch commit",
545
- ),
546
- border,
547
- ),
548
- );
549
- console.log(
550
- boxRow(
551
- chalk.hex("#94A3B8")(
552
- " [3] Xóa secret trong code / dùng biến môi trường (process.env)",
553
- ),
554
- border,
555
- ),
556
- );
557
-
558
- console.log(boxBottom(border));
559
-
560
- if (details.unblockUrl) {
561
- console.log(
562
- chalk.hex("#F59E0B")(
563
- `\n » URL mở khóa tạm thời (nếu là key mẫu thử nghiệm):\n ${chalk.underline(details.unblockUrl)}`,
564
- ),
565
- );
566
- }
567
- console.log(
568
- chalk.hex("#64748B")(
569
- `\n » Tài liệu GitHub: ${details.resolveUrl || "https://docs.github.com/code-security/secret-scanning/pushing-a-branch-blocked-by-push-protection"}\n`,
570
- ),
571
- );
572
- }
573
-
574
- /**
575
- * Card Thông báo Thành công sau khi Push
576
- */
577
- export function printSuccessBox({ branch, repoUrl }) {
578
- const border = chalk.hex("#059669");
579
- const title = chalk.bold.bgHex("#10B981").hex("#064E3B")(
580
- " ĐẨY DỰ ÁN LÊN GIT THÀNH CÔNG! ",
581
- );
582
-
583
- console.log("");
584
- console.log(boxTop(title, border));
585
- console.log(boxRow("", border));
586
-
587
- const branchPill = chalk.bgHex("#065F46").hex("#6EE7B7").bold(` ${branch} `);
588
- console.log(boxKvDot("Branch", branchPill, 12, border));
589
- console.log(
590
- boxKvDot("Remote", chalk.hex("#38BDF8").underline(repoUrl), 12, border),
591
- );
592
- console.log(
593
- boxKvDot(
594
- "Trạng thái",
595
- chalk.hex("#A7F3D0")("Đồng bộ hoàn tất 100%"),
596
- 12,
597
- border,
598
- ),
599
- );
600
-
601
- console.log(boxRow("", border));
602
- console.log(
603
- boxRow(
604
- chalk.hex("#64748B")("» Xem lịch sử commit: git log -1 --stat"),
605
- border,
606
- ),
607
- );
608
- console.log(boxBottom(border));
609
- console.log("");
610
- }
611
-
612
- export function printCancelled() {
613
- const border = chalk.hex("#D97706");
614
- const title = chalk.bold.bgHex("#D97706").hex("#FFFFFF")(
615
- " ĐÃ HỦY THAO TÁC ",
616
- );
617
- console.log("");
618
- console.log(boxTop(title, border));
619
- console.log(
620
- boxRow(
621
- chalk.hex("#FDE68A")(
622
- "Không có bất kỳ thay đổi nào được thực hiện trên repo.",
623
- ),
624
- border,
625
- ),
626
- );
627
- console.log(boxBottom(border));
628
- console.log("");
629
- }
630
-
631
- export function printErrorBox(title = "XẢY RA LỖI", lines = [], hint = "") {
632
- const W = getW();
633
- const border = chalk.hex("#E11D48");
634
- const cleanTitle = String(title || "").toUpperCase();
635
- const titleStyled = chalk.bold.bgHex("#E11D48").hex("#FFFFFF")(
636
- ` [LỖI] ${cleanTitle} `,
637
- );
638
- const rows = Array.isArray(lines) ? lines : [String(lines || "")];
639
-
640
- console.log("");
641
- console.log(boxTop(titleStyled, border));
642
- rows.forEach((l) => {
643
- if (!l) {
644
- console.log(boxRow("", border));
645
- } else {
646
- console.log(
647
- boxRow(chalk.hex("#FDA4AF")(truncateVisual(String(l), W - 4)), border),
648
- );
649
- }
650
- });
651
- if (hint) {
652
- console.log(boxRow("", border));
653
- console.log(
654
- boxRow(chalk.hex("#38BDF8")(`» ${truncateVisual(hint, W - 6)}`), border),
655
- );
656
- }
657
- console.log(boxBottom(border));
658
- console.log("");
659
- }
660
-
661
- export function printGitMissing() {
662
- printErrorBox(
663
- "CHƯA CÀI ĐẶT GIT",
664
- [
665
- "Không tìm thấy Git trên hệ thống máy tính của bạn.",
666
- "Vui lòng tải và cài đặt Git để tiếp tục!",
667
- ],
668
- "Tải ngay tại: https://git-scm.com/downloads",
669
- );
670
- }
671
-
672
- export function printAuthFailedBox(message = "") {
673
- const border = chalk.hex("#E11D48");
674
- const title = chalk.bold.bgHex("#E11D48").hex("#FFFFFF")(
675
- " LỖI XÁC THỰC GIT ",
676
- );
677
- const firstLine = String(message || "")
678
- .split("\n")[0]
679
- .slice(0, 120);
680
-
681
- console.log("");
682
- console.log(boxTop(title, border));
683
- console.log(
684
- boxRow(
685
- chalk.hex("#FDA4AF")(
686
- "Không thể xác thực với remote. Kiểm tra lại quyền truy cập.",
687
- ),
688
- border,
689
- ),
690
- );
691
- if (firstLine)
692
- console.log(
693
- boxRow(
694
- chalk.hex("#64748B")(truncateVisual(firstLine, getW() - 4)),
695
- border,
696
- ),
697
- );
698
- console.log(boxRow("", border));
699
- console.log(
700
- boxRow(chalk.bold.hex("#F8FAFC")("» Cách khắc phục nhanh:"), border),
701
- );
702
- console.log(
703
- boxRow(
704
- chalk.hex("#E2E8F0")(" [1] Chạy tính năng GITHUB trong tool để kết nối tài khoản"),
705
- border,
706
- ),
707
- );
708
- console.log(
709
- boxRow(
710
- chalk.hex("#E2E8F0")(" [2] Dùng lệnh gh: gh auth login"),
711
- border,
712
- ),
713
- );
714
- console.log(
715
- boxRow(
716
- chalk.hex("#94A3B8")(" [3] Sử dụng SSH URL: git@github.com:user/repo.git"),
717
- border,
718
- ),
719
- );
720
- console.log(boxBottom(border));
721
- console.log("");
722
- }
723
-
724
- export function printNonFastForwardBox(message = "", branch = "main") {
725
- const border = chalk.hex("#D97706");
726
- const title = chalk.bold.bgHex("#D97706").hex("#FFFFFF")(
727
- " REMOTE ĐÃ CÓ COMMIT MỚI HƠN ",
728
- );
729
- const firstLine = String(message || "")
730
- .split("\n")[0]
731
- .slice(0, 120);
732
-
733
- console.log("");
734
- console.log(boxTop(title, border));
735
- console.log(
736
- boxRow(
737
- chalk.hex("#FDE68A")(
738
- "Kho lưu trữ trên Remote đang chứa commit mới hơn Local.",
739
- ),
740
- border,
741
- ),
742
- );
743
- if (firstLine)
744
- console.log(
745
- boxRow(
746
- chalk.hex("#64748B")(truncateVisual(firstLine, getW() - 4)),
747
- border,
748
- ),
749
- );
750
- console.log(boxRow("", border));
751
- console.log(
752
- boxRow(
753
- chalk.hex("#38BDF8")(
754
- ` » Bạn có thể chọn Pull (rebase) rồi push lại ngay trong tool`,
755
- ),
756
- border,
757
- ),
758
- );
759
- console.log(
760
- boxRow(
761
- chalk.hex("#94A3B8")(
762
- " Chỉ dùng --force khi bạn chắc chắn muốn ghi đè Remote.",
763
- ),
764
- border,
765
- ),
766
- );
767
- console.log(boxBottom(border));
768
- console.log("");
769
- }
770
-
771
- export function printFixResult({
772
- fixed = [],
773
- gitignoreAdded = [],
774
- codeFilesWithSecrets = [],
775
- failed = [],
776
- } = {}) {
777
- const W = getW();
778
- console.log("");
779
- if (fixed.length > 0) {
780
- console.log(
781
- chalk.hex("#34D399")(
782
- ` [OK] Đã gỡ ${fixed.length} file khỏi commit: ${truncateVisual(fixed.join(", "), W - 32)}`,
783
- ),
784
- );
785
- }
786
- if (gitignoreAdded.length > 0) {
787
- console.log(
788
- chalk.cyan(
789
- ` [+] Thêm vào .gitignore: ${truncateVisual(gitignoreAdded.join(", "), W - 28)}`,
790
- ),
791
- );
792
- }
793
- if (codeFilesWithSecrets && codeFilesWithSecrets.length > 0) {
794
- console.log(
795
- chalk.yellowBright(
796
- " [!] File code chứa secret (đã gỡ khỏi commit, KHÔNG cho vào .gitignore):",
797
- ),
798
- );
799
- codeFilesWithSecrets.forEach((f) =>
800
- console.log(chalk.yellow(` - ${f}`)),
801
- );
802
- console.log(
803
- chalk.gray(" » Hãy xóa key trong file và thay bằng process.env."),
804
- );
805
- }
806
- if (failed.length > 0) {
807
- failed.forEach((f) => console.log(chalk.red(` [x] ${f.file}: ${f.reason}`)));
808
- }
809
- }
810
-
811
- export function printFooter() {
812
- console.log(chalk.hex("#334155")(" ─── » ───"));
813
- console.log(
814
- chalk.hex("#64748B")(" » Mẹo: Chạy ") +
815
- chalk.hex("#38BDF8").bold("git-push-time --help") +
816
- chalk.hex("#64748B")(" để xem toàn bộ danh sách lệnh và phím tắt."),
817
- );
818
- console.log(
819
- chalk.hex("#475569")(
820
- " » GitHub CLI & Push Time — Chúc bạn làm việc hiệu quả!\n",
821
- ),
822
- );
823
- }
824
-
825
- export function styleCliHelp(program) {
826
- program.configureHelp({
827
- styleTitle: (t) => chalk.bold.hex("#38BDF8")(t),
828
- styleCommandText: (t) => chalk.hex("#F8FAFC")(t),
829
- styleOptionText: (t) => chalk.hex("#34D399")(t),
830
- styleArgumentText: (t) => chalk.hex("#FBBF24")(t),
831
- styleDescriptionText: (t) => chalk.hex("#94A3B8")(t),
832
- });
833
- program.addHelpText(
834
- "after",
835
- `
836
- ${chalk.hex("#334155")("─── » Ví dụ phổ biến ───")}
837
- ${chalk.hex("#34D399")("$")} ${chalk.white('git-push-time')} # Mở menu điều khiển tương tác trực quan
838
- ${chalk.hex("#34D399")("$")} ${chalk.white('git-push-time github create')} # Tạo nhanh repo mới trên GitHub
839
- ${chalk.hex("#34D399")("$")} ${chalk.white('git-push-time -r <repo-url> -d "-2d" -y')} # Push tự động lùi 2 ngày
840
- ${chalk.hex("#34D399")("$")} ${chalk.white('git-push-time fix')} # Quét & gỡ sạch secret
841
- ${chalk.hex("#34D399")("$")} ${chalk.white('git-push-time pull')} # Cập nhật code mới từ remote
842
- `,
843
- );
844
- }
1
+ import chalk from "chalk";
2
+ import boxen from "boxen";
3
+ import stringWidth from "string-width";
4
+
5
+ /**
6
+ * Chiều rộng khung thống nhất cho toàn bộ UI.
7
+ * - Luôn bằng nhau giữa dashboard / banner / prompt / box chi tiết
8
+ * nên các khung xếp chồng không bị lệch (vỡ giao diện).
9
+ * - Terminal hẹp thì co theo `cols - 2`, terminal rộng thì cap 76.
10
+ */
11
+ export function getW() {
12
+ const cols = process.stdout.columns;
13
+ if (!cols || cols < 10) return 72;
14
+ const avail = cols - 2;
15
+ // Terminal quá hẹp (<34): dùng đúng phần hiển thị được, tránh tràn dòng.
16
+ if (avail < 34) return Math.max(24, avail);
17
+ return Math.min(76, avail);
18
+ }
19
+
20
+ function fitStyled(text, maxWidth) {
21
+ const value = String(text ?? '').replace(/[\r\n\t]+/g, ' ');
22
+ if (maxWidth <= 0) return '';
23
+ if (stringWidth(value) <= maxWidth) return value;
24
+
25
+ const segmenter = new Intl.Segmenter(undefined, { granularity: 'grapheme' });
26
+ const parts = value.match(/\u001b\[[0-?]*[ -/]*[@-~]|[^\u001b]+|\u001b/g) || [];
27
+ const output = [];
28
+ let visible = 0;
29
+ let clipped = false;
30
+ const target = Math.max(0, maxWidth - 1);
31
+
32
+ for (const part of parts) {
33
+ if (part.startsWith('\u001b[')) {
34
+ output.push(part);
35
+ continue;
36
+ }
37
+ for (const { segment } of segmenter.segment(part)) {
38
+ const width = stringWidth(segment);
39
+ if (visible + width > target) {
40
+ clipped = true;
41
+ break;
42
+ }
43
+ output.push(segment);
44
+ visible += width;
45
+ }
46
+ if (clipped) break;
47
+ }
48
+
49
+ output.push('…');
50
+ // A clipped styled value must not leak its color into later terminal output.
51
+ if (value.includes('\u001b[')) output.push('\u001b[0m');
52
+ return output.join('');
53
+ }
54
+
55
+
56
+ function hexToRgb(hex) {
57
+ const n = parseInt(hex.replace("#", ""), 16);
58
+ return [(n >> 16) & 255, (n >> 8) & 255, n & 255];
59
+ }
60
+
61
+ export function multiGradient(text, colors = ["#818CF8", "#38BDF8", "#34D399", "#A7F3D0"]) {
62
+ const chars = [...text];
63
+ const rgbColors = colors.map(hexToRgb);
64
+ return chars.map((char, index) => {
65
+ const t = (index / (chars.length - 1 || 1)) * (rgbColors.length - 1);
66
+ const colorIndex = Math.min(Math.floor(t), rgbColors.length - 2);
67
+ const localT = t - colorIndex;
68
+ const [r1, g1, b1] = rgbColors[colorIndex];
69
+ const [r2, g2, b2] = rgbColors[colorIndex + 1];
70
+ return chalk.rgb(Math.round(r1 + (r2-r1)*localT), Math.round(g1 + (g2-g1)*localT), Math.round(b1 + (b2-b1)*localT))(char);
71
+ }).join("");
72
+ }
73
+
74
+ export function pad(str, len) {
75
+ const vLen = stringWidth(str);
76
+ if (vLen >= len) return str;
77
+ return str + " ".repeat(len - vLen);
78
+ }
79
+
80
+ export function truncateVisual(str, maxLen) {
81
+ return fitStyled(str, maxLen);
82
+ }
83
+
84
+ /** Khung tiêu đề nhất quán cho từng bước tương tác trong terminal. */
85
+ export function framePrompt(message) {
86
+ // Dùng cùng getW() với mọi box khác để các khung luôn thẳng hàng,
87
+ // không còn tình trạng prompt hẹp (56) còn dashboard rộng (76) gây vỡ.
88
+ return boxen(String(message ?? ""), {
89
+ borderStyle: "round",
90
+ borderColor: "#818CF8",
91
+ padding: { left: 1, right: 1, top: 0, bottom: 0 },
92
+ width: getW(),
93
+ textAlignment: "center",
94
+ });
95
+ }
96
+
97
+ /* ==========================================================================
98
+ BOX ENGINE CHUẨN (Bo góc mềm & Căn lề pixel-perfect)
99
+ ========================================================================== */
100
+
101
+ export function boxTop(title = "", borderColor = chalk.hex("#334155")) {
102
+ const W = getW();
103
+ if (!title) return borderColor("╭" + "─".repeat(Math.max(2, W - 2)) + "╮");
104
+
105
+ // Căn giữa tiêu đề để 2 bên đều nhau: ╭──── Title ────╮
106
+ // Chừa 1 space mỗi bên title + tối thiểu 2 gạch mỗi bên.
107
+ const maxTitle = Math.max(4, W - 8);
108
+ const fittedTitle = fitStyled(title, maxTitle);
109
+ const titleWidth = stringWidth(fittedTitle);
110
+ const remaining = Math.max(4, W - 2 - titleWidth - 2);
111
+ const leftLen = Math.ceil(remaining / 2);
112
+ const rightLen = Math.floor(remaining / 2);
113
+ return (
114
+ borderColor("╭" + "─".repeat(leftLen) + " ") +
115
+ fittedTitle +
116
+ borderColor(" " + "─".repeat(rightLen) + "╮")
117
+ );
118
+ }
119
+
120
+ /** Khung tiêu đề căn trái theo lề nội dung của boxRow. */
121
+ export function boxTopLeft(title = "", borderColor = chalk.hex("#334155")) {
122
+ const W = getW();
123
+ if (!title) return borderColor("╭" + "─".repeat(Math.max(2, W - 2)) + "╮");
124
+ const fittedTitle = truncateVisual(title, W - 6);
125
+ const titleWidth = stringWidth(fittedTitle);
126
+ const rightDash = Math.max(0, W - titleWidth - 4);
127
+ return borderColor("╭ ") + fittedTitle + borderColor(" " + "─".repeat(rightDash) + "╮");
128
+ }
129
+
130
+ export function boxBottom(borderColor = chalk.hex("#334155")) {
131
+ const W = getW();
132
+ return borderColor("╰" + "─".repeat(Math.max(2, W - 2)) + "╯");
133
+ }
134
+
135
+ export function boxRow(content = "", borderColor = chalk.hex("#334155")) {
136
+ const W = getW();
137
+ const inner = Math.max(4, W - 4);
138
+ return borderColor("│ ") + pad(fitStyled(content, inner), inner) + borderColor(" │");
139
+ }
140
+
141
+ export function boxDivider(borderColor = chalk.hex("#334155")) {
142
+ const W = getW();
143
+ return borderColor("├" + "─".repeat(Math.max(2, W - 2)) + "┤");
144
+ }
145
+
146
+ /**
147
+ * Hàng Key-Value có đường nối bằng dấu chấm · · ·
148
+ * Dùng "·" (U+00B7) thay vì "․" (U+2024) để không bị vỡ font trên
149
+ * Windows PowerShell / Consolas. Label không còn bị cắt oan khi
150
+ * terminal hẹp nhờ công thức fitted mới.
151
+ */
152
+ /**
153
+ * Hàng Key-Value có đường nối bằng dấu chấm · · ·
154
+ * Căn lề chuẩn xác, khoảng cách đều và không bị vỡ font trên mọi terminal.
155
+ */
156
+ export function boxKvDot(
157
+ label,
158
+ value,
159
+ labelWidth = 14,
160
+ borderColor = chalk.hex("#334155"),
161
+ ) {
162
+ const W = getW();
163
+ const innerWidth = Math.max(8, W - 4);
164
+ const fittedLabelWidth = Math.min(labelWidth, Math.max(4, innerWidth - 10));
165
+ const maxValWidth = Math.max(4, innerWidth - fittedLabelWidth - 4);
166
+ const truncatedVal = truncateVisual(value, maxValWidth);
167
+ const valWidth = stringWidth(truncatedVal);
168
+
169
+ const dotsLen = Math.max(2, innerWidth - fittedLabelWidth - valWidth - 2);
170
+ const dots = " " + chalk.hex("#334155")("·".repeat(dotsLen)) + " ";
171
+ const formattedLabel = chalk.hex("#94A3B8")(
172
+ pad(fitStyled(label, fittedLabelWidth), fittedLabelWidth),
173
+ );
174
+
175
+ return boxRow(`${formattedLabel}${dots}${truncatedVal}`, borderColor);
176
+ }
177
+
178
+ /* ==========================================================================
179
+ PUBLIC INTERFACE & BANNER
180
+ ========================================================================== */
181
+
182
+ /* ==========================================================================
183
+ CYBER CAT MASCOT — 20x12 pixel art grid, two pixel rows per terminal cell
184
+ ========================================================================== */
185
+
186
+ const MASCOT_COLORS = {
187
+ P: "#818CF8", // Indigo ears
188
+ W: "#F8FAFC", // White face
189
+ C: "#38BDF8", // Cyan visor
190
+ E: "#06B6D4", // Visor eye glow
191
+ K: "#0F172A", // Dark visor frame
192
+ M: "#F43F5E", // Rose nose/mouth
193
+ G: "#10B981", // Emerald badge
194
+ B: "#334155", // Slate base
195
+ ".": "transparent",
196
+ };
197
+
198
+ const MASCOT_GRID = [
199
+ "..PP............PP......",
200
+ ".PPPP..........PPPP.....",
201
+ ".PPWW..........WWPP.....",
202
+ "WWWWWWWWWWWWWWWWWWWW....",
203
+ "WWKKKKKKKKKKKKKKWWWW....",
204
+ "WWKCCCCCCCCCCCCKWWWW....",
205
+ "WWKCEKEEEEEEKECKWWWW....",
206
+ "WWKKKKKKKKKKKKKKWWWW....",
207
+ "WWWWWWWWMMWWWWWWWWWW....",
208
+ ".WWWWWWWWWWWWWWWWWW..P..",
209
+ "..WWWW..GGGG..WWWWWWWW..",
210
+ "..BBBB..BBBB..BBBBWWWW..",
211
+ ];
212
+
213
+ export function mascotLines() {
214
+ const lines = [];
215
+ for (let y = 0; y < MASCOT_GRID.length; y += 2) {
216
+ let line = "";
217
+ for (let x = 0; x < MASCOT_GRID[y].length; x++) {
218
+ const top = MASCOT_GRID[y][x];
219
+ const bot = MASCOT_GRID[y + 1][x];
220
+ if (top === "." && bot === ".") line += " ";
221
+ else if (top === "." || bot === ".") {
222
+ const pixel = top === "." ? bot : top;
223
+ line += chalk.hex(MASCOT_COLORS[pixel])(top === "." ? "▄" : "▀");
224
+ } else if (top === bot) {
225
+ line += chalk.hex(MASCOT_COLORS[top])("█");
226
+ } else {
227
+ line += chalk.hex(MASCOT_COLORS[top]).bgHex(MASCOT_COLORS[bot])("▀");
228
+ }
229
+ }
230
+ lines.push(line);
231
+ }
232
+ return lines;
233
+ }
234
+
235
+ /**
236
+ * Banner: Cyber Cat Mascot + Wordmark + Badges
237
+ */
238
+ export function printBanner(version = "1.1.1") {
239
+ const W = getW();
240
+ const inner = Math.max(20, W - 2 - 4);
241
+ const badges = [
242
+ chalk.bgHex("#1E1B4B").hex("#818CF8").bold(` v${version} `),
243
+ chalk.bgHex("#064E3B").hex("#34D399").bold(" SMART GIT "),
244
+ chalk.bgHex("#0C4A6E").hex("#38BDF8").bold(" GITHUB SYNC "),
245
+ chalk.bgHex("#4C0519").hex("#FB7185").bold(" SECRET SHIELD "),
246
+ chalk.bgHex("#451A03").hex("#FBBF24").bold(" BACKDATE "),
247
+ ];
248
+ const rows = [];
249
+ let row = "";
250
+ for (const badge of badges) {
251
+ const next = row ? `${row} ${badge}` : badge;
252
+ if (row && stringWidth(next) > inner) {
253
+ rows.push(row);
254
+ row = badge;
255
+ } else row = next;
256
+ }
257
+ if (row) rows.push(row);
258
+
259
+ const title = multiGradient("G I T P U S H T I M E", [
260
+ "#818CF8",
261
+ "#38BDF8",
262
+ "#2DD4BF",
263
+ "#F472B6",
264
+ ]);
265
+ const subtitle = chalk.hex("#94A3B8")(
266
+ "Git & GitHub CLI · Đẩy code siêu tốc · An toàn · Đổi giờ commit",
267
+ );
268
+ const mascot = mascotLines();
269
+ const body = [...mascot, "", title, subtitle, "", ...rows].join("\n");
270
+ const frame = boxen(body, {
271
+ borderStyle: "round",
272
+ borderColor: "#6366F1",
273
+ padding: { top: 1, bottom: 1, left: 2, right: 2 },
274
+ width: W,
275
+ textAlignment: "center",
276
+ });
277
+ console.log(`\n${frame}\n`);
278
+ }
279
+
280
+ /**
281
+ * Hiển thị Dashboard trạng thái ngắn gọn & trực quan ở đầu menu
282
+ */
283
+ export function printDashboardStatus({
284
+ targetDir = process.cwd(),
285
+ currentBranch = "main",
286
+ githubUser = null,
287
+ remoteUrl = null,
288
+ changes = 0,
289
+ lastCommit = null,
290
+ version = "1.1.1",
291
+ }) {
292
+ const border = chalk.hex("#6366F1");
293
+ const W = getW();
294
+ const remote = remoteUrl ? formatRemoteLabel(remoteUrl) : chalk.hex("#94A3B8")("Chưa liên kết");
295
+
296
+ const ghStatus = githubUser
297
+ ? `${chalk.hex("#38BDF8").bold(`@${githubUser.login}`)} ${chalk.bgHex("#064E3B").hex("#34D399").bold(" [✓ ĐÃ KẾT NỐI] ")}`
298
+ : chalk.bgHex("#1E1B4B").hex("#A5B4FC").bold(" [○ CHƯA ĐĂNG NHẬP] ");
299
+
300
+ const branchPill = changes === 0
301
+ ? chalk.bgHex("#064E3B").hex("#34D399").bold(" [✓ SẠCH] ")
302
+ : chalk.bgHex("#78350F").hex("#FDE047").bold(` [● ${changes} THAY ĐỔI] `);
303
+
304
+ const branchDisplay = `${chalk.hex("#38BDF8").bold(currentBranch)} ${branchPill}`;
305
+
306
+ console.log("");
307
+ console.log(
308
+ boxTop(
309
+ `${chalk.bold.hex("#F8FAFC")(" BẢNG ĐIỀU KHIỂN GIT ")} ${chalk.hex("#94A3B8")(`v${version}`)}`,
310
+ border,
311
+ ),
312
+ );
313
+ console.log(boxRow("", border));
314
+ console.log(boxKvDot("Thư mục", chalk.hex("#F1F5F9").bold(targetDir), 14, border));
315
+ console.log(boxKvDot("Nhánh Git", branchDisplay, 14, border));
316
+ console.log(boxKvDot("GitHub", ghStatus, 14, border));
317
+ console.log(boxKvDot("Remote", remote, 14, border));
318
+
319
+ if (lastCommit && lastCommit.hash) {
320
+ const commitText = `${chalk.hex("#A78BFA").bold(lastCommit.hash)} ${chalk.hex("#CBD5E1")(truncateVisual(lastCommit.message || "", 26))} ${chalk.hex("#64748B")(`(${lastCommit.relativeTime || ""})`)}`;
321
+ console.log(boxKvDot("Commit gần", commitText, 14, border));
322
+ }
323
+
324
+ console.log(boxRow("", border));
325
+ console.log(boxBottom(border));
326
+ }
327
+
328
+ function formatRemoteLabel(url) {
329
+ const value = String(url || "").trim().replace(/\.git$/i, "");
330
+ const match = value.match(/(?:github\.com[:/])([^/]+\/[^/]+)$/i);
331
+ return match ? chalk.hex("#38BDF8")(match[1]) : chalk.hex("#CBD5E1")(value);
332
+ }
333
+
334
+ export function printPushProgress({ current, total = 6, title, completed = [] }) {
335
+ if (process.stdout.isTTY) process.stdout.write("\u001b[2J\u001b[H");
336
+ const nodes = Array.from({ length: total }, (_, index) => {
337
+ const n = index + 1;
338
+ if (n < current) return chalk.hex("#34D399")("●");
339
+ if (n === current) return chalk.hex("#38BDF8").bold("●");
340
+ return chalk.hex("#475569")("○");
341
+ });
342
+ const rail = nodes.join(chalk.hex("#334155")("──"));
343
+ const lead = `${chalk.hex("#38BDF8").bold("PUSH PROGRESS")} ${rail}`;
344
+ const detail = chalk.hex("#94A3B8")(`[Bước ${current}/${total} · ${title}]`);
345
+ console.log("");
346
+ if (stringWidth(`${lead} ${detail}`) <= getW() - 2) console.log(`${lead} ${detail}`);
347
+ else {
348
+ console.log(lead);
349
+ console.log(` ${detail}`);
350
+ }
351
+ if (completed.length) {
352
+ console.log("");
353
+ for (const item of completed) {
354
+ console.log(
355
+ ` ${chalk.hex("#34D399")("✓")} ${chalk.hex("#94A3B8")(item.label.padEnd(16))} ${chalk.hex("#334155")("·····")} ${chalk.hex("#F1F5F9")(truncateVisual(item.value, getW() - 28))}`,
356
+ );
357
+ }
358
+ }
359
+ }
360
+
361
+ /**
362
+ * Tiêu đề phân đoạn với điểm nhấn màu sắc
363
+ */
364
+ export function printSection(title) {
365
+ const W = getW();
366
+ const marker = chalk.hex("#A78BFA").bold("■");
367
+ const maxTitle = Math.max(4, W - 12);
368
+ const fittedTitle = fitStyled(String(title || "").trim(), maxTitle);
369
+ const coreWidth = stringWidth(fittedTitle) + 4;
370
+ const remaining = Math.max(4, W - coreWidth);
371
+ const leftLen = Math.ceil(remaining / 2);
372
+ const rightLen = Math.floor(remaining / 2);
373
+ console.log("");
374
+ console.log(
375
+ chalk.hex("#334155")("─".repeat(leftLen) + " ") +
376
+ marker +
377
+ chalk.bold.hex("#E2E8F0")(` ${fittedTitle} `) +
378
+ chalk.hex("#334155")("─".repeat(rightLen)),
379
+ );
380
+ }
381
+
382
+ /**
383
+ * Pill Step Badge (Ví dụ: 1/6)
384
+ */
385
+ export function stepLabel(current, total, text) {
386
+ const pill = chalk.bgHex("#2563EB").hex("#FFFFFF").bold(` ${current}/${total} `);
387
+ return `${pill} ${chalk.hex("#F1F5F9").bold(text)}`;
388
+ }
389
+
390
+ /**
391
+ * Bảng tóm tắt thông tin trước khi Push
392
+ */
393
+ export function printSummary({ repoUrl, commitMsg, dateDisplay, branch, force, sourceDir }) {
394
+ const border = chalk.hex("#38BDF8");
395
+ const title = chalk.bold.hex("#F8FAFC")(" XÁC NHẬN THÔNG TIN PUSH ");
396
+ console.log("");
397
+ console.log(boxTop(title, border));
398
+ console.log(boxRow("", border));
399
+ if (sourceDir) console.log(boxKvDot("Thư mục nguồn", chalk.hex("#F1F5F9")(sourceDir), 16, border));
400
+ console.log(boxKvDot("Kho lưu trữ", formatRemoteLabel(repoUrl), 16, border));
401
+ console.log(boxKvDot("Nhánh đích", chalk.hex("#38BDF8").bold(branch), 16, border));
402
+ console.log(boxKvDot("Thông điệp", chalk.hex("#FDE047")(`"${commitMsg}"`), 16, border));
403
+ console.log(boxKvDot("Thời điểm", chalk.hex("#A78BFA")(dateDisplay), 16, border));
404
+ console.log(boxKvDot("Quét Secret", chalk.hex("#34D399")("✓ Tự động kiểm tra trước khi đẩy"), 16, border));
405
+ if (force) {
406
+ console.log(boxRow("", border));
407
+ console.log(boxRow(chalk.hex("#F43F5E").bold(" [!] CẢNH BÁO: Chế độ ghi đè (--force) đang kích hoạt!"), border));
408
+ }
409
+ console.log(boxRow("", border));
410
+ console.log(boxBottom(border));
411
+ }
412
+
413
+ export function printTargetDir(dir = "") {
414
+ const W = getW();
415
+ console.log(
416
+ chalk.hex("#64748B")(
417
+ ` Thư mục: ${truncateVisual(String(dir || ""), W - 13)}`,
418
+ ),
419
+ );
420
+ }
421
+
422
+ /**
423
+ * Hiển thị thẻ Profile thông tin tài khoản GitHub
424
+ */
425
+ export function printGitHubProfile(user, source = '') {
426
+ const border = chalk.hex("#4F46E5");
427
+ const title = chalk.bold.bgHex("#4F46E5").hex("#FFFFFF")(
428
+ " TÀI KHOẢN GITHUB KẾT NỐI ",
429
+ );
430
+
431
+ console.log("");
432
+ console.log(boxTop(title, border));
433
+
434
+ console.log(
435
+ boxKvDot("Username", chalk.hex("#38BDF8").bold(`@${user.login}`), 16, border)
436
+ );
437
+ if (user.name) {
438
+ console.log(boxKvDot("Tên hiển thị", chalk.hex("#F8FAFC")(user.name), 16, border));
439
+ }
440
+ if (user.email) {
441
+ console.log(boxKvDot("Email", chalk.hex("#94A3B8")(user.email), 16, border));
442
+ }
443
+ if (user.bio) {
444
+ console.log(boxKvDot("Tiểu sử", chalk.hex("#CBD5E1")(truncateVisual(user.bio, 40)), 16, border));
445
+ }
446
+
447
+ const repoStats = `${user.public_repos || 0} public • ${user.total_private_repos || 0} private`;
448
+ console.log(boxKvDot("Repositories", chalk.hex("#34D399").bold(repoStats), 16, border));
449
+
450
+ if (source) {
451
+ const srcDesc = source === 'gh-cli' ? 'GitHub CLI (gh)' : source === 'env' ? 'Biến môi trường' : 'Lưu trữ cá nhân';
452
+ console.log(boxKvDot("Nguồn xác thực", chalk.hex("#A78BFA")(srcDesc), 16, border));
453
+ }
454
+
455
+ console.log(boxDivider(border));
456
+ console.log(boxRow(chalk.hex("#64748B")(`» Trang cá nhân: ${user.html_url}`), border));
457
+ console.log(boxBottom(border));
458
+ console.log("");
459
+ }
460
+
461
+ /**
462
+ * Hiển thị mã xác thực GitHub Device Flow cho người dùng
463
+ */
464
+ export function printDeviceCodePrompt({ userCode, verificationUri }) {
465
+ const border = chalk.hex("#6366F1");
466
+ const title = chalk.bold.bgHex("#4F46E5").hex("#FFFFFF")(
467
+ " GITHUB OAUTH / DEVICE FLOW ",
468
+ );
469
+
470
+ console.log("");
471
+ console.log(boxTop(title, border));
472
+ console.log(boxRow("", border));
473
+ console.log(boxRow(chalk.hex("#F8FAFC").bold("Bước 1: Mở trình duyệt và truy cập liên kết:"), border));
474
+ console.log(boxRow(chalk.hex("#38BDF8").bold.underline(` ${verificationUri}`), border));
475
+ console.log(boxRow("", border));
476
+ console.log(boxRow(chalk.hex("#F8FAFC").bold("Bước 2: Nhập mã xác nhận (User Code):"), border));
477
+
478
+ const codeBox = chalk.bgHex("#1E1B4B").hex("#A5B4FC").bold(` >>> ${userCode} <<< `);
479
+ console.log(boxRow(` ${codeBox}`, border));
480
+ console.log(boxRow("", border));
481
+ console.log(boxRow(chalk.hex("#94A3B8")("» Hệ thống đang tự động mở trình duyệt cho bạn..."), border));
482
+ console.log(boxRow(chalk.hex("#64748B")("» Nhấn Authorize trên trình duyệt để hoàn tất."), border));
483
+ console.log(boxBottom(border));
484
+ console.log("");
485
+ }
486
+
487
+ /**
488
+ * Hiển thị thông báo sau khi tạo repository GitHub mới thành công
489
+ */
490
+ export function printRepoCreatedBox(repo) {
491
+ const border = chalk.hex("#059669");
492
+ const title = chalk.bold.bgHex("#10B981").hex("#064E3B")(
493
+ " TẠO REPOSITORY GITHUB THÀNH CÔNG! ",
494
+ );
495
+
496
+ console.log("");
497
+ console.log(boxTop(title, border));
498
+ console.log(boxRow("", border));
499
+
500
+ const visibilityPill = repo.isPrivate
501
+ ? chalk.bgHex("#7F1D1D").hex("#FCA5A5").bold(" PRIVATE ")
502
+ : chalk.bgHex("#065F46").hex("#6EE7B7").bold(" PUBLIC ");
503
+
504
+ console.log(boxKvDot("Tên Repo", chalk.hex("#F8FAFC").bold(repo.fullName || repo.name), 14, border));
505
+ console.log(boxKvDot("Quyền riêng tư", visibilityPill, 14, border));
506
+ if (repo.description) {
507
+ console.log(boxKvDot("Mô tả", chalk.hex("#CBD5E1")(truncateVisual(repo.description, 42)), 14, border));
508
+ }
509
+ console.log(boxKvDot("HTTPS Clone", chalk.hex("#38BDF8").underline(repo.cloneUrl), 14, border));
510
+ console.log(boxKvDot("SSH Clone", chalk.hex("#A78BFA")(repo.sshUrl), 14, border));
511
+
512
+ console.log(boxRow("", border));
513
+ console.log(boxDivider(border));
514
+ console.log(boxRow(chalk.hex("#6EE7B7")(`» Xem trên GitHub: ${repo.htmlUrl}`), border));
515
+ console.log(boxBottom(border));
516
+ console.log("");
517
+ }
518
+
519
+ /**
520
+ * Cảnh báo Folder lồng trong Repo cha
521
+ */
522
+ export function printNestedRepoWarning({ targetDir = "", topLevel = "" } = {}) {
523
+ const border = chalk.hex("#D97706");
524
+ const title = chalk.bold.bgHex("#D97706").hex("#FFFFFF")(
525
+ " FOLDER NẰM TRONG REPO CHA ",
526
+ );
527
+
528
+ console.log("");
529
+ console.log(boxTop(title, border));
530
+ console.log(
531
+ boxRow(
532
+ chalk.hex("#FDE047")(
533
+ "Folder nguồn đang nằm trong Git repo của folder cha:",
534
+ ),
535
+ border,
536
+ ),
537
+ );
538
+ console.log(boxKvDot(" +- CHA", chalk.hex("#F8FAFC")(topLevel), 10, border));
539
+ console.log(
540
+ boxKvDot(" +- CON", chalk.hex("#F8FAFC")(targetDir), 10, border),
541
+ );
542
+ console.log(boxRow("", border));
543
+ console.log(
544
+ boxRow(
545
+ chalk.hex("#94A3B8")(
546
+ "Nếu push tiếp, lịch sử/file của folder cha có thể đi kèm.",
547
+ ),
548
+ border,
549
+ ),
550
+ );
551
+ console.log(
552
+ boxRow(
553
+ chalk.hex("#34D399")(
554
+ "Gợi ý: Tạo repo RIÊNG để chỉ push folder này.",
555
+ ),
556
+ border,
557
+ ),
558
+ );
559
+ console.log(boxBottom(border));
560
+ }
561
+
562
+ /**
563
+ * Cảnh báo Secret nhạy cảm
564
+ */
565
+ export function printPrePushSecretWarning({ riskyFiles = [], findings = [] }) {
566
+ const border = chalk.hex("#D97706");
567
+ const title = chalk.bold.bgHex("#D97706").hex("#FFFFFF")(
568
+ " PHÁT HIỆN DỮ LIỆU NHẠY CẢM ",
569
+ );
570
+
571
+ console.log("");
572
+ console.log(boxTop(title, border));
573
+ console.log(
574
+ boxRow(
575
+ chalk.hex("#FDE047")(
576
+ "GitHub có thể chặn push nếu phát hiện key bí mật (GH013)",
577
+ ),
578
+ border,
579
+ ),
580
+ );
581
+ console.log(boxRow("", border));
582
+
583
+ const W2 = getW();
584
+ const maxFileW = Math.max(10, W2 - 14);
585
+ const maxLocW = Math.max(10, W2 - 24);
586
+ const maxPrevW = Math.max(10, W2 - 18);
587
+
588
+ if (riskyFiles.length > 0) {
589
+ console.log(
590
+ boxRow(chalk.bold.hex("#F8FAFC")("File cấu hình nguy cơ:"), border),
591
+ );
592
+ const showFiles = riskyFiles.slice(0, 4);
593
+ showFiles.forEach((f) => {
594
+ const tree = chalk.hex("#64748B")(" +- ");
595
+ console.log(
596
+ boxRow(tree + chalk.hex("#FCD34D")(truncateVisual(f, maxFileW)), border),
597
+ );
598
+ });
599
+ if (riskyFiles.length > 4) {
600
+ console.log(
601
+ boxRow(
602
+ chalk.hex("#64748B")(` +- ...và ${riskyFiles.length - 4} file khác`),
603
+ border,
604
+ ),
605
+ );
606
+ }
607
+ }
608
+
609
+ if (findings.length > 0) {
610
+ if (riskyFiles.length > 0) console.log(boxRow("", border));
611
+ console.log(
612
+ boxRow(
613
+ chalk.bold.hex("#F8FAFC")("Vị trí nghi vấn Secret trong code:"),
614
+ border,
615
+ ),
616
+ );
617
+ const showFindings = findings.slice(0, 4);
618
+ showFindings.forEach((f, idx) => {
619
+ const isLast = idx === showFindings.length - 1;
620
+ const tree = chalk.hex("#64748B")(" +- ");
621
+ const loc = truncateVisual(`${f.file}:${f.line}`, maxLocW);
622
+ console.log(
623
+ boxRow(
624
+ tree +
625
+ chalk.hex("#F8FAFC")(loc) +
626
+ chalk.hex("#94A3B8")(` [${f.type}]`),
627
+ border,
628
+ ),
629
+ );
630
+ if (f.preview) {
631
+ const indent = chalk.hex("#64748B")(isLast ? " " : " | ");
632
+ console.log(
633
+ boxRow(
634
+ indent + chalk.hex("#64748B")(`"${truncateVisual(f.preview, maxPrevW)}"`),
635
+ border,
636
+ ),
637
+ );
638
+ }
639
+ });
640
+ if (findings.length > 4) {
641
+ console.log(
642
+ boxRow(
643
+ chalk.hex("#64748B")(` +- ...và ${findings.length - 4} vị trí khác`),
644
+ border,
645
+ ),
646
+ );
647
+ }
648
+ }
649
+
650
+ console.log(boxRow("", border));
651
+ console.log(
652
+ boxRow(
653
+ chalk.hex("#34D399")(
654
+ 'Gợi ý: Chọn "Tự động fix" để gỡ file + .gitignore an toàn',
655
+ ),
656
+ border,
657
+ ),
658
+ );
659
+ console.log(boxBottom(border));
660
+ }
661
+
662
+ /**
663
+ * Cảnh báo Push bị chặn bởi GitHub Push Protection (GH013)
664
+ */
665
+ export function printSecretBlockedBox(rawMessage, details = {}) {
666
+ const border = chalk.hex("#E11D48");
667
+ const files = details.files || [];
668
+ const types = details.secretTypes || [];
669
+ const title = chalk.bold.bgHex("#E11D48").hex("#FFFFFF")(
670
+ " PUSH BỊ CHẶN — PHÁT HIỆN SECRET (GH013) ",
671
+ );
672
+
673
+ console.log("");
674
+ console.log(boxTop(title, border));
675
+ console.log(
676
+ boxRow(
677
+ chalk.hex("#FDA4AF")(
678
+ "GitHub Push Protection đã chặn push vì phát hiện secret!",
679
+ ),
680
+ border,
681
+ ),
682
+ );
683
+ console.log(boxRow("", border));
684
+
685
+ if (types.length > 0) {
686
+ console.log(
687
+ boxKvDot(
688
+ "Loại secret",
689
+ chalk.hex("#F8FAFC").bold(types.slice(0, 2).join(", ")),
690
+ 14,
691
+ border,
692
+ ),
693
+ );
694
+ }
695
+ if (files.length > 0) {
696
+ files.slice(0, 2).forEach((f) => {
697
+ console.log(
698
+ boxKvDot("File nguồn", chalk.hex("#FCD34D")(f), 14, border),
699
+ );
700
+ });
701
+ }
702
+
703
+ console.log(boxRow("", border));
704
+ console.log(
705
+ boxRow(chalk.bold.hex("#F8FAFC")("» Các giải pháp khắc phục:"), border),
706
+ );
707
+ console.log(
708
+ boxRow(
709
+ chalk.hex("#E2E8F0")(" [1] Thu hồi (revoke) key ngay nếu là token thật"),
710
+ border,
711
+ ),
712
+ );
713
+ console.log(
714
+ boxRow(
715
+ chalk.hex("#38BDF8")(
716
+ " [2] Dùng tool tự động gỡ file & squash làm sạch commit",
717
+ ),
718
+ border,
719
+ ),
720
+ );
721
+ console.log(
722
+ boxRow(
723
+ chalk.hex("#94A3B8")(
724
+ " [3] Xóa secret trong code / dùng biến môi trường (process.env)",
725
+ ),
726
+ border,
727
+ ),
728
+ );
729
+
730
+ console.log(boxBottom(border));
731
+
732
+ if (details.unblockUrl) {
733
+ console.log(
734
+ chalk.hex("#F59E0B")(
735
+ `\n » URL mở khóa tạm thời (nếu là key mẫu thử nghiệm):\n ${chalk.underline(details.unblockUrl)}`,
736
+ ),
737
+ );
738
+ }
739
+ console.log(
740
+ chalk.hex("#64748B")(
741
+ `\n » Tài liệu GitHub: ${details.resolveUrl || "https://docs.github.com/code-security/secret-scanning/pushing-a-branch-blocked-by-push-protection"}\n`,
742
+ ),
743
+ );
744
+ }
745
+
746
+ /**
747
+ * Card Thông báo Thành công sau khi Push
748
+ */
749
+ /**
750
+ * Card Thông báo Thành công sau khi Push
751
+ */
752
+ export function printSuccessBox({
753
+ branch,
754
+ repoUrl,
755
+ durationSeconds = null,
756
+ secretStatus = "Đã quét (0 rủi ro)",
757
+ }) {
758
+ const border = chalk.hex("#10B981");
759
+ const title = chalk.bold.hex("#F8FAFC")(" PUSH THÀNH CÔNG ");
760
+ console.log("");
761
+ console.log(boxTop(title, border));
762
+ console.log(boxRow("", border));
763
+ console.log(boxKvDot("Nhánh đích", chalk.hex("#34D399").bold(branch), 18, border));
764
+ console.log(boxKvDot("Trạng thái Secret", chalk.hex("#38BDF8")(secretStatus), 18, border));
765
+ if (durationSeconds !== null) {
766
+ console.log(
767
+ boxKvDot(
768
+ "Thời gian xử lý",
769
+ chalk.hex("#FBBF24").bold(`${durationSeconds.toFixed(1)}s`),
770
+ 18,
771
+ border,
772
+ ),
773
+ );
774
+ }
775
+ const webUrl = toGitHubWebUrl(repoUrl);
776
+ if (webUrl) {
777
+ console.log(boxRow("", border));
778
+ console.log(boxDivider(border));
779
+ console.log(
780
+ boxRow(
781
+ `${chalk.hex("#34D399")("» Xem trên GitHub:")} ${chalk.hex("#38BDF8").underline(webUrl)}`,
782
+ border,
783
+ ),
784
+ );
785
+ } else {
786
+ console.log(boxKvDot("Remote", chalk.hex("#CBD5E1")(truncateVisual(repoUrl, getW() - 14)), 18, border));
787
+ }
788
+ console.log(boxRow("", border));
789
+ console.log(boxBottom(border));
790
+ console.log("");
791
+ }
792
+
793
+ function toGitHubWebUrl(url) {
794
+ const match = String(url || "").trim().match(/(?:https?:\/\/github\.com\/|git@github\.com:|ssh:\/\/git@github\.com\/)([^/]+\/[^/]+?)(?:\.git)?$/i);
795
+ return match ? `https://github.com/${match[1]}` : null;
796
+ }
797
+
798
+ export function printCancelled() {
799
+ const border = chalk.hex("#64748B");
800
+ const title = chalk.bold.hex("#F8FAFC")(
801
+ " ĐÃ HỦY THAO TÁC ",
802
+ );
803
+ console.log("");
804
+ console.log(boxTop(title, border));
805
+ console.log(boxRow("", border));
806
+ console.log(
807
+ boxRow(
808
+ chalk.hex("#94A3B8")(
809
+ "Thao tác đã dừng lại an toàn. Không có thay đổi nào được thực hiện.",
810
+ ),
811
+ border,
812
+ ),
813
+ );
814
+ console.log(boxRow("", border));
815
+ console.log(boxBottom(border));
816
+ console.log("");
817
+ }
818
+
819
+ export function printErrorBox(title = "XẢY RA LỖI", lines = [], hint = "") {
820
+ const W = getW();
821
+ const border = chalk.hex("#E11D48");
822
+ const cleanTitle = String(title || "").toUpperCase();
823
+ const titleStyled = chalk.bold.bgHex("#E11D48").hex("#FFFFFF")(` [LỖI] ${cleanTitle} `);
824
+ const rows = Array.isArray(lines) ? lines : [String(lines || "")];
825
+
826
+ console.log("");
827
+ console.log(boxTop(titleStyled, border));
828
+ rows.forEach((l) => {
829
+ if (!l) {
830
+ console.log(boxRow("", border));
831
+ } else {
832
+ console.log(
833
+ boxRow(chalk.hex("#FDA4AF")(truncateVisual(String(l), W - 4)), border),
834
+ );
835
+ }
836
+ });
837
+ if (hint) {
838
+ console.log(boxRow("", border));
839
+ console.log(
840
+ boxRow(chalk.hex("#38BDF8")(`» ${truncateVisual(hint, W - 6)}`), border),
841
+ );
842
+ }
843
+ console.log(boxBottom(border));
844
+ console.log("");
845
+ }
846
+
847
+ export function printGitMissing() {
848
+ printErrorBox(
849
+ "CHƯA CÀI ĐẶT GIT",
850
+ [
851
+ "Không tìm thấy Git trên hệ thống máy tính của bạn.",
852
+ "Vui lòng tải và cài đặt Git để tiếp tục!",
853
+ ],
854
+ "Tải ngay tại: https://git-scm.com/downloads",
855
+ );
856
+ }
857
+
858
+ export function printAuthFailedBox(message = "") {
859
+ const border = chalk.hex("#E11D48");
860
+ const title = chalk.bold.bgHex("#E11D48").hex("#FFFFFF")(
861
+ " LỖI XÁC THỰC GIT ",
862
+ );
863
+ const firstLine = String(message || "")
864
+ .split("\n")[0]
865
+ .slice(0, 120);
866
+
867
+ console.log("");
868
+ console.log(boxTop(title, border));
869
+ console.log(
870
+ boxRow(
871
+ chalk.hex("#FDA4AF")(
872
+ "Không thể xác thực với remote. Kiểm tra lại quyền truy cập.",
873
+ ),
874
+ border,
875
+ ),
876
+ );
877
+ if (firstLine)
878
+ console.log(
879
+ boxRow(
880
+ chalk.hex("#64748B")(truncateVisual(firstLine, getW() - 4)),
881
+ border,
882
+ ),
883
+ );
884
+ console.log(boxRow("", border));
885
+ console.log(
886
+ boxRow(chalk.bold.hex("#F8FAFC")("» Cách khắc phục nhanh:"), border),
887
+ );
888
+ console.log(
889
+ boxRow(
890
+ chalk.hex("#E2E8F0")(" [1] Chạy tính năng GITHUB trong tool để kết nối tài khoản"),
891
+ border,
892
+ ),
893
+ );
894
+ console.log(
895
+ boxRow(
896
+ chalk.hex("#E2E8F0")(" [2] Dùng lệnh gh: gh auth login"),
897
+ border,
898
+ ),
899
+ );
900
+ console.log(
901
+ boxRow(
902
+ chalk.hex("#94A3B8")(" [3] Sử dụng SSH URL: git@github.com:user/repo.git"),
903
+ border,
904
+ ),
905
+ );
906
+ console.log(boxBottom(border));
907
+ console.log("");
908
+ }
909
+
910
+ export function printNonFastForwardBox(message = "", branch = "main") {
911
+ const border = chalk.hex("#D97706");
912
+ const title = chalk.bold.bgHex("#D97706").hex("#FFFFFF")(
913
+ " REMOTE ĐÃ CÓ COMMIT MỚI HƠN ",
914
+ );
915
+ const firstLine = String(message || "")
916
+ .split("\n")[0]
917
+ .slice(0, 120);
918
+
919
+ console.log("");
920
+ console.log(boxTop(title, border));
921
+ console.log(
922
+ boxRow(
923
+ chalk.hex("#FDE68A")(
924
+ "Kho lưu trữ trên Remote đang chứa commit mới hơn Local.",
925
+ ),
926
+ border,
927
+ ),
928
+ );
929
+ if (firstLine)
930
+ console.log(
931
+ boxRow(
932
+ chalk.hex("#64748B")(truncateVisual(firstLine, getW() - 4)),
933
+ border,
934
+ ),
935
+ );
936
+ console.log(boxRow("", border));
937
+ console.log(
938
+ boxRow(
939
+ chalk.hex("#38BDF8")(
940
+ ` » Bạn có thể chọn Pull (rebase) rồi push lại ngay trong tool`,
941
+ ),
942
+ border,
943
+ ),
944
+ );
945
+ console.log(
946
+ boxRow(
947
+ chalk.hex("#94A3B8")(
948
+ " Chỉ dùng --force khi bạn chắc chắn muốn ghi đè Remote.",
949
+ ),
950
+ border,
951
+ ),
952
+ );
953
+ console.log(boxBottom(border));
954
+ console.log("");
955
+ }
956
+
957
+ export function printFixResult({
958
+ fixed = [],
959
+ gitignoreAdded = [],
960
+ codeFilesWithSecrets = [],
961
+ failed = [],
962
+ } = {}) {
963
+ const W = getW();
964
+ const border = chalk.hex("#10B981");
965
+ const title = chalk.bold.hex("#F8FAFC")(" KẾT QUẢ BẢO VỆ SECRET ");
966
+
967
+ console.log("");
968
+ console.log(boxTop(title, border));
969
+ console.log(boxRow("", border));
970
+
971
+ if (fixed.length > 0) {
972
+ console.log(
973
+ boxRow(
974
+ `${chalk.hex("#34D399").bold("[OK] Đã gỡ khỏi commit:")} ${chalk.hex("#F1F5F9")(truncateVisual(fixed.join(", "), W - 28))}`,
975
+ border,
976
+ ),
977
+ );
978
+ }
979
+ if (gitignoreAdded.length > 0) {
980
+ console.log(
981
+ boxRow(
982
+ `${chalk.hex("#38BDF8").bold("[+] Thêm vào .gitignore:")} ${chalk.hex("#CBD5E1")(truncateVisual(gitignoreAdded.join(", "), W - 30))}`,
983
+ border,
984
+ ),
985
+ );
986
+ }
987
+ if (codeFilesWithSecrets && codeFilesWithSecrets.length > 0) {
988
+ console.log(boxRow("", border));
989
+ console.log(
990
+ boxRow(
991
+ chalk.hex("#FBBF24").bold("[!] File code chứa secret (đã gỡ stage, KHÔNG ignore):"),
992
+ border,
993
+ ),
994
+ );
995
+ codeFilesWithSecrets.forEach((f) =>
996
+ console.log(boxRow(` - ${chalk.hex("#CBD5E1")(truncateVisual(f, W - 10))}`, border)),
997
+ );
998
+ console.log(
999
+ boxRow(chalk.hex("#94A3B8")(" » Hãy xóa key trong file và thay bằng process.env."), border),
1000
+ );
1001
+ }
1002
+ if (failed.length > 0) {
1003
+ console.log(boxRow("", border));
1004
+ failed.forEach((f) =>
1005
+ console.log(boxRow(chalk.hex("#F43F5E")(` [x] ${f.file}: ${f.reason}`), border)),
1006
+ );
1007
+ }
1008
+
1009
+ console.log(boxRow("", border));
1010
+ console.log(boxBottom(border));
1011
+ console.log("");
1012
+ }
1013
+
1014
+ export function printFooter() {
1015
+ const W = getW();
1016
+ // Dải phân cách căn đều 2 bên, full width như mọi khung.
1017
+ const core = "»";
1018
+ const remaining = Math.max(4, W - 3); // 1 core + 2 space
1019
+ const leftLen = Math.ceil(remaining / 2);
1020
+ const rightLen = Math.floor(remaining / 2);
1021
+ console.log(
1022
+ chalk.hex("#334155")("─".repeat(leftLen) + " ") +
1023
+ chalk.hex("#64748B")(core) +
1024
+ chalk.hex("#334155")(" " + "─".repeat(rightLen))
1025
+ );
1026
+ const tip1 =
1027
+ chalk.hex("#64748B")("» Mẹo: Chạy ") +
1028
+ chalk.hex("#38BDF8").bold("git-push-time --help") +
1029
+ chalk.hex("#64748B")(" để xem toàn bộ lệnh.");
1030
+ const tip2 = chalk.hex("#475569")("» GitHub CLI & Push Time — Chúc hiệu quả!");
1031
+ for (const tip of [tip1, tip2]) {
1032
+ const w = stringWidth(tip);
1033
+ if (w >= W) {
1034
+ console.log(` ${tip}`);
1035
+ } else {
1036
+ const padTotal = W - w;
1037
+ const left = Math.floor(padTotal / 2);
1038
+ console.log(" ".repeat(left) + tip);
1039
+ }
1040
+ }
1041
+ console.log("");
1042
+ }
1043
+
1044
+ export function styleCliHelp(program) {
1045
+ program.configureHelp({
1046
+ styleTitle: (t) => chalk.bold.hex("#38BDF8")(t),
1047
+ styleCommandText: (t) => chalk.hex("#F8FAFC")(t),
1048
+ styleOptionText: (t) => chalk.hex("#34D399")(t),
1049
+ styleArgumentText: (t) => chalk.hex("#FBBF24")(t),
1050
+ styleDescriptionText: (t) => chalk.hex("#94A3B8")(t),
1051
+ });
1052
+ program.addHelpText(
1053
+ "after",
1054
+ `
1055
+ ${chalk.hex("#334155")("─── » Ví dụ phổ biến ───")}
1056
+ ${chalk.hex("#34D399")("$")} ${chalk.white('git-push-time')} # Mở menu điều khiển tương tác trực quan
1057
+ ${chalk.hex("#34D399")("$")} ${chalk.white('git-push-time github create')} # Tạo nhanh repo mới trên GitHub
1058
+ ${chalk.hex("#34D399")("$")} ${chalk.white('git-push-time -r <repo-url> -d "-2d" -y')} # Push tự động lùi 2 ngày
1059
+ ${chalk.hex("#34D399")("$")} ${chalk.white('git-push-time fix')} # Quét & gỡ sạch secret
1060
+ ${chalk.hex("#34D399")("$")} ${chalk.white('git-push-time pull')} # Cập nhật code mới từ remote
1061
+ `,
1062
+ );
1063
+ }