Skip to content

Commit b4f504e

Browse files
committed
fix: Handle standalone "\r" before overwrite removal
1 parent d756d68 commit b4f504e

2 files changed

Lines changed: 16 additions & 16 deletions

File tree

js/util/console-color.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ export class ColoredConsole {
8383
case 1: this.state.bold = true; break;
8484
case 3: this.state.italic = true; break;
8585
case 4: this.state.underline = true; break;
86-
case 5: this.state.blink = true; break;
87-
case 6: this.state.rapidBlink = true; break;
86+
case 5: this.state.blink = true; this.state.rapidBlink = false; break;
87+
case 6: this.state.rapidBlink = true; this.state.blink = false; break;
8888
case 8: this.state.secret = true; break;
8989
case 9: this.state.strikethrough = true; break;
9090
case 22: this.state.bold = false; break;
@@ -130,26 +130,25 @@ export class ColoredConsole {
130130
}
131131

132132
for (const line of this.state.lines) {
133-
if (this.state.carriageReturn && line !== "\n") {
134-
if (fragment.childElementCount) {
135-
fragment.removeChild(fragment.lastChild);
136-
}
137-
}
138133
// A lone \r is a pure carriage-return signal — update state but don't
139134
// create a DOM node for it (it has no renderable content).
140135
if (line === "\r") {
141136
this.state.carriageReturn = true;
142137
continue;
143138
}
139+
if (this.state.carriageReturn && line !== "\n") {
140+
if (fragment.childElementCount) {
141+
fragment.removeChild(fragment.lastChild);
142+
}
143+
}
144144
const hadCarriageReturn = line.endsWith("\r");
145145
fragment.appendChild(this.processLine(line.replace(/\r/g, "")));
146146
this.state.carriageReturn = hadCarriageReturn;
147147
}
148148

149149
if (
150150
prevCarriageReturn &&
151-
this.state.lines[0] !== "\n" &&
152-
this.state.lines[0] !== "\r" &&
151+
fragment.childElementCount > 0 &&
153152
this.targetElement.lastChild
154153
) {
155154
this.targetElement.replaceChild(fragment, this.targetElement.lastChild);

src/util/console-color.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,11 @@ export class ColoredConsole {
106106
break;
107107
case 5:
108108
this.state.blink = true;
109+
this.state.rapidBlink = false;
109110
break;
110111
case 6:
111112
this.state.rapidBlink = true;
113+
this.state.blink = false;
112114
break;
113115
case 8:
114116
this.state.secret = true;
@@ -209,26 +211,25 @@ export class ColoredConsole {
209211
}
210212

211213
for (const line of this.state.lines) {
212-
if (this.state.carriageReturn && line !== "\n") {
213-
if (fragment.childElementCount) {
214-
fragment.removeChild(fragment.lastChild!);
215-
}
216-
}
217214
// A lone \r is a pure carriage-return signal — update state but don't
218215
// create a DOM node for it (it has no renderable content).
219216
if (line === "\r") {
220217
this.state.carriageReturn = true;
221218
continue;
222219
}
220+
if (this.state.carriageReturn && line !== "\n") {
221+
if (fragment.childElementCount) {
222+
fragment.removeChild(fragment.lastChild!);
223+
}
224+
}
223225
const hadCarriageReturn = line.endsWith("\r");
224226
fragment.appendChild(this.processLine(line.replace(/\r/g, "")));
225227
this.state.carriageReturn = hadCarriageReturn;
226228
}
227229

228230
if (
229231
prevCarriageReturn &&
230-
this.state.lines[0] !== "\n" &&
231-
this.state.lines[0] !== "\r" &&
232+
fragment.childElementCount > 0 &&
232233
this.targetElement.lastChild
233234
) {
234235
this.targetElement.replaceChild(fragment, this.targetElement.lastChild!);

0 commit comments

Comments
 (0)