ansi_styles 0.3.2+1 copy "ansi_styles: ^0.3.2+1" to clipboard
ansi_styles: ^0.3.2+1 copied to clipboard

ANSI escape codes for styling strings in the terminal.

🌈 AnsiStyles

Create colorful terminal output with ansi styled text in io environments.

Melos docs.page

DocumentationLicense


Usage #

Import the package:

import 'package:ansi_styles/ansi_styles.dart';
copied to clipboard

Use the AnsiStyle export to create styled text by chaining properties. For example:

void main() {
  print(AnsiStyles.red.underline('Underlined red text'));
  print(AnsiStyles.inverse.italic.green('Inverted italic green text'));
  print(AnsiStyles.cyan('Cyan text'));
  print(AnsiStyles.bgYellowBright.bold('Bold text with a yellow background'));
  print(AnsiStyles.bold.rgb(255,192,203)('Bold pink text'));
  print(AnsiStyles.strikethrough.bgRgb(255,165,0)('Strikethrough text with an orange background'));
}
copied to clipboard

Output preview:

ansi_styles_preview

To remove any ansi styling from text, call the strip() method:

String styledText = AnsiStyles.red.underline('Underlined red text');
String cleanText = AnsiStyles.strip(styledText);
copied to clipboard

String Extension #

This package also provides a String Extension which can be imported:

import 'package:ansi_styles/extension.dart';
copied to clipboard

Styling methods are now available on Strings:

void main() {
  print('hello'.bold.red);
  print('hello'.bold.red.underline.bgBlack);
}
copied to clipboard

License #


Built and maintained by Invertase.

11
likes
150
points
319
downloads

Publisher

verified publisherinvertase.io

Weekly Downloads

2024.09.19 - 2025.04.03

ANSI escape codes for styling strings in the terminal.

Repository (GitHub)

Documentation

API reference

License

Apache-2.0 (license)

More

Packages that depend on ansi_styles