Background color functions for terminal text styling. These functions apply ANSI escape codes to change the background color behind text while preserving the foreground text color.
Apply standard ANSI background colors to text.
/**
* Apply black background color to text
* @param text - The text to style
* @returns Styled text with ANSI escape codes
*/
function bgBlack(text: string): string;
/**
* Apply red background color to text
* @param text - The text to style
* @returns Styled text with ANSI escape codes
*/
function bgRed(text: string): string;
/**
* Apply green background color to text
* @param text - The text to style
* @returns Styled text with ANSI escape codes
*/
function bgGreen(text: string): string;
/**
* Apply yellow background color to text
* @param text - The text to style
* @returns Styled text with ANSI escape codes
*/
function bgYellow(text: string): string;
/**
* Apply blue background color to text
* @param text - The text to style
* @returns Styled text with ANSI escape codes
*/
function bgBlue(text: string): string;
/**
* Apply magenta background color to text
* @param text - The text to style
* @returns Styled text with ANSI escape codes
*/
function bgMagenta(text: string): string;
/**
* Apply cyan background color to text
* @param text - The text to style
* @returns Styled text with ANSI escape codes
*/
function bgCyan(text: string): string;
/**
* Apply white background color to text
* @param text - The text to style
* @returns Styled text with ANSI escape codes
*/
function bgWhite(text: string): string;Usage Examples:
const colors = require('ansi-colors');
// Basic background colors
console.log(colors.bgRed('Alert message'));
console.log(colors.bgGreen('Success notification'));
console.log(colors.bgYellow('Warning banner'));
// Combining foreground and background colors
console.log(colors.white.bgRed('White text on red background'));
console.log(colors.black.bgYellow('Black text on yellow background'));
// Chaining with modifiers
console.log(colors.bold.white.bgBlue('Bold white text on blue background'));
// Nested styles with backgrounds
console.log(colors.bgGreen(`Success: ${colors.bgRed.white('Error')} resolved`));