scroll/demo/colors.ts

96 lines
2.3 KiB
JavaScript
Raw Normal View History

2024-07-17 16:23:53 -04:00
/**
* This is a test file and a terminal color table program
*/
import Ansi, { Ground } from '../src/common/ansi.ts';
2024-07-17 16:23:53 -04:00
// ----------------------------------------------------------------------------
// Display table of the 256 type color console escape codes
// ----------------------------------------------------------------------------
function print16colorTable(): void {
let colorTable = '';
2024-07-17 16:23:53 -04:00
[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;
}
colorTable += ' '.repeat(5);
2024-07-17 16:23:53 -04:00
start += 10;
end += 10;
for (i = start; i < end; i++) {
colorTable += Ansi.color(i);
colorTable += String(i).padStart(4, ' ').padEnd(5, ' ');
colorTable += Ansi.ResetFormatting;
}
colorTable += '\n';
});
2024-07-17 16:23:53 -04:00
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];
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;
}
2024-07-17 16:23:53 -04:00
colorTable += '\n';
if (doubleBreaks.includes(line)) {
colorTable += '\n';
}
});
console.log(colorTable);
}
print16colorTable();
print256colorTable();
2024-07-17 16:23:53 -04:00
/**
* Test code for highlighting
*/
const decimal: number[] = [0, 117];
const bigDecimal = 123456789123456789n;
const octal: number[] = [0o15, 0o1];
const bigOctal = 0o777777777777n;
const hexadecimal: number[] = [0x1123, 0x00111];
const bigHex = 0x123456789ABCDEFn;
const binary: number[] = [0b11, 0b0011];
const bigBinary = 0b11101001010101010101n;