Basic Style Usage
import { bold, italic, underline, dim } from "@nevware21/chromacon";
// Apply individual styles
console.log(bold("Important message"));
// Output: "\x1b[1mImportant message\x1b[22m"
console.log(italic("Emphasized text"));
// Output: "\x1b[3mEmphasized text\x1b[23m"
console.log(underline("Underlined text"));
// Output: "\x1b[4mUnderlined text\x1b[24m"
Style Composition and Nesting
import { bold, italic, underline, strikethrough } from "@nevware21/chromacon";
// Combine multiple styles
console.log(bold(italic("Bold and italic")));
// Output: "\x1b[1m\x1b[3mBold and italic\x1b[23m\x1b[22m"
// Complex style combinations
console.log(underline(bold("Underlined and bold")));
console.log(strikethrough(italic("Crossed out italic")));
Combining Styles with Colors
import { bold, italic, red, green, blue, bgYellow } from "@nevware21/chromacon";
// Styles work independently of colors
console.log(red(bold("Bold red text")));
console.log(bold(green("Bold green text")));
// Complex combinations
console.log(bgYellow(bold(blue("Bold blue text on yellow background"))));
console.log(italic(red("Italic red text")));
Usage as String (Raw Style Codes)
import { bold, italic, reset } from "@nevware21/chromacon";
// Manual style control using string representation
console.log(`${bold}This is bold${reset} and this is normal`);
// Output: "\x1b[1mThis is bold\x1b[0m and this is normal"
// Build complex formatting manually
const styledText = `Normal ${bold}bold ${italic}bold-italic${reset} normal again`;
console.log(styledText);
Dynamic Style Application
import { bold, italic, underline, dim } from "@nevware21/chromacon";
const styleMap: Record<string, ChromaStyle> = {
emphasis: bold,
quote: italic,
link: underline,
muted: dim
};
function formatText(type: keyof typeof styleMap, text: string): string {
const styleFn = styleMap[type];
return styleFn(text);
}
console.log(formatText('emphasis', 'Important!'));
console.log(formatText('quote', 'Albert Einstein said...'));
console.log(formatText('link', 'https://example.com'));
Conditional Style Formatting
import { bold, dim, isColorSupported } from "@nevware21/chromacon";
function formatHeading(text: string, level: 1 | 2 | 3): string {
if (!isColorSupported()) {
// Fallback formatting without styles
const prefix = '='.repeat(4 - level);
return `${prefix} ${text} ${prefix}`;
}
// Use styles based on heading level
switch (level) {
case 1: return bold(text);
case 2: return text; // Normal weight
case 3: return dim(text);
default: return text;
}
}
console.log(formatHeading("Main Title", 1));
console.log(formatHeading("Subtitle", 2));
console.log(formatHeading("Minor heading", 3));
Style Utility Functions
import { bold, italic, underline } from "@nevware21/chromacon";
// Create reusable style utilities
const formatKeyword = (text: string) => bold(text);
const formatComment = (text: string) => italic(text);
const formatUrl = (text: string) => underline(text);
// Use in code documentation
console.log(`The ${formatKeyword('const')} keyword declares a constant`);
console.log(`${formatComment('// This is a comment')}`);
console.log(`Visit ${formatUrl('https://github.com')} for more info`);
A hybrid type that represents both a style formatting function and a string containing the current theme formatting sequences. For the default ANSI theme, this will be ANSI escape codes.
ChromaStyleis specifically designed for text styling (bold, italic, underline, etc.) rather than color formatting. While ChromaColor handles color-specific formatting,ChromaStylefocuses on text appearance modifications that don't involve color changes.Key Differences from ChromaColor:
ChromaStyleapplies text styles (bold, italic, underline), whileChromaColorapplies colors (red, blue, green)Like
ChromaColor, it can be used in two ways:The behavior adapts to the current theme system and respects color level settings for consistency.