Timothy J. Warren
2b3be61933
All checks were successful
timw4mail/scroll/pipeline/head This commit looks good
112 lines
1.9 KiB
JavaScript
112 lines
1.9 KiB
JavaScript
/**
|
|
* This is a test file and a terminal color table program
|
|
*/
|
|
// ----------------------------------------------------------------------------
|
|
// Display table of the 256 type color console escape codes
|
|
// ----------------------------------------------------------------------------
|
|
|
|
export enum Ground {
|
|
Fore = 38,
|
|
Back = 48,
|
|
}
|
|
|
|
const code = (
|
|
param: any,
|
|
suffix: string = '',
|
|
): string => {
|
|
if (Array.isArray(param)) {
|
|
param = param.join(';');
|
|
}
|
|
|
|
return ['\x1b[', param, suffix].join('');
|
|
};
|
|
const textFormat = (param: any): string => code(param, 'm');
|
|
const color256 = (value: number, ground: Ground): string =>
|
|
textFormat([ground, 5, value]);
|
|
|
|
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';
|
|
|
|
if (doubleBreaks.includes(line)) {
|
|
colorTable += '\n';
|
|
}
|
|
});
|
|
|
|
console.log(colorTable);
|
|
|
|
/**
|
|
* 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;
|