diff --git a/src/common/highlight.ts b/src/common/highlight.ts index 3c9c58f..af29ece 100644 --- a/src/common/highlight.ts +++ b/src/common/highlight.ts @@ -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; } } diff --git a/src/common/row.ts b/src/common/row.ts index 48113a7..1b2a65b 100644 --- a/src/common/row.ts +++ b/src/common/row.ts @@ -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; }