Preparations for highlighting numbers
All checks were successful
timw4mail/scroll/pipeline/head This commit looks good

This commit is contained in:
Timothy Warren 2024-02-29 14:24:22 -05:00
parent cd448f74d6
commit 55c9dc1c3d
6 changed files with 40 additions and 0 deletions

View File

@ -307,6 +307,14 @@ testSuite({
assertFalse(isAscii('😺acalskjsdf')); assertFalse(isAscii('😺acalskjsdf'));
assertFalse(isAscii('ab😺ac')); assertFalse(isAscii('ab😺ac'));
}, },
'isAsciiDigit()': () => {
const { isAsciiDigit } = Fn;
assertTrue(isAsciiDigit('1234567890'));
assertFalse(isAsciiDigit('A1'));
assertFalse(isAsciiDigit('/'));
assertFalse(isAsciiDigit(':'));
},
'isControl()': () => { 'isControl()': () => {
const { isControl } = Fn; const { isControl } = Fn;

View File

@ -106,6 +106,7 @@ const moveCursorForward = (col: number): string => code(col, 'C');
const moveCursorDown = (row: number): string => code(row, 'B'); const moveCursorDown = (row: number): string => code(row, 'B');
const textFormat = (param: string | number | string[] | number[]): string => const textFormat = (param: string | number | string[] | number[]): string =>
code(param, 'm'); code(param, 'm');
const color = (value: AnsiColor): string => textFormat(value);
const color256 = (value: number, ground: Ground = Ground.Fore): string => const color256 = (value: number, ground: Ground = Ground.Fore): string =>
textFormat([ground, AnsiColor.Type256, value]); textFormat([ground, AnsiColor.Type256, value]);
const rgb = ( const rgb = (
@ -128,6 +129,7 @@ export const Ansi = {
moveCursorForward, moveCursorForward,
moveCursorDown, moveCursorDown,
textFormat, textFormat,
color,
color256, color256,
rgb, rgb,
}; };

View File

@ -72,6 +72,9 @@ export class Document {
return this.#rows.length === 0; return this.#rows.length === 0;
} }
/**
* Open a file for editing
*/
public async open(filename: string): Promise<Document> { public async open(filename: string): Promise<Document> {
const { file } = await getRuntime(); const { file } = await getRuntime();
@ -89,6 +92,9 @@ export class Document {
return this; return this;
} }
/**
* Save the current document
*/
public async save(filename: string) { public async save(filename: string) {
const { file } = await getRuntime(); const { file } = await getRuntime();
@ -149,6 +155,10 @@ export class Document {
this.dirty = true; this.dirty = true;
} }
/**
* Remove a character from the document, merging
* adjacent lines if necessary
*/
public delete(at: Position): void { public delete(at: Position): void {
const len = this.numRows; const len = this.numRows;
if (at.y >= len) { if (at.y >= len) {

View File

@ -159,6 +159,16 @@ export function isAscii(char: string): boolean {
return strChars(char).every((char) => ord(char) < 0x80); 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? * Is the one char in the string an ascii control character?
* *

View File

@ -16,6 +16,11 @@ export class Row {
*/ */
render: string[] = []; render: string[] = [];
/**
* The syntax highlighting map
*/
hl: string[] = [];
private constructor(s: string | string[] = '') { private constructor(s: string | string[] = '') {
this.chars = Array.isArray(s) ? s : strChars(s); this.chars = Array.isArray(s) ? s : strChars(s);
this.render = []; this.render = [];

View File

@ -162,6 +162,11 @@ export enum SearchDirection {
Backward = -1, Backward = -1,
} }
export enum HighlightType {
None,
Number,
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Testing // Testing
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------