@semalt-ai/code 1.8.3 → 1.8.5

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/legacy.js DELETED
@@ -1,130 +0,0 @@
1
- 'use strict';
2
-
3
- const readline = require('readline');
4
-
5
- const { RST, THEME } = require('./ansi');
6
- const { getCols } = require('./utils');
7
-
8
- // ─── StatusBar ─────────────────────────────────────────────────────────────────
9
- // Used by cmdCode and cmdEdit for non-TUI status display.
10
- // Also holds the static StatusBar.current shim wired by createUI.
11
-
12
- class StatusBar {
13
- constructor() {
14
- this._fields = { status: 'idle', model: '', tokens: '', ctx: '', latency: '', elapsed: '' };
15
- this._animFrames = ['⠋','⠙','⠹','⠸','⠼','⠴','⠦','⠧','⠇','⠏'];
16
- this._animIdx = 0; this._animTimer = null;
17
- this._onResize = () => this._handleResize();
18
- if (process.stdout.isTTY) { process.stdout.on('resize', this._onResize); this._reserveBottom(); }
19
- StatusBar.current = this;
20
- }
21
- _rows() { return process.stdout.rows || 24; }
22
- _reserveBottom() { const rows = this._rows(); process.stdout.write(`\x1b7\x1b[1;${rows - 1}r\x1b8`); this.render(); }
23
- _handleResize() { const rows = this._rows(); process.stdout.write(`\x1b7\x1b[1;${rows - 1}r\x1b8`); this.render(); }
24
- _startAnim() { if (this._animTimer) return; this._animTimer = setInterval(() => { this._animIdx = (this._animIdx + 1) % this._animFrames.length; this.render(); }, 100); }
25
- _stopAnim() { if (this._animTimer) { clearInterval(this._animTimer); this._animTimer = null; } this._animIdx = 0; }
26
- render() {
27
- if (!process.stdout.isTTY) return;
28
- const { loadConfig } = require('../config');
29
- const showTokens = loadConfig().show_token_count !== false;
30
- const parts = [];
31
- if (this._fields.status) {
32
- if (this._fields.status === 'streaming' || this._fields.status === 'thinking') {
33
- parts.push(`${THEME.tool}${this._animFrames[this._animIdx]}${THEME.reset} ${THEME.dim}${this._fields.status === 'thinking' ? 'Thinking…' : 'Streaming…'}${THEME.reset}`);
34
- } else { parts.push(`${THEME.dim}${this._fields.status}${THEME.reset}`); }
35
- }
36
- if (this._fields.model) parts.push(`${THEME.sys}${this._fields.model}${THEME.reset}`);
37
- if (showTokens && this._fields.tokens) parts.push(`${THEME.dim}${this._fields.tokens}${THEME.reset}`);
38
- if (showTokens && this._fields.ctx) parts.push(this._fields.ctx);
39
- if (this._fields.latency) parts.push(`${THEME.dim}${this._fields.latency}${THEME.reset}`);
40
- if (this._fields.elapsed) parts.push(`${THEME.dim}${this._fields.elapsed}${THEME.reset}`);
41
- const line = parts.join(` ${THEME.dim}│${THEME.reset} `);
42
- const rows = this._rows();
43
- process.stdout.write(`\x1b7\x1b[${rows};0H\x1b[K${line}\x1b8`);
44
- }
45
- update(fields) {
46
- if (!process.stdout.isTTY) return;
47
- Object.assign(this._fields, fields);
48
- if (this._fields.status === 'streaming' || this._fields.status === 'thinking') this._startAnim();
49
- else this._stopAnim();
50
- this.render();
51
- }
52
- liveUpdate(fields) { if (!process.stdout.isTTY) return; Object.assign(this._fields, fields); }
53
- destroy() {
54
- if (!process.stdout.isTTY) return;
55
- this._stopAnim();
56
- process.stdout.removeListener('resize', this._onResize);
57
- const rows = this._rows();
58
- process.stdout.write(`\x1b7\x1b[${rows};0H\x1b[K\x1b[r\x1b8`);
59
- if (StatusBar.current === this) StatusBar.current = null;
60
- }
61
- }
62
- StatusBar.current = null;
63
-
64
- // ─── interactiveSelect ────────────────────────────────────────────────────────
65
-
66
- async function interactiveSelect(items, renderItem, options) {
67
- const opts = options || {};
68
- const { initialIndex = 0 } = opts;
69
- return new Promise((resolve) => {
70
- if (!process.stdout.isTTY || !process.stdin.isTTY) { resolve(null); return; }
71
- let selectedIndex = Math.max(0, Math.min(initialIndex, items.length - 1));
72
- let done = false;
73
- const wasRaw = typeof process.stdin.isRaw === 'boolean' ? process.stdin.isRaw : false;
74
- const render = () => {
75
- readline.moveCursor(process.stdout, 0, -items.length);
76
- for (let i = 0; i < items.length; i++) {
77
- readline.cursorTo(process.stdout, 0); readline.clearLine(process.stdout, 0);
78
- const line = renderItem(items[i], i === selectedIndex);
79
- process.stdout.write(line + '\n');
80
- }
81
- };
82
- for (let i = 0; i < items.length; i++) {
83
- const line = renderItem(items[i], i === selectedIndex);
84
- process.stdout.write(line + '\n');
85
- }
86
- process.stdin.setRawMode(true); process.stdin.resume();
87
- const finish = (result) => {
88
- if (done) return; done = true;
89
- process.stdin.setRawMode(wasRaw); process.stdin.removeListener('data', onData); process.stdin.pause();
90
- // Collapse: show only the selected item, clear the rest
91
- const displayIdx = result !== null ? result : items.length - 1;
92
- readline.moveCursor(process.stdout, 0, -items.length);
93
- readline.cursorTo(process.stdout, 0);
94
- process.stdout.write('\x1b[2K' + renderItem(items[displayIdx], true, true) + '\x1b[J\n');
95
- resolve(result);
96
- };
97
- const onData = (chunk) => {
98
- if (done) return;
99
- const data = chunk.toString('utf8');
100
- if (data[0] === '\x0f') { if (opts.onExpand) opts.onExpand(); return; }
101
- if (data === '\x03' || data === '\x1b' || data === 'q') { finish(null); return; }
102
- if (data === '\r' || data === '\n') { finish(selectedIndex); return; }
103
- if (data === '\x1b[A' || data === 'k') { selectedIndex = Math.max(0, selectedIndex - 1); render(); return; }
104
- if (data === '\x1b[B' || data === 'j') { selectedIndex = Math.min(items.length - 1, selectedIndex + 1); render(); return; }
105
- };
106
- process.stdin.on('data', onData);
107
- });
108
- }
109
-
110
- // ─── SelectMenu ───────────────────────────────────────────────────────────────
111
-
112
- class SelectMenu {
113
- constructor(options) {
114
- this.options = options;
115
- this.selectedIdx = 0;
116
- }
117
-
118
- moveUp() { this.selectedIdx = Math.max(0, this.selectedIdx - 1); }
119
- moveDown() { this.selectedIdx = Math.min(this.options.length - 1, this.selectedIdx + 1); }
120
- current() { return this.options[this.selectedIdx]; }
121
-
122
- render() {
123
- return this.options.map((opt, i) => {
124
- if (i === this.selectedIdx) return ` \x1b[7m › ${opt} \x1b[27m`;
125
- return ` ${opt}`;
126
- }).join('\n');
127
- }
128
- }
129
-
130
- module.exports = { StatusBar, interactiveSelect, SelectMenu };