Skip to content

Commit b0c5262

Browse files
committed
fix cursor bug
1 parent 246ca6c commit b0c5262

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

packages/core/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @clack/core
22

3+
## 0.0.7
4+
5+
### Patch Changes
6+
7+
- Fix cursor bug
8+
39
## 0.0.6
410

511
### Patch Changes

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@clack/core",
3-
"version": "0.0.6",
3+
"version": "0.0.7",
44
"type": "module",
55
"exports": {
66
".": {

packages/core/src/prompts/prompt.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export interface PromptOptions<Self extends Prompt> {
3737
validate?: ((value: string) => string | void) | undefined;
3838
input?: Readable;
3939
output?: Writable;
40+
debug?: boolean;
4041
}
4142

4243
export type State = 'initial' | 'active' | 'cancel' | 'submit' | 'error';
@@ -188,10 +189,11 @@ export default class Prompt {
188189
const frame = this._render(this) ?? '';
189190
if (frame === this._prevFrame) return;
190191

191-
if (this.state !== 'initial') {
192+
if (this.state === 'initial') {
193+
this.output.write(cursor.hide);
194+
} else {
192195
const diff = diffLines(this._prevFrame, frame);
193196
this.restoreCursor();
194-
195197
// If a single line has changed, only update that line
196198
if (diff && diff?.length === 1) {
197199
const diffLine = diff[0];
@@ -200,7 +202,6 @@ export default class Prompt {
200202
const lines = frame.split('\n');
201203
this.output.write(lines[diffLine]);
202204
this._prevFrame = frame;
203-
// TODO: handle wrapping
204205
this.output.write(cursor.move(0, lines.length - diffLine - 1))
205206
return;
206207
// If many lines have changed, rerender everything past the first line
@@ -212,14 +213,10 @@ export default class Prompt {
212213
const newLines = lines.slice(diffLine);
213214
this.output.write(newLines.join('\n'));
214215
this._prevFrame = frame;
215-
// TODO: handle wrapping
216-
this.output.write(cursor.move(0, newLines.length - 1))
217216
return;
218217
}
219218

220219
this.output.write(erase.down());
221-
} else {
222-
this.output.write(cursor.hide);
223220
}
224221

225222
this.output.write(frame);

0 commit comments

Comments
 (0)