Module format

Source
Expand description

A module for text formatting and styling in terminal applications.

This module provides functionality for adding colors and styles to text, as well as utilities for working with ANSI escape codes. It includes a Color struct for RGB color representation, a Style enum for text styles, and a Stylize trait for applying these formats to strings.

§Features

  • RGB color support for both foreground and background
  • Text styling (bold, italic, underline, etc.)
  • ANSI escape code handling
  • Utilities for stripping ANSI codes and calculating visual string length

§Examples

use dev_utils::format::{Color, Style, Stylize};
use dev_utils::format::{RED, WHITE};

let text = "Hello, World!";
println!("{}", text.color(RED).on_color(WHITE).style(Style::Bold));

Structs§

Color
Represents an RGB color.

Enums§

Style
Variants are created by the create_style_enum! macro.

Constants§

BLACK
BLUE
CYAN
GREEN
MAGENTA
RED
WHITE
YELLOW

Traits§

Stylize
A trait for applying colors and styles to text.

Functions§

strip_ansi_codes
Removes ANSI escape codes from a string.
visual_length
Calculates the visual length of a string, ignoring ANSI escape codes.