@make-u-free/migi 0.4.0 → 0.4.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.
Files changed (2) hide show
  1. package/bin/migi.js +21 -12
  2. package/package.json +1 -1
package/bin/migi.js CHANGED
@@ -86,6 +86,7 @@ async function readChatInput() {
86
86
  const lines = ['']
87
87
  let curLine = 0
88
88
  let drawnLines = 0
89
+ let lastLineCount = 0
89
90
 
90
91
  emitKeypressEvents(process.stdin)
91
92
  if (process.stdin.isTTY) process.stdin.setRawMode(true)
@@ -93,29 +94,37 @@ async function readChatInput() {
93
94
  function draw() {
94
95
  const w = process.stdout.columns || 80
95
96
 
96
- // 前回描画分をクリア
97
- if (drawnLines > 0) {
98
- process.stdout.write(`\x1b[${drawnLines}A\x1b[1G`)
99
- for (let i = 0; i < drawnLines; i++) {
100
- process.stdout.write('\x1b[2K\n')
101
- }
102
- process.stdout.write(`\x1b[${drawnLines}A\x1b[1G`)
97
+ // 行数が変わっていない(通常の文字入力)→ 現在行だけ上書き。セパレーター・ガイドは触らない
98
+ if (lines.length === lastLineCount && drawnLines > 0) {
99
+ const prefix = curLine === 0 ? PFIRST : PCONT
100
+ process.stdout.write('\r\x1b[K' + chalk.cyan(prefix) + lines[curLine])
101
+ return
103
102
  }
104
103
 
105
- // 入力行 + セパレーター + ガイド を描画
104
+ // 行数変化 or 初回 全体を再描画
105
+ lastLineCount = lines.length
106
106
  const allLines = [
107
107
  ...lines.map((l, i) => chalk.cyan(i === 0 ? PFIRST : PCONT) + l),
108
108
  chalk.dim('─'.repeat(w)),
109
109
  chalk.dim(` ✦ ${model} · Shift+Enterで改行 / Enterで送信`)
110
110
  ]
111
+
112
+ let buf = ''
113
+ if (drawnLines > 0) {
114
+ buf += `\x1b[${drawnLines}A\x1b[1G`
115
+ for (let i = 0; i < drawnLines; i++) buf += '\x1b[2K\n'
116
+ buf += `\x1b[${drawnLines}A\x1b[1G`
117
+ }
118
+
111
119
  drawnLines = allLines.length
112
- process.stdout.write(allLines.join('\n') + '\n')
120
+ buf += allLines.join('\n') + '\n'
113
121
 
114
- // カーソルを入力行の末尾に移動
115
122
  const linesBelow = drawnLines - curLine
116
- if (linesBelow > 0) process.stdout.write(`\x1b[${linesBelow}A`)
123
+ if (linesBelow > 0) buf += `\x1b[${linesBelow}A`
117
124
  const col = (curLine === 0 ? PFIRST : PCONT).length + lines[curLine].length + 1
118
- process.stdout.write(`\x1b[${col}G`)
125
+ buf += `\x1b[${col}G`
126
+
127
+ process.stdout.write(buf)
119
128
  }
120
129
 
121
130
  draw()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@make-u-free/migi",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Your AI right-hand agent. Works anywhere, with any LLM API.",
5
5
  "type": "module",
6
6
  "bin": {