claude-buddy-reroll 2.0.0 → 2.0.1
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/package.json +1 -1
- package/src/dex-ui.mjs +10 -7
- package/src/selector.mjs +216 -212
- package/src/ui.mjs +136 -106
package/package.json
CHANGED
package/src/dex-ui.mjs
CHANGED
|
@@ -41,28 +41,31 @@ function pushUniqueVariant(ordered, seen, variant) {
|
|
|
41
41
|
|
|
42
42
|
function makeBox(title, lines, width = 28) {
|
|
43
43
|
const innerWidth = width - 4;
|
|
44
|
+
const DIM = '\x1b[2m';
|
|
45
|
+
const BOLD = '\x1b[1m';
|
|
46
|
+
const GRAY = '\x1b[90m';
|
|
47
|
+
const R = '\x1b[0m';
|
|
44
48
|
const output = [
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
`+${'-'.repeat(width - 2)}+`,
|
|
49
|
+
`${GRAY}${BOLD}${title}${R}`,
|
|
50
|
+
`${GRAY}${'─'.repeat(width - 2)}${R}`,
|
|
48
51
|
];
|
|
49
52
|
|
|
50
53
|
for (const line of lines) {
|
|
51
|
-
output.push(
|
|
54
|
+
output.push(`${DIM} ${fitLine(line, innerWidth)}${R}`);
|
|
52
55
|
}
|
|
53
56
|
|
|
54
|
-
output.push(
|
|
57
|
+
output.push('');
|
|
55
58
|
return output;
|
|
56
59
|
}
|
|
57
60
|
|
|
58
|
-
function joinColumns(leftLines, rightLines, leftWidth = 28, gap = '
|
|
61
|
+
function joinColumns(leftLines, rightLines, leftWidth = 28, gap = ' ') {
|
|
59
62
|
const totalRows = Math.max(leftLines.length, rightLines.length);
|
|
60
63
|
const output = [];
|
|
61
64
|
|
|
62
65
|
for (let row = 0; row < totalRows; row++) {
|
|
63
66
|
const left = leftLines[row] || ' '.repeat(leftWidth);
|
|
64
67
|
const right = rightLines[row] || '';
|
|
65
|
-
output.push(
|
|
68
|
+
output.push(` ${left}${gap}${right}`);
|
|
66
69
|
}
|
|
67
70
|
|
|
68
71
|
return output;
|
package/src/selector.mjs
CHANGED
|
@@ -1,212 +1,216 @@
|
|
|
1
|
-
// Terminal UI selector —
|
|
2
|
-
import { emitKeypressEvents } from 'readline';
|
|
3
|
-
import { padAnsiEnd, stripAnsi } from './ansi.mjs';
|
|
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
|
-
let
|
|
50
|
-
let
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const
|
|
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
|
-
const
|
|
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
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
if (
|
|
156
|
-
process.
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
if (custom.
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
cursor = (cursor +
|
|
191
|
-
tick++;
|
|
192
|
-
render();
|
|
193
|
-
} else if (key.name === '
|
|
194
|
-
cursor = (cursor
|
|
195
|
-
tick++;
|
|
196
|
-
render();
|
|
197
|
-
} else if (key.name === '
|
|
198
|
-
cursor = (cursor +
|
|
199
|
-
tick++;
|
|
200
|
-
render();
|
|
201
|
-
} else if (key.name === '
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
1
|
+
// Terminal UI selector — v2: clean layout, subtle focus, smooth feel
|
|
2
|
+
import { emitKeypressEvents } from 'readline';
|
|
3
|
+
import { padAnsiEnd, stripAnsi, visibleLength } from './ansi.mjs';
|
|
4
|
+
|
|
5
|
+
const R = '\x1b[0m';
|
|
6
|
+
const BOLD = '\x1b[1m';
|
|
7
|
+
const DIM = '\x1b[2m';
|
|
8
|
+
const CYAN = '\x1b[36m';
|
|
9
|
+
const GRAY = '\x1b[90m';
|
|
10
|
+
const WHITE = '\x1b[37m';
|
|
11
|
+
const HIDE_CURSOR = '\x1b[?25l';
|
|
12
|
+
const SHOW_CURSOR = '\x1b[?25h';
|
|
13
|
+
const CLEAR = '\x1b[2J\x1b[H';
|
|
14
|
+
|
|
15
|
+
// Focus style: subtle arrow + bold text, no heavy BG inversion
|
|
16
|
+
const FOCUS_POINTER = `${CYAN}›${R}`;
|
|
17
|
+
const UNFOCUS_SPACE = ' ';
|
|
18
|
+
|
|
19
|
+
export function getSelectorRenderLineCount(bodyRows) {
|
|
20
|
+
return bodyRows + 5;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function getFullscreenBodyRows({ gridRows, previewHeight = 0, previewLinesLength = 0, footerLinesLength = 1, terminalRows = 24 }) {
|
|
24
|
+
const desiredBodyRows = Math.max(gridRows, previewHeight, previewLinesLength);
|
|
25
|
+
const reservedRows = 2 + 1 + Math.max(1, footerLinesLength);
|
|
26
|
+
const availableBodyRows = Math.max(gridRows, terminalRows - reservedRows);
|
|
27
|
+
return Math.min(desiredBodyRows, availableBodyRows);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Show an interactive list selector with arrow key navigation.
|
|
32
|
+
* @param {Object} options
|
|
33
|
+
* @param {string} options.title
|
|
34
|
+
* @param {Array<{label: string, description?: string, value: any}>} options.items
|
|
35
|
+
* @param {number} [options.columns=2]
|
|
36
|
+
* @param {number} [options.selected=0]
|
|
37
|
+
* @param {(item: any, meta: { cursor: number, tick: number }) => string} [options.preview]
|
|
38
|
+
* @param {number} [options.previewHeight=0]
|
|
39
|
+
* @param {boolean} [options.fullscreen=false]
|
|
40
|
+
* @param {number} [options.animationIntervalMs=0]
|
|
41
|
+
* @param {(item: any, meta: { cursor: number, tick: number, state: any }) => string[]} [options.footer]
|
|
42
|
+
* @param {any} [options.state]
|
|
43
|
+
* @param {(str: string, key: any, meta: { cursor: number, item: any, items: any[], tick: number, state: any }) => {handled?: boolean, state?: any, patch?: object, tick?: number}|void} [options.onKey]
|
|
44
|
+
* @returns {Promise<{index: number, value: any} | null>}
|
|
45
|
+
*/
|
|
46
|
+
export async function select({ title, items, columns = 2, selected = 0, preview = null, previewHeight = 0, fullscreen = false, animationIntervalMs = 0, footer = null, state = {}, onKey = null }) {
|
|
47
|
+
if (!process.stdin.isTTY) return null;
|
|
48
|
+
|
|
49
|
+
let cursor = selected;
|
|
50
|
+
let tick = 0;
|
|
51
|
+
let selectorState = state;
|
|
52
|
+
const rows = Math.ceil(items.length / columns);
|
|
53
|
+
const colWidth = Math.min(24, Math.floor(((process.stdout.columns || 80) - 6) / columns));
|
|
54
|
+
let renderedBodyRows = rows;
|
|
55
|
+
let didFullscreenInit = false;
|
|
56
|
+
|
|
57
|
+
function render() {
|
|
58
|
+
const meta = { cursor, tick, state: selectorState };
|
|
59
|
+
const previewText = typeof preview === 'function' ? preview(items[cursor], meta) : '';
|
|
60
|
+
const previewLines = previewText ? String(previewText).split('\n') : [];
|
|
61
|
+
const footerLines = typeof footer === 'function' ? footer(items[cursor], meta) : null;
|
|
62
|
+
const resolvedFooter = Array.isArray(footerLines) && footerLines.length > 0
|
|
63
|
+
? footerLines
|
|
64
|
+
: [` ${FOCUS_POINTER} ${items[cursor].label}${items[cursor].description ? ` ${DIM}${items[cursor].description}${R}` : ''}`];
|
|
65
|
+
const bodyRows = fullscreen
|
|
66
|
+
? getFullscreenBodyRows({
|
|
67
|
+
gridRows: rows,
|
|
68
|
+
previewHeight,
|
|
69
|
+
previewLinesLength: previewLines.length,
|
|
70
|
+
footerLinesLength: resolvedFooter.length,
|
|
71
|
+
terminalRows: process.stdout.rows || 24,
|
|
72
|
+
})
|
|
73
|
+
: Math.max(rows, previewHeight, previewLines.length);
|
|
74
|
+
const totalLines = getSelectorRenderLineCount(Math.max(renderedBodyRows, bodyRows)) + (resolvedFooter.length - 1);
|
|
75
|
+
|
|
76
|
+
if (fullscreen) {
|
|
77
|
+
if (!didFullscreenInit) {
|
|
78
|
+
process.stdout.write(CLEAR);
|
|
79
|
+
for (let i = 0; i < totalLines; i++) process.stdout.write('\n');
|
|
80
|
+
didFullscreenInit = true;
|
|
81
|
+
}
|
|
82
|
+
process.stdout.write(`\x1b[${totalLines}A`);
|
|
83
|
+
} else {
|
|
84
|
+
process.stdout.write(`\x1b[${totalLines}A`);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Title
|
|
88
|
+
process.stdout.write(`\x1b[2K ${BOLD}${title}${R}\n`);
|
|
89
|
+
process.stdout.write(`\x1b[2K\n`);
|
|
90
|
+
|
|
91
|
+
for (let row = 0; row < bodyRows; row++) {
|
|
92
|
+
let gridLine = ' ';
|
|
93
|
+
|
|
94
|
+
if (row < rows) {
|
|
95
|
+
for (let col = 0; col < columns; col++) {
|
|
96
|
+
const idx = row * columns + col;
|
|
97
|
+
if (idx >= items.length) {
|
|
98
|
+
gridLine += ' '.repeat(colWidth);
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
const item = items[idx];
|
|
102
|
+
const isFocused = idx === cursor;
|
|
103
|
+
|
|
104
|
+
if (isFocused) {
|
|
105
|
+
const text = `${FOCUS_POINTER} ${BOLD}${stripAnsi(item.label)}${R}`;
|
|
106
|
+
gridLine += padAnsiEnd(text, colWidth);
|
|
107
|
+
} else {
|
|
108
|
+
const text = `${UNFOCUS_SPACE} ${DIM}${stripAnsi(item.label)}${R}`;
|
|
109
|
+
gridLine += padAnsiEnd(text, colWidth);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
gridLine += ' '.repeat(columns * colWidth);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const previewLine = previewLines[row] ? ` ${previewLines[row]}` : '';
|
|
117
|
+
process.stdout.write(`\x1b[2K${gridLine}${previewLine}\n`);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
process.stdout.write(`\x1b[2K\n`);
|
|
121
|
+
for (const line of resolvedFooter) {
|
|
122
|
+
process.stdout.write(`\x1b[2K ${line}\n`);
|
|
123
|
+
}
|
|
124
|
+
renderedBodyRows = bodyRows;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return new Promise((resolve) => {
|
|
128
|
+
process.stdout.write(HIDE_CURSOR);
|
|
129
|
+
|
|
130
|
+
let animationTimer = null;
|
|
131
|
+
|
|
132
|
+
if (!fullscreen) {
|
|
133
|
+
const initialPreviewText = typeof preview === 'function' ? preview(items[cursor], { cursor, tick, state: selectorState }) : '';
|
|
134
|
+
const initialPreviewLines = initialPreviewText ? String(initialPreviewText).split('\n') : [];
|
|
135
|
+
const initialFooter = typeof footer === 'function' ? footer(items[cursor], { cursor, tick, state: selectorState }) : null;
|
|
136
|
+
const resolvedFooter = Array.isArray(initialFooter) && initialFooter.length > 0 ? initialFooter : [''];
|
|
137
|
+
const totalLines = getSelectorRenderLineCount(Math.max(rows, previewHeight, initialPreviewLines.length)) + (resolvedFooter.length - 1);
|
|
138
|
+
for (let i = 0; i < totalLines; i++) process.stdout.write('\n');
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
render();
|
|
142
|
+
|
|
143
|
+
if (animationIntervalMs > 0) {
|
|
144
|
+
animationTimer = setInterval(() => {
|
|
145
|
+
tick++;
|
|
146
|
+
render();
|
|
147
|
+
}, animationIntervalMs);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
emitKeypressEvents(process.stdin);
|
|
151
|
+
if (process.stdin.setRawMode) process.stdin.setRawMode(true);
|
|
152
|
+
process.stdin.resume();
|
|
153
|
+
|
|
154
|
+
function cleanup() {
|
|
155
|
+
if (process.stdin.setRawMode) process.stdin.setRawMode(false);
|
|
156
|
+
process.stdin.pause();
|
|
157
|
+
process.stdin.removeListener('keypress', handleKeypress);
|
|
158
|
+
if (animationTimer) clearInterval(animationTimer);
|
|
159
|
+
if (fullscreen) process.stdout.write(CLEAR);
|
|
160
|
+
process.stdout.write(SHOW_CURSOR);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function handleKeypress(str, key) {
|
|
164
|
+
if (!key) return;
|
|
165
|
+
|
|
166
|
+
if (typeof onKey === 'function') {
|
|
167
|
+
const custom = onKey(str, key, {
|
|
168
|
+
cursor,
|
|
169
|
+
item: items[cursor],
|
|
170
|
+
items,
|
|
171
|
+
tick,
|
|
172
|
+
state: selectorState,
|
|
173
|
+
});
|
|
174
|
+
if (custom) {
|
|
175
|
+
if (Object.prototype.hasOwnProperty.call(custom, 'state')) {
|
|
176
|
+
selectorState = custom.state;
|
|
177
|
+
} else if (custom.patch && selectorState && typeof selectorState === 'object') {
|
|
178
|
+
selectorState = { ...selectorState, ...custom.patch };
|
|
179
|
+
}
|
|
180
|
+
if (typeof custom.tick === 'number') tick = custom.tick;
|
|
181
|
+
if (custom.handled) {
|
|
182
|
+
tick++;
|
|
183
|
+
render();
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (key.name === 'up') {
|
|
190
|
+
cursor = (cursor - columns + items.length) % items.length;
|
|
191
|
+
tick++;
|
|
192
|
+
render();
|
|
193
|
+
} else if (key.name === 'down') {
|
|
194
|
+
cursor = (cursor + columns) % items.length;
|
|
195
|
+
tick++;
|
|
196
|
+
render();
|
|
197
|
+
} else if (key.name === 'left') {
|
|
198
|
+
cursor = (cursor - 1 + items.length) % items.length;
|
|
199
|
+
tick++;
|
|
200
|
+
render();
|
|
201
|
+
} else if (key.name === 'right') {
|
|
202
|
+
cursor = (cursor + 1) % items.length;
|
|
203
|
+
tick++;
|
|
204
|
+
render();
|
|
205
|
+
} else if (key.name === 'return') {
|
|
206
|
+
cleanup();
|
|
207
|
+
resolve({ index: cursor, value: items[cursor].value });
|
|
208
|
+
} else if (key.name === 'escape' || (key.ctrl && key.name === 'c')) {
|
|
209
|
+
cleanup();
|
|
210
|
+
resolve(null);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
process.stdin.on('keypress', handleKeypress);
|
|
215
|
+
});
|
|
216
|
+
}
|
package/src/ui.mjs
CHANGED
|
@@ -1,106 +1,136 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
const
|
|
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
|
-
export function
|
|
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
|
-
|
|
1
|
+
// UI layout primitives — v2: clean, consistent, Speaki-branded
|
|
2
|
+
import { RARITIES, RARITY_STARS, RARITY_WEIGHTS } from './engine.mjs';
|
|
3
|
+
import { padAnsiEnd, visibleLength } from './ansi.mjs';
|
|
4
|
+
import { formatStars } from './terminal.mjs';
|
|
5
|
+
|
|
6
|
+
const R = '\x1b[0m';
|
|
7
|
+
const BOLD = '\x1b[1m';
|
|
8
|
+
const DIM = '\x1b[2m';
|
|
9
|
+
const ITALIC = '\x1b[3m';
|
|
10
|
+
const CYAN = '\x1b[36m';
|
|
11
|
+
const GREEN = '\x1b[32m';
|
|
12
|
+
const MAGENTA = '\x1b[35m';
|
|
13
|
+
const YELLOW = '\x1b[33;1m';
|
|
14
|
+
const RED = '\x1b[31m';
|
|
15
|
+
const WHITE = '\x1b[37m';
|
|
16
|
+
const GRAY = '\x1b[90m';
|
|
17
|
+
|
|
18
|
+
const RARITY_TONE = {
|
|
19
|
+
common: GRAY,
|
|
20
|
+
uncommon: GREEN,
|
|
21
|
+
rare: '\x1b[34m',
|
|
22
|
+
epic: MAGENTA,
|
|
23
|
+
legendary: YELLOW,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// ─── Layout primitives ──────────────────────────────────
|
|
27
|
+
|
|
28
|
+
function hr(width = 48, char = '─', color = GRAY) {
|
|
29
|
+
return `${color}${char.repeat(width)}${R}`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function heading(text, color = MAGENTA) {
|
|
33
|
+
return `${color}${BOLD}${text}${R}`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function label(key, value) {
|
|
37
|
+
return ` ${GRAY}${key}${R} ${value}`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function bullet(text, icon = '›', color = GREEN) {
|
|
41
|
+
return ` ${color}${icon}${R} ${text}`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// ─── Banner ─────────────────────────────────────────────
|
|
45
|
+
|
|
46
|
+
export function renderBanner(title = 'BUDDY LAB', subtitle = 'collectible companion terminal') {
|
|
47
|
+
return [
|
|
48
|
+
'',
|
|
49
|
+
` ${MAGENTA}${BOLD}${title}${R}`,
|
|
50
|
+
` ${DIM}${subtitle}${R}`,
|
|
51
|
+
` ${hr(40)}`,
|
|
52
|
+
'',
|
|
53
|
+
].join('\n');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// ─── Section panel ──────────────────────────────────────
|
|
57
|
+
|
|
58
|
+
export function renderPanel(title, lines = [], color = GRAY) {
|
|
59
|
+
const out = [];
|
|
60
|
+
out.push(` ${color}${BOLD}${title}${R}`);
|
|
61
|
+
for (const line of lines) {
|
|
62
|
+
out.push(` ${line}`);
|
|
63
|
+
}
|
|
64
|
+
out.push('');
|
|
65
|
+
return out.join('\n');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// ─── Quota summary ──────────────────────────────────────
|
|
69
|
+
|
|
70
|
+
export function renderQuotaSummary({ used = 0, limit = 0, starred = false, eventRemaining = 0 } = {}) {
|
|
71
|
+
const remaining = Math.max(0, limit - used);
|
|
72
|
+
const bar = renderQuotaBar(used, limit);
|
|
73
|
+
return [
|
|
74
|
+
`${bar} ${DIM}${remaining}/${limit} left${starred ? ' ⭐' : ''}${R}`,
|
|
75
|
+
`${DIM}사용: ${used} 이벤트: ${eventRemaining}회 남음${R}`,
|
|
76
|
+
];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function renderQuotaBar(used, limit) {
|
|
80
|
+
const w = 10;
|
|
81
|
+
const filled = Math.min(w, Math.round((used / Math.max(limit, 1)) * w));
|
|
82
|
+
const remaining = w - filled;
|
|
83
|
+
return `${GREEN}${'█'.repeat(remaining)}${GRAY}${'░'.repeat(filled)}${R}`;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// ─── Rarity table ───────────────────────────────────────
|
|
87
|
+
|
|
88
|
+
export function renderRarityOverview() {
|
|
89
|
+
return RARITIES.map((rarity) => {
|
|
90
|
+
const pct = `${RARITY_WEIGHTS[rarity]}%`.padStart(3);
|
|
91
|
+
const color = RARITY_TONE[rarity] || WHITE;
|
|
92
|
+
const stars = formatStars(RARITY_STARS[rarity]);
|
|
93
|
+
return `${color}${stars.padEnd(6)}${R} ${color}${rarity.padEnd(10)}${R} ${GRAY}${pct}${R}`;
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// ─── Home screen ────────────────────────────────────────
|
|
98
|
+
|
|
99
|
+
export function renderHomeScreen() {
|
|
100
|
+
return [
|
|
101
|
+
renderBanner(),
|
|
102
|
+
renderPanel('Commands', [
|
|
103
|
+
`${GREEN}bdy check${R} ${DIM}현재 버디 + 설치 상태${R}`,
|
|
104
|
+
`${GREEN}bdy gacha 10${R} ${DIM}10연차 가챠${R}`,
|
|
105
|
+
`${GREEN}bdy reroll${R} ${DIM}후보 뽑고 바로 적용${R}`,
|
|
106
|
+
`${GREEN}bdy dex${R} ${DIM}도감 탐색${R}`,
|
|
107
|
+
`${GREEN}bdy restore${R} ${DIM}원래 버디로 복원${R}`,
|
|
108
|
+
]),
|
|
109
|
+
renderPanel('Rarity', renderRarityOverview(), MAGENTA),
|
|
110
|
+
].join('\n');
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// ─── Check screen ───────────────────────────────────────
|
|
114
|
+
|
|
115
|
+
export function renderCheckScreen({ accountLabel, installLabel, salt, patched, quotaLines, buddyCard, profileLine = '' }) {
|
|
116
|
+
return [
|
|
117
|
+
renderBanner('BUDDY STATUS', '현재 버디 + 설치 상태'),
|
|
118
|
+
renderPanel('Runtime', [
|
|
119
|
+
label('Account', accountLabel),
|
|
120
|
+
label('Install', installLabel),
|
|
121
|
+
label('Salt', `${salt}${patched ? ` ${YELLOW}(patched)${R}` : ` ${DIM}(original)${R}`}`),
|
|
122
|
+
...(profileLine ? [label('Profile', profileLine)] : []),
|
|
123
|
+
]),
|
|
124
|
+
renderPanel('Quota', quotaLines, GREEN),
|
|
125
|
+
buddyCard,
|
|
126
|
+
].join('\n');
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// ─── Search status ──────────────────────────────────────
|
|
130
|
+
|
|
131
|
+
export function renderSearchStatus({ targetSpecies, criteria, attempts }) {
|
|
132
|
+
const rarityText = criteria?.rarity ? ` ${RARITY_TONE[criteria.rarity] || ''}${criteria.rarity}${R}` : '';
|
|
133
|
+
return ` ${CYAN}›${R} ${targetSpecies}${rarityText} ${GRAY}(${attempts} attempts)${R}`;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export { R as RESET, BOLD, DIM, CYAN, GREEN, MAGENTA, YELLOW, RED };
|