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('ab😺ac'));
},
'isAsciiDigit()': () => {
const { isAsciiDigit } = Fn;
assertTrue(isAsciiDigit('1234567890'));
assertFalse(isAsciiDigit('A1'));
assertFalse(isAsciiDigit('/'));
assertFalse(isAsciiDigit(':'));
},
'isControl()': () => {
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 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,
};

View File

@ -72,6 +72,9 @@ export class Document {
return this.#rows.length === 0;
}
/**
* Open a file for editing
*/
public async open(filename: string): Promise<Document> {
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) {

View File

@ -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?
*

View File

@ -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 = [];

View File

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