diff --git a/src/common/all_test.ts b/src/common/all_test.ts index 57e98c1..7bb82a4 100644 --- a/src/common/all_test.ts +++ b/src/common/all_test.ts @@ -307,6 +307,14 @@ testSuite({ assertFalse(isAscii('😺acalskjsdf')); assertFalse(isAscii('ab😺ac')); }, + 'isAsciiDigit()': () => { + const { isAsciiDigit } = Fn; + + assertTrue(isAsciiDigit('1234567890')); + assertFalse(isAsciiDigit('A1')); + assertFalse(isAsciiDigit('/')); + assertFalse(isAsciiDigit(':')); + }, 'isControl()': () => { const { isControl } = Fn; diff --git a/src/common/ansi.ts b/src/common/ansi.ts index 05386f0..af0d838 100644 --- a/src/common/ansi.ts +++ b/src/common/ansi.ts @@ -106,6 +106,7 @@ const moveCursorForward = (col: number): string => code(col, 'C'); const moveCursorDown = (row: number): string => code(row, 'B'); const textFormat = (param: string | number | string[] | number[]): string => code(param, 'm'); +const color = (value: AnsiColor): string => textFormat(value); const color256 = (value: number, ground: Ground = Ground.Fore): string => textFormat([ground, AnsiColor.Type256, value]); const rgb = ( @@ -128,6 +129,7 @@ export const Ansi = { moveCursorForward, moveCursorDown, textFormat, + color, color256, rgb, }; diff --git a/src/common/document.ts b/src/common/document.ts index e6ac5bb..1e92e05 100644 --- a/src/common/document.ts +++ b/src/common/document.ts @@ -72,6 +72,9 @@ export class Document { return this.#rows.length === 0; } + /** + * Open a file for editing + */ public async open(filename: string): Promise { const { file } = await getRuntime(); @@ -89,6 +92,9 @@ export class Document { return this; } + /** + * Save the current document + */ public async save(filename: string) { const { file } = await getRuntime(); @@ -149,6 +155,10 @@ export class Document { this.dirty = true; } + /** + * Remove a character from the document, merging + * adjacent lines if necessary + */ public delete(at: Position): void { const len = this.numRows; if (at.y >= len) { diff --git a/src/common/fns.ts b/src/common/fns.ts index 75153d9..3180abc 100644 --- a/src/common/fns.ts +++ b/src/common/fns.ts @@ -159,6 +159,16 @@ export function isAscii(char: string): boolean { return strChars(char).every((char) => ord(char) < 0x80); } +/** + * Are all the characters numerals? + * + * @param char - string to check + */ +export function isAsciiDigit(char: string): boolean { + return isAscii(char) && + strChars(char).every((char) => ord(char) >= 0x30 && ord(char) < 0x3a); +} + /** * Is the one char in the string an ascii control character? * diff --git a/src/common/row.ts b/src/common/row.ts index 322ef9b..8575e77 100644 --- a/src/common/row.ts +++ b/src/common/row.ts @@ -16,6 +16,11 @@ export class Row { */ render: string[] = []; + /** + * The syntax highlighting map + */ + hl: string[] = []; + private constructor(s: string | string[] = '') { this.chars = Array.isArray(s) ? s : strChars(s); this.render = []; diff --git a/src/common/types.ts b/src/common/types.ts index 271a26c..7745468 100644 --- a/src/common/types.ts +++ b/src/common/types.ts @@ -162,6 +162,11 @@ export enum SearchDirection { Backward = -1, } +export enum HighlightType { + None, + Number, +} + // ---------------------------------------------------------------------------- // Testing // ----------------------------------------------------------------------------