diff --git a/demo/colors.ts b/demo/colors.ts index 55249c1..367c21a 100644 --- a/demo/colors.ts +++ b/demo/colors.ts @@ -6,10 +6,10 @@ import Ansi, { AnsiColor, Ground } from '../src/common/ansi.ts'; // Display table of the 256 type color console escape codes // ---------------------------------------------------------------------------- -const addColor = (fore: number | string, back: number | string): string => { +const addColor = (fore: string, back: string): string => { let output = ''; - output += (typeof fore === 'number') ? Ansi.color(fore) : fore; - output += (typeof back === 'number') ? Ansi.color(back) : back; + output += fore; + output += back; return output; }; @@ -20,7 +20,7 @@ const padNum = (num: number): string => const colorBlock = ( start: number, end: number, - block: (i: number) => [string | number, string | number], + block: (i: number) => [string, string], ): string => { let output = ''; @@ -39,16 +39,34 @@ function print16colorTable(): void { let end = start + 8; let blocks = [ - colorBlock(start, end, (i: number) => [i, AnsiColor.BgBlack]), - colorBlock(start, end, (i: number) => [i, AnsiColor.BgBrightWhite]), + colorBlock( + start, + end, + (i: number) => [Ansi.textFormat(i), Ansi.color.background.Black], + ), + colorBlock( + start, + end, + (i: number) => [Ansi.textFormat(i), Ansi.color.background.BrightWhite], + ), ]; start += 10; end += 10; - blocks.push(colorBlock(start, end, (i: number) => [AnsiColor.FgBlack, i])); blocks.push( - colorBlock(start, end, (i: number) => [AnsiColor.FgBrightWhite, i]), + colorBlock( + start, + end, + (i: number) => [Ansi.color.Black, Ansi.textFormat(i)], + ), + ); + blocks.push( + colorBlock( + start, + end, + (i: number) => [Ansi.color.BrightWhite, Ansi.textFormat(i)], + ), ); return blocks.join(' '.repeat(5)); @@ -87,22 +105,26 @@ function print256colorTable(): void { colorBlock( start, end, - (i: number) => [Ansi.color256(i, Ground.Fore), AnsiColor.BgBlack], + ( + i: number, + ) => [Ansi.color256(i, Ground.Fore), Ansi.color.background.Black], ), colorBlock( start, end, - (i: number) => [Ansi.color256(i, Ground.Fore), AnsiColor.BgBrightWhite], + ( + i: number, + ) => [Ansi.color256(i, Ground.Fore), Ansi.color.background.BrightWhite], ), colorBlock( start, end, - (i: number) => [AnsiColor.FgBlack, Ansi.color256(i, Ground.Back)], + (i: number) => [Ansi.color.Black, Ansi.color256(i, Ground.Back)], ), colorBlock( start, end, - (i: number) => [AnsiColor.FgBrightWhite, Ansi.color256(i, Ground.Back)], + (i: number) => [Ansi.color.BrightWhite, Ansi.color256(i, Ground.Back)], ), ]; diff --git a/src/common/all_test.ts b/src/common/all_test.ts index e4d160a..eba7de3 100644 --- a/src/common/all_test.ts +++ b/src/common/all_test.ts @@ -644,12 +644,12 @@ const RowTest = { const normalRow = Row.from('\tFor whom the bell tolls'); assertEquivalent( normalRow.find('who', 0, SearchDirection.Forward), - Some(8), + Some(5), ); assertEquals(normalRow.find('foo', 0, SearchDirection.Forward), None); const emojiRow = Row.from('\tšŸ˜ŗšŸ˜øšŸ˜¹'); - assertEquivalent(emojiRow.find('šŸ˜¹', 0, SearchDirection.Forward), Some(6)); + assertEquivalent(emojiRow.find('šŸ˜¹', 0, SearchDirection.Forward), Some(3)); assertEquals(emojiRow.find('šŸ¤°šŸ¼', 10, SearchDirection.Forward), None); }, '.find backwards': () => { diff --git a/src/common/document.ts b/src/common/document.ts index 7096bf4..3d945b2 100644 --- a/src/common/document.ts +++ b/src/common/document.ts @@ -98,7 +98,7 @@ export class Document { for (let y = at.y; y >= 0 && y < this.numRows; y += direction) { const maybeMatch = this.#rows[y].find(q, position.x, direction); if (maybeMatch.isSome()) { - position.x = this.#rows[y].rxToCx(maybeMatch.unwrap()); + position.x = maybeMatch.unwrap(); return Some(position); } diff --git a/src/common/row.ts b/src/common/row.ts index b46e370..4e10d47 100644 --- a/src/common/row.ts +++ b/src/common/row.ts @@ -132,7 +132,7 @@ export class Row { /** * Search the current row for the specified string, and return - * the render 'character' index of the start of that match + * the 'character' index of the start of that match */ public find( s: string, @@ -158,11 +158,11 @@ export class Row { // equal the number of characters. So // searching is fairly easy if (thisStr.length === this.chars.length) { - return Some(this.cxToRx(byteIndex)); + return Some(byteIndex); } // Emoji/Extended Unicode-friendly search - return Some(this.cxToRx(this.byteIndexToCharIndex(byteIndex))); + return Some(this.byteIndexToCharIndex(byteIndex)); } /** @@ -532,7 +532,7 @@ export class Row { // Highlight character literals const ch = this.rchars[i]; - if (ch === SINGLE_QUOTE) { + if (ch === SINGLE_QUOTE && this.rIndexOf(SINGLE_QUOTE, i + 1).isSome()) { while (true) { this.hl.push(HighlightType.Character); i += 1;