@make-u-free/migi 0.4.1 → 0.4.3
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/bin/migi.js +17 -3
- package/package.json +1 -1
package/bin/migi.js
CHANGED
|
@@ -86,23 +86,36 @@ async function readChatInput() {
|
|
|
86
86
|
const lines = ['']
|
|
87
87
|
let curLine = 0
|
|
88
88
|
let drawnLines = 0
|
|
89
|
+
let lastLineCount = 0
|
|
90
|
+
let cursorLine = 0 // カーソルが実際にいる物理行(drawn area 先頭からの offset)
|
|
89
91
|
|
|
90
92
|
emitKeypressEvents(process.stdin)
|
|
91
93
|
if (process.stdin.isTTY) process.stdin.setRawMode(true)
|
|
92
94
|
|
|
93
95
|
function draw() {
|
|
94
96
|
const w = process.stdout.columns || 80
|
|
97
|
+
|
|
98
|
+
// 行数が変わっていない(通常の文字入力)→ 現在行だけ上書き。セパレーター・ガイドは触らない
|
|
99
|
+
if (lines.length === lastLineCount && drawnLines > 0) {
|
|
100
|
+
const prefix = curLine === 0 ? PFIRST : PCONT
|
|
101
|
+
process.stdout.write('\r\x1b[K' + chalk.cyan(prefix) + lines[curLine])
|
|
102
|
+
cursorLine = curLine
|
|
103
|
+
return
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// 行数変化 or 初回 → 全体を再描画
|
|
107
|
+
lastLineCount = lines.length
|
|
95
108
|
const allLines = [
|
|
96
109
|
...lines.map((l, i) => chalk.cyan(i === 0 ? PFIRST : PCONT) + l),
|
|
97
110
|
chalk.dim('─'.repeat(w)),
|
|
98
111
|
chalk.dim(` ✦ ${model} · Shift+Enterで改行 / Enterで送信`)
|
|
99
112
|
]
|
|
100
113
|
|
|
101
|
-
// すべての操作を1つのバッファにまとめてから一括書き込み(ちらつき防止)
|
|
102
114
|
let buf = ''
|
|
103
|
-
|
|
104
115
|
if (drawnLines > 0) {
|
|
105
|
-
|
|
116
|
+
// cursorLine = カーソルの現在位置。先頭行まで戻ってから全行クリア
|
|
117
|
+
if (cursorLine > 0) buf += `\x1b[${cursorLine}A`
|
|
118
|
+
buf += `\x1b[1G`
|
|
106
119
|
for (let i = 0; i < drawnLines; i++) buf += '\x1b[2K\n'
|
|
107
120
|
buf += `\x1b[${drawnLines}A\x1b[1G`
|
|
108
121
|
}
|
|
@@ -115,6 +128,7 @@ async function readChatInput() {
|
|
|
115
128
|
const col = (curLine === 0 ? PFIRST : PCONT).length + lines[curLine].length + 1
|
|
116
129
|
buf += `\x1b[${col}G`
|
|
117
130
|
|
|
131
|
+
cursorLine = curLine
|
|
118
132
|
process.stdout.write(buf)
|
|
119
133
|
}
|
|
120
134
|
|