fix: flickering eyebleed

This commit is contained in:
Emmaline Autumn 2025-05-20 10:53:37 -06:00
parent e5b173155a
commit 90f1547e02
3 changed files with 37 additions and 21 deletions

View File

@ -1,6 +1,10 @@
# Changelog # Changelog
## v1.0.1 (2025-07-25) ## v1.0.2 (2025-05-20)
<!-- auto-changelog -->
## v1.0.1 (2025-05-7)
<!-- auto-changelog --> <!-- auto-changelog -->
@ -8,7 +12,7 @@
- help flags can cause issues - help flags can cause issues
## v1.0.0 (2025-07-25) ## v1.0.0 (2025-05-7)
### Features ### Features

View File

@ -111,6 +111,8 @@ export class TerminalBlock {
private renderHeight: number = 0; private renderHeight: number = 0;
private lastRenderRow = 1; private lastRenderRow = 1;
private lastRendered: string[] = [];
private preserveHistory = false; private preserveHistory = false;
constructor(private prepend: string = "") {} constructor(private prepend: string = "") {}
@ -193,27 +195,37 @@ export class TerminalBlock {
} }
renderInternal(startRow?: number) { renderInternal(startRow?: number) {
this.lastRenderRow = startRow ?? this.lastRenderRow; const outputLines: string[] = [];
this.clear(); // uses old renderedLineCount
const outputLines = this.renderLines.map((line) => for (let i = 0; i < this.renderLines.length; i++) {
`${this.prepend}${line}\x1b[K` const line = `${this.prepend}${this.renderLines[i]}`;
); const previous = this.lastRendered[i];
const output = outputLines.join("\n"); if (line !== previous) {
if (startRow !== undefined) { const moveToLine = `\x1b[${(startRow ?? this.lastRenderRow) + i};1H`;
const moveCursor = `\x1b[${startRow};1H`; outputLines.push(moveToLine + line + "\x1b[K");
Deno.stdout.writeSync(new TextEncoder().encode(moveCursor + output)); }
} else {
Deno.stdout.writeSync(new TextEncoder().encode(output));
} }
// update rendered line count *after* rendering if (this.lastRendered.length > this.renderLines.length) {
this.renderedLineCount = outputLines.reduce( const baseRow = startRow ?? this.lastRenderRow;
(count, line) => for (let i = this.renderLines.length; i < this.lastRendered.length; i++) {
count + const moveToLine = `\x1b[${baseRow + i};1H\x1b[2K`;
Math.ceil((line.length) / (Deno.consoleSize().columns || 80)), Deno.stdout.writeSync(new TextEncoder().encode(moveToLine));
0, }
); }
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`;
Deno.stdout.writeSync(new TextEncoder().encode(moveToLine));
}
this.lastRendered = [...this.renderLines];
this.renderedLineCount = this.renderHeight;
this.lastRenderRow = baseRow;
const output = outputLines.join("\n");
Deno.stdout.writeSync(new TextEncoder().encode(output));
} }
clear() { clear() {

View File

@ -3,7 +3,7 @@
"version": "1.0.1", "version": "1.0.1",
"license": "GPL 3.0", "license": "GPL 3.0",
"tasks": { "tasks": {
"dev": "deno run -A --env-file=.env --watch main.ts", "dev": "deno run -A --env-file=.env main.ts",
"compile": "deno compile -o compare-form-fields.exe --target x86_64-pc-windows-msvc -R ./main.ts", "compile": "deno compile -o compare-form-fields.exe --target x86_64-pc-windows-msvc -R ./main.ts",
"install": "deno install -fgq --import-map ./deno.json -n checkfields -R ./main.ts", "install": "deno install -fgq --import-map ./deno.json -n checkfields -R ./main.ts",
"debug": "deno run -A --env-file=.env --inspect-wait --watch main.ts" "debug": "deno run -A --env-file=.env --inspect-wait --watch main.ts"