-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathui.js
More file actions
176 lines (146 loc) · 5.08 KB
/
ui.js
File metadata and controls
176 lines (146 loc) · 5.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/usr/bin/env node
// ─────────────────────────────────────────────────────
// ui.js — Shared UI utilities for OpenCode sync scripts
// Tokyo Night Aesthetic
// ─────────────────────────────────────────────────────
"use strict";
const c = {
reset: "\x1b[0m",
bold: "\x1b[1m",
dim: "\x1b[2m",
italic: "\x1b[3m",
inverse: "\x1b[7m",
// Basic colors (fallback)
red: "\x1b[31m",
green: "\x1b[32m",
yellow: "\x1b[33m",
blue: "\x1b[34m",
magenta: "\x1b[35m",
cyan: "\x1b[36m",
white: "\x1b[37m",
gray: "\x1b[90m",
// Tokyo Night palette (true color RGB)
tn: {
cyan: "\x1b[38;2;92;156;245m", // rgb(92,156,245) — titles, accents, selected item, separator
yellow: "\x1b[38;5;179m", // #e0af68 — warnings
red: "\x1b[38;5;204m", // #f7768e — errors, force
green: "\x1b[38;5;79m", // #34d399 — success checkmarks
purple: "\x1b[38;5;140m", // #9d7cd8 — icons, decorative
gray: "\x1b[38;5;60m", // #565f89 — borders, dim text, unselected
text: "\x1b[38;5;146m", // #a9b1d6 — body text
slate: "\x1b[38;5;103m", // #94a3b8 — secondary text
},
// Semantic aliases
muted: "\x1b[38;5;60m",
success: "\x1b[38;5;79m",
highlight: "\x1b[38;2;92;156;245m",
};
function paint(text, ...styles) {
return `${styles.join("")}${text}${c.reset}`;
}
// ── Status output helpers ───────────────────────────
function printLine(symbol, msg, color = c.gray) {
console.log(` ${color}${symbol}${c.reset} ${msg}`);
}
function title(msg) {
console.log(`\n ${c.bold}${msg}${c.reset}\n`);
}
function logo(action = "push", force = false) {
const brandText = "OpenCode Sync";
const brandStyled = c.bold + c.white + brandText + c.reset;
const sep = c.tn.gray + " — " + c.reset;
const icon = c.tn.purple + "⚡" + c.reset;
const actionText = action === "push" ? "Push to GitHub" : "Pull from GitHub";
const actionStyled = c.tn.cyan + actionText + c.reset;
const forceTag = force ? " " + c.tn.red + c.bold + "⚠ FORCE" + c.reset : "";
console.log();
console.log(` ${brandStyled}${sep}${icon} ${actionStyled}${forceTag}`);
console.log();
}
function success(msg) {
console.log(` ✅ ${msg}`);
}
function error(msg) {
printLine("✖", msg, c.tn.red);
}
function warn(msg) {
printLine("⚠", msg, c.tn.yellow);
}
function info(msg) {
printLine("ℹ", msg, c.tn.cyan);
}
function step(msg) {
printLine("▸", msg, c.tn.gray);
}
function note(msg) {
console.log(` ${c.tn.gray}${msg}${c.reset}`);
}
function section(label, value = "") {
console.log(`\n ${c.tn.cyan}${c.bold}${label}${c.reset} ${value}`);
}
function done(msg) {
console.log();
console.log(` ✅ ${paint(msg, c.bold, c.tn.green)}`);
}
function separator() {
console.log();
console.log(` ${c.tn.cyan}${c.bold}${"━".repeat(48)}${c.reset}`);
}
function completionBanner(action, target) {
separator();
const actionLabel = action === "push" ? "Push" : "Pull";
const targetLabel = target === "config" ? "配置文件" : target === "sessions" ? "会话数据" : "配置和会话";
console.log(` \x1b[38;2;0;210;106m${c.bold}✨ 同步完成!${c.reset} ${c.tn.slate}${targetLabel}已成功 ${actionLabel}${c.reset}`);
console.log();
}
function upToDateBanner(action, target) {
separator();
const targetLabel = target === "config" ? "配置文件" : target === "sessions" ? "会话数据" : "配置和会话";
console.log(` \x1b[38;2;0;210;106m${c.bold}✨ 同步完成!${c.reset} ${c.tn.slate}${targetLabel}已是最新${c.reset}`);
console.log();
}
// ── Stats formatting ────────────────────────────────
function formatStats(added, modified, deleted, renamed) {
const parts = [];
if (added > 0) parts.push(`${c.tn.green}📄+${added}${c.reset}`);
if (modified > 0) parts.push(`${c.tn.yellow}📝~${modified}${c.reset}`);
if (deleted > 0) parts.push(`${c.tn.red}🗑️-${deleted}${c.reset}`);
if (renamed > 0) parts.push(`${c.tn.cyan}🔄${renamed}${c.reset}`);
if (parts.length === 0) {
return `${c.tn.gray}已是最新${c.reset}`;
}
return parts.join(` ${c.tn.gray}│${c.reset} `);
}
function formatDiffStats(diffOutput) {
let added = 0, modified = 0, deleted = 0, renamed = 0;
const lines = (diffOutput || "").split("\n").filter(Boolean);
for (const line of lines) {
const status = line.charAt(0).toUpperCase();
switch (status) {
case "A": added++; break;
case "M": modified++; break;
case "D": deleted++; break;
case "R": renamed++; break;
}
}
return formatStats(added, modified, deleted, renamed);
}
module.exports = {
c,
paint,
logo,
title,
success,
error,
warn,
info,
step,
note,
section,
done,
separator,
completionBanner,
upToDateBanner,
formatStats,
formatDiffStats,
};