Play with colors, add hecto highlighting fix
All checks were successful
timw4mail/scroll/pipeline/head This commit looks good

This commit is contained in:
Timothy Warren 2024-07-18 15:46:52 -04:00
parent ea00f76a62
commit 0c13942aae
2 changed files with 70 additions and 93 deletions

View File

@ -1,92 +1,72 @@
/** /**
* This is a test file and a terminal color table program * This is a test file and a terminal color table program
*/ */
import Ansi, { Ground } from '../src/common/ansi.ts';
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Display table of the 256 type color console escape codes // Display table of the 256 type color console escape codes
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
function print16colorTable(): void {
let colorTable = '';
export enum Ground { [30, 90].forEach((start) => {
Fore = 38, let i = 0;
Back = 48, let end = start + 8;
} for (i = start; i < end; i++) {
colorTable += Ansi.color(i);
const code = ( colorTable += String(i).padStart(3, ' ').padEnd(4, ' ');
param: any, colorTable += Ansi.ResetFormatting;
suffix: string = '',
): string => {
if (Array.isArray(param)) {
param = param.join(';');
} }
return ['\x1b[', param, suffix].join(''); colorTable += ' '.repeat(5);
};
const textFormat = (param: any): string => code(param, 'm');
const color256 = (value: number, ground: Ground): string =>
textFormat([ground, 5, value]);
let colorTable = ''; start += 10;
const doubleBreaks = [15, 51, 87, 123, 159, 195, 231, 255]; end += 10;
[ for (i = start; i < end; i++) {
7, colorTable += Ansi.color(i);
15, colorTable += String(i).padStart(4, ' ').padEnd(5, ' ');
21, colorTable += Ansi.ResetFormatting;
27, }
33,
39, colorTable += '\n';
45, });
51,
57, colorTable += '\n';
63,
69, console.log(colorTable);
75, }
81, function print256colorTable(): void {
87, let colorTable = '';
93, // deno-fmt-ignore
99, const breaks = [
105, 7, 15,
111, 21, 27, 33, 39, 45, 51,
117, 57, 63, 69, 75, 81, 87,
123, 93, 99, 105, 111, 117, 123,
129, 129, 135, 141, 147, 153, 159,
135, 165, 171, 177, 183, 189, 195,
141, 201, 207, 213, 219, 225, 231,
147, 237, 243, 249, 255,
153, ];
159, const doubleBreaks = [15, 51, 87, 123, 159, 195, 231, 255];
165,
171, breaks.forEach((line, n) => {
177,
183,
189,
195,
201,
207,
213,
219,
225,
231,
237,
243,
249,
255,
].forEach((line, n, breaks) => {
const start = (n > 0) ? breaks[n - 1] + 1 : 0; const start = (n > 0) ? breaks[n - 1] + 1 : 0;
const end = line + 1; const end = line + 1;
let i = 0; let i = 0;
for (i = start; i < end; i++) { for (i = start; i < end; i++) {
colorTable += color256(i, Ground.Fore); colorTable += Ansi.color256(i, Ground.Fore);
colorTable += String(i).padStart(4, ' ').padEnd(5, ' '); colorTable += String(i).padStart(4, ' ').padEnd(5, ' ');
colorTable += textFormat(''); colorTable += Ansi.ResetFormatting;
} }
colorTable += ' '.repeat(5); colorTable += ' '.repeat(5);
for (i = start; i < end; i++) { for (i = start; i < end; i++) {
colorTable += color256(i, Ground.Back); colorTable += Ansi.color256(i, Ground.Back);
colorTable += String(i).padStart(4, ' ').padEnd(5, ' '); colorTable += String(i).padStart(4, ' ').padEnd(5, ' ');
colorTable += textFormat(''); colorTable += Ansi.ResetFormatting;
} }
colorTable += '\n'; colorTable += '\n';
@ -94,9 +74,13 @@ const doubleBreaks = [15, 51, 87, 123, 159, 195, 231, 255];
if (doubleBreaks.includes(line)) { if (doubleBreaks.includes(line)) {
colorTable += '\n'; colorTable += '\n';
} }
}); });
console.log(colorTable); console.log(colorTable);
}
print16colorTable();
print256colorTable();
/** /**
* Test code for highlighting * Test code for highlighting

View File

@ -246,15 +246,8 @@ export class Row {
syntax: FileType, syntax: FileType,
startWithComment: boolean, startWithComment: boolean,
): boolean { ): boolean {
// Check for the end of a multiline comment
// if we are currently in one
if (this.isHighlighted && word.isNone()) { if (this.isHighlighted && word.isNone()) {
const lastHl = this.hl[this.hl.length - 1]; return false;
return lastHl === HighlightType.MultiLineComment &&
syntax.hasMultilineComments() &&
this.size > 1 &&
substr(this.toString(), this.size - 2) ===
syntax.multiLineCommentEnd.unwrap();
} }
this.hl = []; this.hl = [];