ansicolor 1.0.2

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 90

ANSI / Xterm 256 color library for Dart

Feel like you're missing some color in your terminal programs? Use AnsiPen to add ANSI color codes to your log messages.

Easy to disable for production, just set color_disabled = true and all codes will be empty - no re-writing debug messages.

Note: color_disabled is a global variable for all pen colors.

Example

Note: Be mindful of contrasting colors. If you set "bright white" foreground and don't adjust the background, you'll have a bad time with lighter terminals.

Foreground to bright white with default background:

AnsiPen pen = new AnsiPen()..white(bold: true);
print(pen("Bright white foreground") + " this text is default fg/bg");

Background as a peach, foreground as white:

AnsiPen pen = new AnsiPen()..white()..rgb(r: 1.0, g: 0.8, b: 0.2);
print(pen("White foreground with a peach background"));

Rainbow Demo

If you want a specific color, you can call the xterm() with the index listed in the rainbow below. To show the rainbow on your own terminal, pub run examples/ansicolor.dart

alt tag

1.0.2

  • Adding this CHANGELOG.md
  • Moving bin/demo.dart to examples/ansicolor.dart

1.0.1

  • Updated authors

1.0.0

  • Dart 2.0 support!

example/ansicolor.dart

import 'package:ansicolor/ansicolor.dart';

main() {
  print(ansi_demo());
}

/// Due to missing sprintf(), this is my cheap "%03d".
String _toSpace(int i, [int width = 3]) {
  if (width <= 0 && i == 0) return "";
  return "${_toSpace(i ~/ 10, --width)}${i % 10}";
}

/// Return a reference table for foreground and background colors.
String ansi_demo() {
  StringBuffer sb = new StringBuffer();

  AnsiPen pen = new AnsiPen();

  for (int c = 0; c < 16; c++) {
    pen
      ..reset()
      ..white(bold: true)
      ..xterm(c, bg: true);
    sb.write(pen("${_toSpace(c)} "));
    pen
      ..reset()
      ..xterm(c);
    sb.write(pen(" ${_toSpace(c)} "));
    if (c == 7 || c == 15) {
      sb.write("\n");
    }
  }

  for (int r = 0; r < 6; r++) {
    sb.write("\n");
    for (int g = 0; g < 6; g++) {
      for (int b = 0; b < 6; b++) {
        var c = r * 36 + g * 6 + b + 16;
        pen
          ..reset()
          ..rgb(r: r / 5, g: g / 5, b: b / 5, bg: true)
          ..white(bold: true);
        sb.write(pen(" ${_toSpace(c)} "));
        pen
          ..reset()
          ..rgb(r: r / 5, g: g / 5, b: b / 5);
        sb.write(pen(" ${_toSpace(c)} "));
      }
      sb.write("\n");
    }
  }

  for (int c = 0; c < 24; c++) {
    if (0 == c % 8) {
      sb.write("\n");
    }
    pen
      ..reset()
      ..gray(level: c / 23, bg: true)
      ..white(bold: true);
    sb.write(pen(" ${_toSpace(c + 232)} "));
    pen
      ..reset()
      ..gray(level: c / 23);
    sb.write(pen(" ${_toSpace(c + 232)} "));
  }
  return sb.toString();
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  ansicolor: ^1.0.2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:ansicolor/ansicolor.dart';
  
Version Uploaded Documentation Archive
1.0.2 Jul 24, 2018 Go to the documentation of ansicolor 1.0.2 Download ansicolor 1.0.2 archive
1.0.1 Jul 23, 2018 Go to the documentation of ansicolor 1.0.1 Download ansicolor 1.0.1 archive
0.1.1 Jun 20, 2018 Go to the documentation of ansicolor 0.1.1 Download ansicolor 0.1.1 archive
0.1.0 Feb 22, 2018 Go to the documentation of ansicolor 0.1.0 Download ansicolor 0.1.0 archive
0.0.10 Jun 20, 2018 Go to the documentation of ansicolor 0.0.10 Download ansicolor 0.0.10 archive
0.0.9 Aug 20, 2013 Go to the documentation of ansicolor 0.0.9 Download ansicolor 0.0.9 archive
0.0.8 Jul 16, 2013 Go to the documentation of ansicolor 0.0.8 Download ansicolor 0.0.8 archive
0.0.7 Jul 16, 2013 Go to the documentation of ansicolor 0.0.7 Download ansicolor 0.0.7 archive
0.0.6 Jul 16, 2013 Go to the documentation of ansicolor 0.0.6 Download ansicolor 0.0.6 archive
0.0.5 Jul 16, 2013 Go to the documentation of ansicolor 0.0.5 Download ansicolor 0.0.5 archive

All 14 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
80
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
90
Learn more about scoring.

We analyzed this package on Aug 10, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.11.8

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:ansicolor/ansicolor.dart.

Suggestions

The description is too short.

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.36.0 <3.0.0
Dev dependencies
test >=0.12.18