novaprime 1.3.0 → 1.3.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/prompt.js +27 -53
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "novaprime",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "NovaPrime — an AI coding assistant in your terminal, powered by GLM.",
5
5
  "bin": {
6
6
  "novaprime": "bin/novaprime.js"
package/src/prompt.js CHANGED
@@ -1,66 +1,40 @@
1
1
  'use strict';
2
- const ESC = String.fromCharCode(27);
2
+ const readline = require('readline');
3
+
4
+ // Use Node's readline — it correctly handles long lines, wrapping, editing and paste.
5
+ let rl = null;
6
+ function getRl() {
7
+ if (!rl) {
8
+ rl = readline.createInterface({ input: process.stdin, output: process.stdout, historySize: 200 });
9
+ rl.on('SIGINT', () => { try { process.stdout.write('\n'); } catch (_) {} process.exit(0); });
10
+ }
11
+ return rl;
12
+ }
3
13
 
4
- // Raw-mode line reader. Draws optional frame, edits a single line in place,
5
- // and (unlike readline) never clears the lines below — so a box border stays visible.
6
- function readRaw(prompt, opts = {}) {
14
+ function ask(prompt) {
7
15
  return new Promise((resolve) => {
8
- const stdin = process.stdin, stdout = process.stdout;
9
-
10
- // Non-TTY fallback (piped / one-shot): just read a line.
11
- if (!stdin.isTTY) {
12
- stdin.resume(); stdin.setEncoding('utf8');
13
- let acc = '';
14
- const onData = (d) => {
15
- acc += d;
16
- const nl = acc.indexOf('\n');
17
- if (nl >= 0) { stdin.removeListener('data', onData); stdin.pause(); resolve(acc.slice(0, nl).replace(/\r$/, '')); }
18
- };
19
- stdin.on('data', onData);
20
- return;
21
- }
22
-
23
- let buf = '';
24
- if (opts.draw) opts.draw();
25
- stdin.setRawMode(true); stdin.resume(); stdin.setEncoding('utf8');
26
- const redraw = () => stdout.write('\r' + ESC + '[2K' + prompt + buf);
27
- redraw();
28
-
29
- const done = (val) => {
30
- stdin.setRawMode(false); stdin.pause(); stdin.removeListener('data', onData);
31
- if (opts.after) opts.after();
32
- resolve(val);
33
- };
34
- function onData(s) {
35
- let i = 0;
36
- while (i < s.length) {
37
- const ch = s[i], code = s.charCodeAt(i);
38
- if (ch === '\r' || ch === '\n') { return done(buf); }
39
- if (code === 3) { stdin.setRawMode(false); stdout.write('\n'); process.exit(0); } // Ctrl+C
40
- if (code === 4) { return done(buf.length ? buf : null); } // Ctrl+D
41
- if (code === 127 || code === 8) { buf = buf.slice(0, -1); redraw(); i++; continue; } // backspace
42
- if (code === 27) { i += (s[i + 1] === '[') ? 3 : 1; continue; } // skip arrow/escape seq
43
- if (code < 32) { i++; continue; }
44
- buf += ch; redraw(); i++;
45
- }
46
- }
47
- stdin.on('data', onData);
16
+ const r = getRl();
17
+ r.question(prompt || '', (answer) => resolve(answer));
48
18
  });
49
19
  }
50
20
 
51
- function ask(prompt) { return readRaw(prompt || ''); }
52
- function confirm(message) { return readRaw(message + ' (y/N) ').then((a) => /^y(es)?$/i.test((a || '').trim())); }
21
+ function confirm(message) {
22
+ return ask(message + ' (y/N) ').then((a) => /^y(es)?$/i.test((a || '').trim()));
23
+ }
53
24
 
54
- // Full chat box that stays drawn while typing (top + input line + bottom).
25
+ // Chat input: top border above (safe), readline handles the input line,
26
+ // and the bottom border is drawn AFTER submit so the message shows as a complete box.
55
27
  function boxInput(top, bottom, prompt) {
56
- return readRaw(prompt, {
57
- draw: () => process.stdout.write('\n' + top + '\n\n' + bottom + '\n' + ESC + '[2A'),
58
- after: () => process.stdout.write('\r\n\n'),
28
+ return new Promise((resolve) => {
29
+ process.stdout.write(top + '\n');
30
+ const r = getRl();
31
+ r.question(prompt, (answer) => {
32
+ process.stdout.write(bottom + '\n');
33
+ resolve(answer);
34
+ });
59
35
  });
60
36
  }
61
37
 
62
- function close() {
63
- try { if (process.stdin.isTTY) process.stdin.setRawMode(false); process.stdin.pause(); } catch (_) {}
64
- }
38
+ function close() { if (rl) { rl.close(); rl = null; } }
65
39
 
66
40
  module.exports = { ask, confirm, boxInput, close };