@nevware21/chromacon
    Preparing search index...

    Type Alias ChromaStyle

    ChromaStyle: CsiStyle & string

    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.

    ChromaStyle is specifically designed for text styling (bold, italic, underline, etc.) rather than color formatting. While ChromaColor handles color-specific formatting, ChromaStyle focuses on text appearance modifications that don't involve color changes.

    Key Differences from ChromaColor:

    • Purpose: ChromaStyle applies text styles (bold, italic, underline), while ChromaColor applies colors (red, blue, green)
    • Reset Behavior: Style resets typically restore normal intensity/appearance, color resets restore default foreground/background
    • Combination: Styles and colors can be combined together for rich text formatting
    • Independence: Style formatting is independent of color support levels, though both respect the overall theme system

    Like ChromaColor, it can be used in two ways:

    1. As a function - to apply style formatting to text, automatically wrapping and resetting the style
    2. As a string - to get the current theme formatting sequences to enable the style

    The behavior adapts to the current theme system and respects color level settings for consistency.

    The input string to be styled when used as a function

    The input string wrapped with appropriate theme style codes when used as a function

    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`);
    • CsiStyle - The base function type for CSI style formatting
    • ChromaColor - Similar type for color formatting (red, blue, green, etc.)
    • ColorLevel - Enumeration controlling overall theme formatting support
    • isColorSupported - Check if formatting output is supported

    1.0.0