Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(std/fmt): add bright color variations #7241

Merged
merged 1 commit into from
Aug 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions std/fmt/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,41 @@ export function white(str: string): string {
}

export function gray(str: string): string {
return brightBlack(str);
}

export function brightBlack(str: string): string {
Comment on lines +123 to +126
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is change to gray intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, did not want to remove any identifiers here but gray was returning 90 which is "bright black" so grey becomes an alias of it.

Copy link
Contributor Author

@caspervonb caspervonb Aug 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference, Wikipedia has a pretty color table https://en.wikipedia.org/wiki/ANSI_escape_code#Terminal_output_sequences

return run(str, code([90], 39));
}

export function brightRed(str: string): string {
return run(str, code([91], 39));
}

export function brightGreen(str: string): string {
return run(str, code([92], 39));
}

export function brightYellow(str: string): string {
return run(str, code([93], 39));
}

export function brightBlue(str: string): string {
return run(str, code([94], 39));
}

export function brightMagenta(str: string): string {
return run(str, code([95], 39));
}

export function brightCyan(str: string): string {
return run(str, code([96], 39));
}

export function brightWhite(str: string): string {
return run(str, code([97], 39));
}

export function bgBlack(str: string): string {
return run(str, code([40], 49));
}
Expand Down Expand Up @@ -155,6 +187,38 @@ export function bgWhite(str: string): string {
return run(str, code([47], 49));
}

export function bgBrightBlack(str: string): string {
return run(str, code([100], 49));
}

export function bgBrightRed(str: string): string {
return run(str, code([101], 49));
}

export function bgBrightGreen(str: string): string {
return run(str, code([102], 49));
}

export function bgBrightYellow(str: string): string {
return run(str, code([103], 49));
}

export function bgBrightBlue(str: string): string {
return run(str, code([104], 49));
}

export function bgBrightMagenta(str: string): string {
return run(str, code([105], 49));
}

export function bgBrightCyan(str: string): string {
return run(str, code([106], 49));
}

export function bgBrightWhite(str: string): string {
return run(str, code([107], 49));
}

/* Special Color Sequences */

function clampAndTruncate(n: number, max = 255, min = 0): number {
Expand Down
64 changes: 64 additions & 0 deletions std/fmt/colors_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,38 @@ Deno.test("testGray", function (): void {
assertEquals(c.gray("foo bar"), "foo bar");
});

Deno.test("testBrightBlack", function (): void {
assertEquals(c.brightBlack("foo bar"), "foo bar");
});

Deno.test("testBrightRed", function (): void {
assertEquals(c.brightRed("foo bar"), "foo bar");
});

Deno.test("testBrightGreen", function (): void {
assertEquals(c.brightGreen("foo bar"), "foo bar");
});

Deno.test("testBrightYellow", function (): void {
assertEquals(c.brightYellow("foo bar"), "foo bar");
});

Deno.test("testBrightBlue", function (): void {
assertEquals(c.brightBlue("foo bar"), "foo bar");
});

Deno.test("testBrightMagenta", function (): void {
assertEquals(c.brightMagenta("foo bar"), "foo bar");
});

Deno.test("testBrightCyan", function (): void {
assertEquals(c.brightCyan("foo bar"), "foo bar");
});

Deno.test("testBrightWhite", function (): void {
assertEquals(c.brightWhite("foo bar"), "foo bar");
});

Deno.test("testBgBlack", function (): void {
assertEquals(c.bgBlack("foo bar"), "foo bar");
});
Expand Down Expand Up @@ -119,6 +151,38 @@ Deno.test("testBgWhite", function (): void {
assertEquals(c.bgWhite("foo bar"), "foo bar");
});

Deno.test("testBgBrightBlack", function (): void {
assertEquals(c.bgBrightBlack("foo bar"), "foo bar");
});

Deno.test("testBgBrightRed", function (): void {
assertEquals(c.bgBrightRed("foo bar"), "foo bar");
});

Deno.test("testBgBrightGreen", function (): void {
assertEquals(c.bgBrightGreen("foo bar"), "foo bar");
});

Deno.test("testBgBrightYellow", function (): void {
assertEquals(c.bgBrightYellow("foo bar"), "foo bar");
});

Deno.test("testBgBrightBlue", function (): void {
assertEquals(c.bgBrightBlue("foo bar"), "foo bar");
});

Deno.test("testBgBrightMagenta", function (): void {
assertEquals(c.bgBrightMagenta("foo bar"), "foo bar");
});

Deno.test("testBgBrightCyan", function (): void {
assertEquals(c.bgBrightCyan("foo bar"), "foo bar");
});

Deno.test("testBgBrightWhite", function (): void {
assertEquals(c.bgBrightWhite("foo bar"), "foo bar");
});

Deno.test("testClampUsingRgb8", function (): void {
assertEquals(c.rgb8("foo bar", -10), "foo bar");
});
Expand Down