@make-u-free/migi 0.4.5 → 0.4.6
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 +16 -6
- package/package.json +1 -1
package/bin/migi.js
CHANGED
|
@@ -87,10 +87,18 @@ async function readChatInput() {
|
|
|
87
87
|
let curLine = 0
|
|
88
88
|
let drawnLines = 0
|
|
89
89
|
let cursorLine = 0 // カーソルの物理行(drawn area 先頭からの offset)
|
|
90
|
+
let drawPending = false
|
|
90
91
|
|
|
91
92
|
emitKeypressEvents(process.stdin)
|
|
92
93
|
if (process.stdin.isTTY) process.stdin.setRawMode(true)
|
|
93
94
|
|
|
95
|
+
// ペースト等の連続入力をまとめて1回の描画にするためのデバウンス
|
|
96
|
+
function scheduleDraw() {
|
|
97
|
+
if (drawPending) return
|
|
98
|
+
drawPending = true
|
|
99
|
+
setImmediate(() => { drawPending = false; draw() })
|
|
100
|
+
}
|
|
101
|
+
|
|
94
102
|
function draw() {
|
|
95
103
|
const w = process.stdout.columns || 80
|
|
96
104
|
const newLines = [
|
|
@@ -136,11 +144,12 @@ async function readChatInput() {
|
|
|
136
144
|
|
|
137
145
|
const onKey = (str, key) => {
|
|
138
146
|
if (!key) {
|
|
139
|
-
if (str) { lines[curLine] += str;
|
|
147
|
+
if (str) { lines[curLine] += str; scheduleDraw() }
|
|
140
148
|
return
|
|
141
149
|
}
|
|
142
150
|
|
|
143
151
|
if (key.ctrl && key.name === 'c') {
|
|
152
|
+
if (drawPending) { drawPending = false; draw() } // カーソル位置を確定させてから終了
|
|
144
153
|
process.stdout.write(`\x1b[${drawnLines - 1 - curLine}B\n`)
|
|
145
154
|
process.stdin.removeListener('keypress', onKey)
|
|
146
155
|
if (process.stdin.isTTY) process.stdin.setRawMode(false)
|
|
@@ -153,9 +162,10 @@ async function readChatInput() {
|
|
|
153
162
|
if (key.meta || key.shift) {
|
|
154
163
|
lines.splice(curLine + 1, 0, '')
|
|
155
164
|
curLine++
|
|
156
|
-
|
|
165
|
+
scheduleDraw()
|
|
157
166
|
} else {
|
|
158
|
-
// Enter →
|
|
167
|
+
// Enter → 送信(保留中の描画があれば先に確定)
|
|
168
|
+
if (drawPending) { drawPending = false; draw() }
|
|
159
169
|
const content = lines.join('\n').trim()
|
|
160
170
|
if (!content) return
|
|
161
171
|
process.stdout.write(`\x1b[${drawnLines - 1 - curLine}B\n`)
|
|
@@ -169,18 +179,18 @@ async function readChatInput() {
|
|
|
169
179
|
if (key.name === 'backspace') {
|
|
170
180
|
if (lines[curLine].length > 0) {
|
|
171
181
|
lines[curLine] = lines[curLine].slice(0, -1)
|
|
172
|
-
|
|
182
|
+
scheduleDraw()
|
|
173
183
|
} else if (curLine > 0) {
|
|
174
184
|
lines.splice(curLine, 1)
|
|
175
185
|
curLine--
|
|
176
|
-
|
|
186
|
+
scheduleDraw()
|
|
177
187
|
}
|
|
178
188
|
return
|
|
179
189
|
}
|
|
180
190
|
|
|
181
191
|
if (str && !key.ctrl && !key.meta) {
|
|
182
192
|
lines[curLine] += str
|
|
183
|
-
|
|
193
|
+
scheduleDraw()
|
|
184
194
|
}
|
|
185
195
|
}
|
|
186
196
|
|