Optimize highlighting escape sequences
This commit is contained in:
parent
a3a8fba6e2
commit
9458794fa3
@ -1,4 +1,4 @@
|
||||
import Ansi, { AnsiColor } from './ansi.ts';
|
||||
import Ansi from './ansi.ts';
|
||||
|
||||
export enum HighlightType {
|
||||
None,
|
||||
@ -11,6 +11,6 @@ export function highlightToColor(type: HighlightType): string {
|
||||
return Ansi.color256(196);
|
||||
|
||||
default:
|
||||
return Ansi.color(AnsiColor.FgDefault);
|
||||
return Ansi.ResetFormatting;
|
||||
}
|
||||
}
|
||||
|
@ -179,13 +179,21 @@ export class Row {
|
||||
const end = Math.min(len, this.rsize);
|
||||
const start = Math.min(offset, len);
|
||||
let result = '';
|
||||
let currentHighlight = HighlightType.None;
|
||||
|
||||
for (let i = start; i < end; i++) {
|
||||
result += highlightToColor(this.hl[i]);
|
||||
const highlightType = this.hl[i];
|
||||
|
||||
if (highlightType !== currentHighlight) {
|
||||
currentHighlight = highlightType;
|
||||
result += highlightToColor(highlightType);
|
||||
}
|
||||
|
||||
result += this.rchars[i];
|
||||
result += Ansi.ResetFormatting;
|
||||
}
|
||||
|
||||
result += Ansi.ResetFormatting;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user