Skip to content

Commit

Permalink
Add foreground colors to ansi module
Browse files Browse the repository at this point in the history
  • Loading branch information
Hexagon committed Mar 14, 2024
1 parent f1a857b commit de2de20
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cross/utils",
"version": "0.1.3",
"version": "0.1.4",
"exports": {
".": "./mod.ts",
"./ansi": "./utils/ansi.ts",
Expand Down
72 changes: 72 additions & 0 deletions utils/ansi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,78 @@ export class Colors {
static bgWhite(text: string): string {
return AnsiCodes.BgWhite + text + AnsiCodes.Reset;
}

/**
* Sets the foreground color to black.
* @param {string} text The text to format.
* @returns {string} The formatted text.
*/
static black(text: string): string {
return AnsiCodes.FgBlack + text + AnsiCodes.Reset;
}

/**
* Sets the foreground color to red.
* @param {string} text The text to format.
* @returns {string} The formatted text.
*/
static red(text: string): string {
return AnsiCodes.FgRed + text + AnsiCodes.Reset;
}

/**
* Sets the foreground color to green.
* @param {string} text The text to format.
* @returns {string} The formatted text.
*/
static green(text: string): string {
return AnsiCodes.FgGreen + text + AnsiCodes.Reset;
}

/**
* Sets the foreground color to yellow.
* @param {string} text The text to format.
* @returns {string} The formatted text.
*/
static yellow(text: string): string {
return AnsiCodes.FgYellow + text + AnsiCodes.Reset;
}

/**
* Sets the foreground color to blue.
* @param {string} text The text to format.
* @returns {string} The formatted text.
*/
static blue(text: string): string {
return AnsiCodes.FgBlue + text + AnsiCodes.Reset;
}

/**
* Sets the foreground color to magenta.
* @param {string} text The text to format.
* @returns {string} The formatted text.
*/
static magenta(text: string): string {
return AnsiCodes.FgMagenta + text + AnsiCodes.Reset;
}

/**
* Sets the foreground color to cyan.
* @param {string} text The text to format.
* @returns {string} The formatted text.
*/
static cyan(text: string): string {
return AnsiCodes.FgCyan + text + AnsiCodes.Reset;
}

/**
* Sets the foreground color to white.
* @param {string} text The text to format.
* @returns {string} The formatted text.
*/
static white(text: string): string {
return AnsiCodes.FgWhite + text + AnsiCodes.Reset;
}
}

export class Cursor {
Expand Down

0 comments on commit de2de20

Please sign in to comment.