colorfy 2.1.1 copy "colorfy: ^2.1.1" to clipboard
colorfy: ^2.1.1 copied to clipboard

Terminal string styling done right with Dart.

Colorfy #

Colorfy is a Dart package for styling terminal strings with colors and effects, making your CLI output more readable and visually appealing.

Features #

  • Apply foreground and background colors to text
  • Add styles like bold, underline, and more
  • Easy-to-use API for chaining styles

Highlights #

  • Expressive API
  • Highly performant
  • No dependencies
  • Ability to nest styles
  • 256/Truecolor color support
  • Auto-detects color support
  • Clean and focused
  • Actively maintained

Usage #

import 'package:colorfy/colorfy.dart';

void main() {
  print(color('Hello, World!').red().bold());
}

colorfy comes with an easy to use composable API where you just chain and nest the styles you want.

import 'package:colorfy/colorfy.dart';

// Combine styled and normal strings
void main(){
  print(color('hello') +'World'+ color('!'))
}

// Compose multiple styles using the chainable API
print(color('Hello World ').blue().bgRed().bold());

// Nest styles
print(color('hello ', [color('world').bgRed(), '!']) );


// Nest styles of the same type even (color, underline, background)
 print(
  color("i am green line ", [
    color("witth a blue substring ").bgBlue().underline(),
    'that become again!'
  ]).green()
 );


 print('''
CPU : ${color('90%').red()}
RAM : ${color('70%').yellow()}
DISK: ${color('50%').green()}
''');

// Use RGB colors in terminal emulators that support it.
print(color('Underlined reddish color').rgb(123, 45, 67).bold());
print(color('Bold Grey').hex('#DEADED'));

Easily define your own themes:

import 'package:colorfy/colorfy.dart';

const error = chalk.bold.red;
const warning = chalk.hex('#FFA500'); // Orange color

print(color())
console.log(error('Error!'));
console.log(warning('Warning!'));

Take advantage of print (String Subistition)

final name = 'KABULU';
print(color('Hello %s').green().format([name]));

Installation #

Add to your pubspec.yaml:

dependencies:
  colorfy: ^2.1.0

supportsColor #

Detect whether the terminal supports color. Used internally and handled for you, but exposed for convenience.

Can be overridden by the user with the flags --color and --no-color. For situations where using --color is not possible, use the environment variable FORCE_COLOR=1 (level 1), FORCE_COLOR=2 (level 2), or FORCE_COLOR=3 (level 3) to forcefully enable color, or FORCE_COLOR=0 to forcefully disable. The use of FORCE_COLOR overrides all other color support checks.

Explicit 256/Truecolor mode can be enabled using the --color=256 and --color=16m flags, respectively.

Windows #

If you're on Windows, do yourself a favor and use Windows Terminal instead of cmd.exe.

Maintainers #

License #

MIT

3
likes
135
points
44
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Terminal string styling done right with Dart.

Repository (GitHub)
View/report issues

License

MIT (license)

More

Packages that depend on colorfy