caroushell 0.1.12 → 0.1.13
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/dist/app.js +6 -4
- package/dist/keyboard.js +1 -24
- package/dist/terminal.js +18 -2
- package/package.json +1 -1
package/dist/app.js
CHANGED
|
@@ -142,7 +142,7 @@ class App {
|
|
|
142
142
|
}
|
|
143
143
|
async run() {
|
|
144
144
|
await this.init();
|
|
145
|
-
this.keyboard.
|
|
145
|
+
this.keyboard.enableCapture();
|
|
146
146
|
this.keyboard.on("key", (evt) => {
|
|
147
147
|
void this.handleKey(evt);
|
|
148
148
|
});
|
|
@@ -174,7 +174,8 @@ class App {
|
|
|
174
174
|
this.terminal.renderBlock(lines);
|
|
175
175
|
// Ensure command output starts on the next line
|
|
176
176
|
this.terminal.write("\n");
|
|
177
|
-
this.keyboard.
|
|
177
|
+
this.keyboard.disableCapture();
|
|
178
|
+
this.terminal.disableWrites();
|
|
178
179
|
try {
|
|
179
180
|
const storeInHistory = await (0, spawner_1.runUserCommand)(cmd);
|
|
180
181
|
if (storeInHistory) {
|
|
@@ -182,13 +183,14 @@ class App {
|
|
|
182
183
|
}
|
|
183
184
|
}
|
|
184
185
|
finally {
|
|
185
|
-
this.
|
|
186
|
+
this.terminal.enableWrites();
|
|
187
|
+
this.keyboard.enableCapture();
|
|
186
188
|
}
|
|
187
189
|
}
|
|
188
190
|
exit() {
|
|
189
191
|
// Clear terminal contents before shutting down to leave a clean screen.
|
|
190
192
|
this.terminal.renderBlock([]);
|
|
191
|
-
this.keyboard.
|
|
193
|
+
this.keyboard.disableCapture();
|
|
192
194
|
process.exit(0);
|
|
193
195
|
}
|
|
194
196
|
async tryAutocompleteFile() {
|
package/dist/keyboard.js
CHANGED
|
@@ -50,38 +50,15 @@ for (const seq of Object.keys(KEYMAP)) {
|
|
|
50
50
|
class Keyboard extends events_1.EventEmitter {
|
|
51
51
|
constructor() {
|
|
52
52
|
super(...arguments);
|
|
53
|
-
this.active = false;
|
|
54
53
|
this.capturing = false;
|
|
55
54
|
this.buffer = '';
|
|
56
55
|
this.stdin = process.stdin;
|
|
57
56
|
this.onData = (data) => this.handleData(data);
|
|
58
57
|
}
|
|
59
|
-
start() {
|
|
60
|
-
if (this.active)
|
|
61
|
-
return;
|
|
62
|
-
this.active = true;
|
|
63
|
-
this.stdin.setEncoding('utf8');
|
|
64
|
-
this.enableCapture();
|
|
65
|
-
}
|
|
66
|
-
stop() {
|
|
67
|
-
if (!this.active)
|
|
68
|
-
return;
|
|
69
|
-
this.active = false;
|
|
70
|
-
this.disableCapture();
|
|
71
|
-
}
|
|
72
|
-
pause() {
|
|
73
|
-
if (!this.active)
|
|
74
|
-
return;
|
|
75
|
-
this.disableCapture();
|
|
76
|
-
}
|
|
77
|
-
resume() {
|
|
78
|
-
if (!this.active)
|
|
79
|
-
return;
|
|
80
|
-
this.enableCapture();
|
|
81
|
-
}
|
|
82
58
|
enableCapture() {
|
|
83
59
|
if (this.capturing)
|
|
84
60
|
return;
|
|
61
|
+
this.stdin.setEncoding('utf8');
|
|
85
62
|
if (this.stdin.isTTY)
|
|
86
63
|
this.stdin.setRawMode(true);
|
|
87
64
|
this.stdin.on('data', this.onData);
|
package/dist/terminal.js
CHANGED
|
@@ -21,6 +21,16 @@ class Terminal {
|
|
|
21
21
|
this.activeRows = 0;
|
|
22
22
|
this.cursorRow = 0;
|
|
23
23
|
this.cursorCol = 0;
|
|
24
|
+
this.writesDisabled = false;
|
|
25
|
+
}
|
|
26
|
+
disableWrites() {
|
|
27
|
+
this.writesDisabled = true;
|
|
28
|
+
}
|
|
29
|
+
enableWrites() {
|
|
30
|
+
this.writesDisabled = false;
|
|
31
|
+
}
|
|
32
|
+
canWrite() {
|
|
33
|
+
return !this.writesDisabled;
|
|
24
34
|
}
|
|
25
35
|
moveCursorToTopOfBlock() {
|
|
26
36
|
if (this.activeRows === 0)
|
|
@@ -51,6 +61,8 @@ class Terminal {
|
|
|
51
61
|
}
|
|
52
62
|
}
|
|
53
63
|
write(text) {
|
|
64
|
+
if (!this.canWrite())
|
|
65
|
+
return;
|
|
54
66
|
this.out.write(text);
|
|
55
67
|
}
|
|
56
68
|
hideCursor() {
|
|
@@ -61,6 +73,8 @@ class Terminal {
|
|
|
61
73
|
}
|
|
62
74
|
// Render a block of lines by clearing previous block (if any) and writing fresh
|
|
63
75
|
renderBlock(lines, cursorRow, cursorCol) {
|
|
76
|
+
if (!this.canWrite())
|
|
77
|
+
return;
|
|
64
78
|
this.withCork(() => {
|
|
65
79
|
this.moveCursorToTopOfBlock();
|
|
66
80
|
if (this.activeRows > 0) {
|
|
@@ -68,9 +82,9 @@ class Terminal {
|
|
|
68
82
|
readline_1.default.clearScreenDown(this.out);
|
|
69
83
|
}
|
|
70
84
|
for (let i = 0; i < lines.length; i++) {
|
|
71
|
-
this.
|
|
85
|
+
this.write(lines[i]);
|
|
72
86
|
if (i < lines.length - 1)
|
|
73
|
-
this.
|
|
87
|
+
this.write("\n");
|
|
74
88
|
}
|
|
75
89
|
this.activeRows = lines.length;
|
|
76
90
|
this.cursorRow = Math.max(0, this.activeRows - 1);
|
|
@@ -87,6 +101,8 @@ class Terminal {
|
|
|
87
101
|
});
|
|
88
102
|
}
|
|
89
103
|
moveCursorTo(lineIndex, column) {
|
|
104
|
+
if (!this.canWrite())
|
|
105
|
+
return;
|
|
90
106
|
if (this.activeRows === 0)
|
|
91
107
|
return;
|
|
92
108
|
const safeLine = Math.min(Math.max(lineIndex, 0), Math.max(0, this.activeRows - 1));
|