From 0c13942aae78338304714e9d1c107d8c7e44cdaf Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Thu, 18 Jul 2024 15:46:52 -0400 Subject: [PATCH] Play with colors, add hecto highlighting fix --- demo/colors.ts | 154 +++++++++++++++++++++------------------------- src/common/row.ts | 9 +-- 2 files changed, 70 insertions(+), 93 deletions(-) diff --git a/demo/colors.ts b/demo/colors.ts index f3c75ac..b5aae39 100644 --- a/demo/colors.ts +++ b/demo/colors.ts @@ -1,102 +1,86 @@ /** * 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 // ---------------------------------------------------------------------------- +function print16colorTable(): void { + let colorTable = ''; -export enum Ground { - Fore = 38, - Back = 48, -} + [30, 90].forEach((start) => { + let i = 0; + let end = start + 8; + for (i = start; i < end; i++) { + colorTable += Ansi.color(i); + colorTable += String(i).padStart(3, ' ').padEnd(4, ' '); + colorTable += Ansi.ResetFormatting; + } -const code = ( - param: any, - suffix: string = '', -): string => { - if (Array.isArray(param)) { - param = param.join(';'); - } + colorTable += ' '.repeat(5); - return ['\x1b[', param, suffix].join(''); -}; -const textFormat = (param: any): string => code(param, 'm'); -const color256 = (value: number, ground: Ground): string => - textFormat([ground, 5, value]); + start += 10; + end += 10; + for (i = start; i < end; i++) { + colorTable += Ansi.color(i); + colorTable += String(i).padStart(4, ' ').padEnd(5, ' '); + colorTable += Ansi.ResetFormatting; + } -let colorTable = ''; -const doubleBreaks = [15, 51, 87, 123, 159, 195, 231, 255]; -[ - 7, - 15, - 21, - 27, - 33, - 39, - 45, - 51, - 57, - 63, - 69, - 75, - 81, - 87, - 93, - 99, - 105, - 111, - 117, - 123, - 129, - 135, - 141, - 147, - 153, - 159, - 165, - 171, - 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 end = line + 1; - - let i = 0; - - for (i = start; i < end; i++) { - colorTable += color256(i, Ground.Fore); - colorTable += String(i).padStart(4, ' ').padEnd(5, ' '); - colorTable += textFormat(''); - } - - colorTable += ' '.repeat(5); - - for (i = start; i < end; i++) { - colorTable += color256(i, Ground.Back); - colorTable += String(i).padStart(4, ' ').padEnd(5, ' '); - colorTable += textFormat(''); - } + colorTable += '\n'; + }); colorTable += '\n'; - if (doubleBreaks.includes(line)) { - colorTable += '\n'; - } -}); + console.log(colorTable); +} +function print256colorTable(): void { + let colorTable = ''; + // deno-fmt-ignore + const breaks = [ + 7, 15, + 21, 27, 33, 39, 45, 51, + 57, 63, 69, 75, 81, 87, + 93, 99, 105, 111, 117, 123, + 129, 135, 141, 147, 153, 159, + 165, 171, 177, 183, 189, 195, + 201, 207, 213, 219, 225, 231, + 237, 243, 249, 255, + ]; + const doubleBreaks = [15, 51, 87, 123, 159, 195, 231, 255]; -console.log(colorTable); + breaks.forEach((line, n) => { + const start = (n > 0) ? breaks[n - 1] + 1 : 0; + const end = line + 1; + + let i = 0; + + for (i = start; i < end; i++) { + colorTable += Ansi.color256(i, Ground.Fore); + colorTable += String(i).padStart(4, ' ').padEnd(5, ' '); + colorTable += Ansi.ResetFormatting; + } + + colorTable += ' '.repeat(5); + + for (i = start; i < end; i++) { + colorTable += Ansi.color256(i, Ground.Back); + colorTable += String(i).padStart(4, ' ').padEnd(5, ' '); + colorTable += Ansi.ResetFormatting; + } + + colorTable += '\n'; + + if (doubleBreaks.includes(line)) { + colorTable += '\n'; + } + }); + + console.log(colorTable); +} + +print16colorTable(); +print256colorTable(); /** * Test code for highlighting diff --git a/src/common/row.ts b/src/common/row.ts index f3224ec..4a97290 100644 --- a/src/common/row.ts +++ b/src/common/row.ts @@ -246,15 +246,8 @@ export class Row { syntax: FileType, startWithComment: boolean, ): boolean { - // Check for the end of a multiline comment - // if we are currently in one if (this.isHighlighted && word.isNone()) { - const lastHl = this.hl[this.hl.length - 1]; - return lastHl === HighlightType.MultiLineComment && - syntax.hasMultilineComments() && - this.size > 1 && - substr(this.toString(), this.size - 2) === - syntax.multiLineCommentEnd.unwrap(); + return false; } this.hl = [];