ansi_colorizer 1.1.3 copy "ansi_colorizer: ^1.1.3" to clipboard
ansi_colorizer: ^1.1.3 copied to clipboard

An ANSI Escape Code support library that lets you apply custom formatting to your text.

example/ansi_colorizer_example.dart

import "package:ansi_colorizer/ansi_colorizer.dart";

void main() {
  // Create an AnsiColorizer object with your specific formatting options.
  const colorizer = AnsiColorizer(
    foreground: Ansi24BitColor.fromRGB(210, 200, 0),
    modifiers: {
      AnsiModifier.bold,
      AnsiModifier.italic,
    },
  );

  // Apply the formatting to the string representation of an object
  // by calling using the colorizer variable like a function.
  //
  // Alternatively you can also use:
  // final result = colorizer.colorize("Hello World");
  final result = colorizer("Hello World");

  // Prints "Hello World", but the text color is yellow and the
  // text is bold and cursive.
  print(result);

  // Create a new [AnsiPrinter] that uses [colorizer] to format every
  // message with an unformatted prefix.
  final printer = colorizer.createPrinter(
    prefix: (_) => "[INFO]: ",
  );

  // Prints "[INFO]: Foobar", but `[INFO]: ` is unformatted and `Foobar` is
  // yellow, bold and cursive.
  printer("Foobar");
}
2
likes
160
points
64
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

An ANSI Escape Code support library that lets you apply custom formatting to your text.

Repository (GitLab)
View/report issues

License

LGPL-2.1 (license)

Dependencies

meta, web

More

Packages that depend on ansi_colorizer