fix: arrow keys in prompts now move cursor, also implements delete key
This commit is contained in:
@@ -44,7 +44,9 @@ export class TerminalLayout {
|
||||
clearTimeout(this.debounceTimer);
|
||||
}
|
||||
this.debounceTimer = setTimeout(
|
||||
() => this.renderLayout(),
|
||||
() => {
|
||||
this.renderLayout();
|
||||
},
|
||||
this.debounceDelay,
|
||||
);
|
||||
}
|
||||
@@ -76,6 +78,10 @@ export class TerminalLayout {
|
||||
block.renderInternal(usedLines + 1);
|
||||
usedLines += lines.length;
|
||||
}
|
||||
for (const name of this.layoutOrder) {
|
||||
const block = this.blocks[name];
|
||||
block.runPostRenderAction?.();
|
||||
}
|
||||
}
|
||||
|
||||
clearAll() {
|
||||
@@ -217,7 +223,9 @@ export class TerminalBlock {
|
||||
const baseRow = startRow ?? this.lastRenderRow;
|
||||
const excessLines = this.renderHeight - this.renderLines.length;
|
||||
for (let i = 0; i < excessLines; i++) {
|
||||
const moveToLine = `[${baseRow + this.renderLines.length + i};1H[2K`;
|
||||
const moveToLine = `\x1b[${
|
||||
baseRow + this.renderLines.length + i
|
||||
};1H\x1b[2K`;
|
||||
Deno.stdout.writeSync(new TextEncoder().encode(moveToLine));
|
||||
}
|
||||
|
||||
@@ -254,6 +262,17 @@ export class TerminalBlock {
|
||||
return this.fixedHeight ?? 0;
|
||||
}
|
||||
|
||||
private _postRenderAction?: () => void;
|
||||
setPostRenderAction(action: (this: TerminalBlock) => void) {
|
||||
this._postRenderAction = action;
|
||||
}
|
||||
runPostRenderAction() {
|
||||
if (this._postRenderAction) {
|
||||
this._postRenderAction.call(this);
|
||||
this._postRenderAction = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
get lineCount() {
|
||||
return this.renderLines.length;
|
||||
}
|
||||
|
Reference in New Issue
Block a user