Git Product home page Git Product logo

ansicolor-dart's Introduction

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 = AnsiPen()..white(bold: true);
print(pen("Bright white foreground") + " this text is default fg/bg");

Background as a peach, foreground as white:

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

Note

If color isn't working for you; try setting ansiColorDisabled = false;. We're relying on the stdio object to inform us of ANSI terminal support. Sometimes this is wrong.

Prior versions of this library just turned on color by default.

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

ansicolor-dart's People

Contributors

davidmorgan avatar frezyx avatar gzgavinzhao avatar jtmcdole avatar kabagouda avatar lyceel avatar michaelrfairhurst avatar natebosch avatar sigmundch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ansicolor-dart's Issues

not work on iOS (Android is fine)

I got some logs like these on iOS:

flutter: ^[[38;5;246mI/17:21:00
flutter: ^[[38;5;246mI/17:21:00
flutter: ^[[38;5;246mI/17:21:00
flutter: ^[[38;5;246mI/17:21:00
flutter: ^[[38;5;246mI/17:21:00
flutter: ^[[38;5;246mI/17:21:00

flutter doctor:
[✓] Flutter (Channel stable, 2.0.4, on Mac OS X 10.15.5 19F101 darwin-x64, locale en-AS)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[✓] Xcode - develop for iOS and macOS
[✓] Android Studio (version 4.1)
[✓] IntelliJ IDEA Ultimate Edition (version 2020.3.1)
[✓] VS Code (version 1.55.2)
[✓] Proxy Configuration
[✓] Connected device (1 available)

flutter devices: (iphone 6p)
Phone (mobile) • b6a915834fadb0f*********accbe869c39966e9f • ios • iOS 12.5.1

How can I solve this problem?

Avoid `color_disabled` global state

color_disabled is global state, and since ansi color is kind of a cross-cutting concern, two different parts of an application could easily mess up each other's state. I think the best way to handle this would be to provide a means to run code in a Zone which exposes a Zone local colorDisabled value, which each ansi pen can read from.

I have a mechanism for this in the clock package:

https://github.com/seaneagan/clock/blob/master/lib/src/zoned_value.dart

Which I use for the withClock method seen here:

https://github.com/seaneagan/clock

Make ansi_demo a script.

IMO it would be better suited as a script than a function in the main library:

pub global activate ansicolor
pub global run ansicolor:demo

Documentation Error (Example in README Doesn't Work)

Small error, but perhaps could cause a great amount of bewildering for beginners:

In the example with a background as a peach, foreground as white, rgb(r: 1.0, g: 0.8, b: 0.2) should be rgb(r: 1.0, g: 0.8, b: 0.2, bg = true), otherwise it will be recognized as a foreground color.

Not print with color in flutter

Hi, I try to print with color in vs code and I only get a normal print color.

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

Output: flutter: ^[[38;5;9mBright white foreground^[[0m this text is default f<…>

Stopped working after update

I was using version 1.0.2, then I updated to version 1.1.1 and it stopped working (i.e. the letters are not colored).

-Reverted this project back to version 1.0.2, run a flutter clean, run project - not working.
-Created a new flutter project with only this package (v 1.1.1) - doesn't work.
-Installed other alternative ansi styling packages - they also not working now
-Opened my another project that was using version 1.0.2 - working ok.

here is my flutter doctor:

[✓] Flutter (Channel stable, 1.22.5, on macOS 11.1 20C69 darwin-x64, locale en)
• Flutter version 1.22.5 at /Users/tema/programs/flutter
• Framework revision 7891006299 (5 weeks ago), 2020-12-10 11:54:40 -0800
• Engine revision ae90085a84
• Dart version 2.10.4

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at /Users/tema/Library/Android/sdk
• Platform android-30, build-tools 30.0.3
• ANDROID_HOME = /Users/tema/Library/Android/sdk
• Java binary at: /Applications/Android
Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build
1.8.0_242-release-1644-b3-6915495)
• All Android licenses accepted.

[✗] Xcode - develop for iOS and macOS
✗ Xcode installation is incomplete; a full installation is necessary for iOS
development.
Download at: https://developer.apple.com/xcode/download/
Or install Xcode via the App Store.
Once installed, run:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
sudo xcodebuild -runFirstLaunch
✗ CocoaPods not installed.
CocoaPods is used to retrieve the iOS and macOS platform side's plugin
code that responds to your plugin usage on the Dart side.
Without CocoaPods, plugins will not work on iOS or macOS.
For more info, see https://flutter.dev/platform-plugins
To install:
sudo gem install cocoapods

[!] Android Studio (version 4.1)
• Android Studio at /Applications/Android Studio.app/Contents
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
• Java version OpenJDK Runtime Environment (build
1.8.0_242-release-1644-b3-6915495)

[✓] VS Code (version 1.52.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.18.1

[✓] Connected device (1 available)
• Redmi Go (mobile) • 192.168.88.230:5555 • android-arm • Android 8.1.0 (API
27)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.