Refactor Ansi module so that it works as expected
All checks were successful
timw4mail/scroll/pipeline/head This commit looks good
All checks were successful
timw4mail/scroll/pipeline/head This commit looks good
This commit is contained in:
parent
d59900a895
commit
46a0314ce6
@ -224,11 +224,11 @@ const highlightToColorTest = {
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
const ANSITest = () => {
|
||||
const { AnsiColor, Ground } = _Ansi;
|
||||
const { Ground } = _Ansi;
|
||||
|
||||
return {
|
||||
'color()': () => {
|
||||
assertEquals(Ansi.color(AnsiColor.FgBlue), '\x1b[34m');
|
||||
assertEquals(Ansi.color.Blue, '\x1b[34m');
|
||||
},
|
||||
'color256()': () => {
|
||||
assertEquals(Ansi.color256(128, Ground.Back), '\x1b[48;5;128m');
|
||||
|
@ -108,7 +108,6 @@ 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 = (
|
||||
@ -131,48 +130,48 @@ export const Ansi = {
|
||||
moveCursorForward,
|
||||
moveCursorDown,
|
||||
textFormat,
|
||||
color,
|
||||
colors: {
|
||||
rgb,
|
||||
Black: AnsiColor.FgBlack,
|
||||
Red: AnsiColor.FgRed,
|
||||
Green: AnsiColor.FgGreen,
|
||||
Yellow: AnsiColor.FgYellow,
|
||||
Blue: AnsiColor.FgBlue,
|
||||
Magenta: AnsiColor.FgMagenta,
|
||||
Cyan: AnsiColor.FgCyan,
|
||||
White: AnsiColor.FgWhite,
|
||||
BrightBlack: AnsiColor.FgBrightBlack,
|
||||
BrightRed: AnsiColor.FgBrightRed,
|
||||
BrightGreen: AnsiColor.FgBrightGreen,
|
||||
BrightYellow: AnsiColor.FgBrightYellow,
|
||||
BrightBlue: AnsiColor.FgBrightBlue,
|
||||
BrightMagenta: AnsiColor.FgBrightMagenta,
|
||||
BrightCyan: AnsiColor.FgBrightCyan,
|
||||
BrightWhite: AnsiColor.FgBrightWhite,
|
||||
Invert: AnsiColor.Invert,
|
||||
color: {
|
||||
Black: textFormat(AnsiColor.FgBlack),
|
||||
Red: textFormat(AnsiColor.FgRed),
|
||||
Green: textFormat(AnsiColor.FgGreen),
|
||||
Yellow: textFormat(AnsiColor.FgYellow),
|
||||
Blue: textFormat(AnsiColor.FgBlue),
|
||||
Magenta: textFormat(AnsiColor.FgMagenta),
|
||||
Cyan: textFormat(AnsiColor.FgCyan),
|
||||
White: textFormat(AnsiColor.FgWhite),
|
||||
Default: textFormat(AnsiColor.FgDefault),
|
||||
BrightBlack: textFormat(AnsiColor.FgBrightBlack),
|
||||
BrightRed: textFormat(AnsiColor.FgBrightRed),
|
||||
BrightGreen: textFormat(AnsiColor.FgBrightGreen),
|
||||
BrightYellow: textFormat(AnsiColor.FgBrightYellow),
|
||||
BrightBlue: textFormat(AnsiColor.FgBrightBlue),
|
||||
BrightMagenta: textFormat(AnsiColor.FgBrightMagenta),
|
||||
BrightCyan: textFormat(AnsiColor.FgBrightCyan),
|
||||
BrightWhite: textFormat(AnsiColor.FgBrightWhite),
|
||||
Invert: textFormat(AnsiColor.Invert),
|
||||
background: {
|
||||
rgb: (r: number, g: number, b: number) => rgb(r, g, b, Ground.Back),
|
||||
Black: AnsiColor.BgBlack,
|
||||
Red: AnsiColor.BgRed,
|
||||
Green: AnsiColor.BgGreen,
|
||||
Yellow: AnsiColor.BgYellow,
|
||||
Blue: AnsiColor.BgBlue,
|
||||
Magenta: AnsiColor.BgMagenta,
|
||||
Cyan: AnsiColor.BgCyan,
|
||||
White: AnsiColor.BgWhite,
|
||||
BrightBlack: AnsiColor.BgBrightBlack,
|
||||
BrightRed: AnsiColor.BgBrightRed,
|
||||
BrightGreen: AnsiColor.BgBrightGreen,
|
||||
BrightYellow: AnsiColor.BgBrightYellow,
|
||||
BrightBlue: AnsiColor.BgBrightBlue,
|
||||
BrightMagenta: AnsiColor.BgBrightMagenta,
|
||||
BrightCyan: AnsiColor.BgBrightCyan,
|
||||
BrightWhite: AnsiColor.BgBrightWhite,
|
||||
Invert: AnsiColor.Invert,
|
||||
Black: textFormat(AnsiColor.BgBlack),
|
||||
Red: textFormat(AnsiColor.BgRed),
|
||||
Green: textFormat(AnsiColor.BgGreen),
|
||||
Yellow: textFormat(AnsiColor.BgYellow),
|
||||
Blue: textFormat(AnsiColor.BgBlue),
|
||||
Magenta: textFormat(AnsiColor.BgMagenta),
|
||||
Cyan: textFormat(AnsiColor.BgCyan),
|
||||
White: textFormat(AnsiColor.BgWhite),
|
||||
Default: textFormat(AnsiColor.BgDefault),
|
||||
BrightBlack: textFormat(AnsiColor.BgBrightBlack),
|
||||
BrightRed: textFormat(AnsiColor.BgBrightRed),
|
||||
BrightGreen: textFormat(AnsiColor.BgBrightGreen),
|
||||
BrightYellow: textFormat(AnsiColor.BgBrightYellow),
|
||||
BrightBlue: textFormat(AnsiColor.BgBrightBlue),
|
||||
BrightMagenta: textFormat(AnsiColor.BgBrightMagenta),
|
||||
BrightCyan: textFormat(AnsiColor.BgBrightCyan),
|
||||
BrightWhite: textFormat(AnsiColor.BgBrightWhite),
|
||||
Invert: textFormat(AnsiColor.Invert),
|
||||
},
|
||||
},
|
||||
color256,
|
||||
rgb,
|
||||
};
|
||||
|
||||
export default Ansi;
|
||||
|
@ -14,7 +14,7 @@ export const defaultTerminalSize: ITerminalSize = {
|
||||
};
|
||||
|
||||
export const SCROLL_COLOR_SCHEME: Map<HighlightType, string> = new Map([
|
||||
[HighlightType.Match, Ansi.colors.Invert.toString()], // Inverted color
|
||||
[HighlightType.Match, Ansi.color.Invert], // Inverted color
|
||||
[HighlightType.Number, Ansi.color256(196)], // Bright Red
|
||||
[HighlightType.Character, Ansi.color256(207)], // Magenta
|
||||
[HighlightType.String, Ansi.color256(45)], // Cyan
|
||||
|
Loading…
Reference in New Issue
Block a user