All Projects → doowb → Ansi Colors

doowb / Ansi Colors

Licence: mit
Easily add ANSI colors to your text and symbols in the terminal. ansi-colors is the official ansi styling library for gulp, and is used by hundreds of other projects, including mocha and enquirer.

Programming Languages

javascript
184084 projects - #8 most used programming language
symbols
36 projects

Projects that are alternatives of or similar to Ansi Colors

kolorist
A tiny utility to colorize stdin/stdout
Stars: ✭ 160 (-46.67%)
Mutual labels:  colors, ansi, ansi-colors
log-utils
Basic logging utils: colors, symbols and timestamp.
Stars: ✭ 24 (-92%)
Mutual labels:  colors, ansi, ansi-colors
Jcolor
An easy syntax to format your strings with colored fonts and backgrounds.
Stars: ✭ 255 (-15%)
Mutual labels:  ansi, ansi-colors
kotter
A declarative, Kotlin-idiomatic API for writing dynamic console applications.
Stars: ✭ 355 (+18.33%)
Mutual labels:  ansi, ansi-colors
ansicolor
A JavaScript ANSI color/style management. ANSI parsing. ANSI to CSS. Small, clean, no dependencies.
Stars: ✭ 91 (-69.67%)
Mutual labels:  ansi, ansi-colors
Colorette
Easily set the color and style of text in the terminal.
Stars: ✭ 1,047 (+249%)
Mutual labels:  ansi, colors
Ansi Econsole
Eclipse plugin that understands ANSI escape sequences to color the Eclipse console output.
Stars: ✭ 72 (-76%)
Mutual labels:  ansi, ansi-colors
leeks.js
Simple ANSI styling for your terminal
Stars: ✭ 12 (-96%)
Mutual labels:  colors, ansi
Paint
Ruby gem for ANSI terminal colors 🎨︎ VERY FAST
Stars: ✭ 317 (+5.67%)
Mutual labels:  ansi, ansi-colors
ansiart2utf8
Processes legacy BBS-style ANSI art (ACiDDraw, PabloDraw, etc.) to UTF-8. Escape codes and line endings are processed for terminal friendliness.
Stars: ✭ 32 (-89.33%)
Mutual labels:  ansi, ansi-colors
ansi-php
ANSI Control Functions and ANSI Control Sequences (Colors, Erasing, etc.) for PHP CLI Apps
Stars: ✭ 82 (-72.67%)
Mutual labels:  ansi, ansi-colors
Picocli
Picocli is a modern framework for building powerful, user-friendly, GraalVM-enabled command line apps with ease. It supports colors, autocompletion, subcommands, and more. In 1 source file so apps can include as source & avoid adding a dependency. Written in Java, usable from Groovy, Kotlin, Scala, etc.
Stars: ✭ 3,286 (+995.33%)
Mutual labels:  ansi, ansi-colors
Termenv
Advanced ANSI style & color support for your terminal applications
Stars: ✭ 555 (+85%)
Mutual labels:  ansi, colors
Colorful
Terminal string styling done right, in Python 🐍 🎉
Stars: ✭ 456 (+52%)
Mutual labels:  ansi, colors
Ololog
A better console.log for the log-driven debugging junkies
Stars: ✭ 141 (-53%)
Mutual labels:  ansi, ansi-colors
Mordant
Full-featured text styling for Kotlin command-line applications
Stars: ✭ 382 (+27.33%)
Mutual labels:  ansi, ansi-colors
Cl Ansi Text
Enables ANSI colors for printing.
Stars: ✭ 30 (-90%)
Mutual labels:  ansi-colors, colors
concolor
Colouring template strings using tags with annotations 🎨
Stars: ✭ 35 (-88.33%)
Mutual labels:  colors, ansi
line
An easy to use golang package for stylizing terminal output
Stars: ✭ 26 (-91.33%)
Mutual labels:  colors, ansi-colors
gitlab-job-log-viewer
Browser extension for code highlighting raw logs in Gitlab CI
Stars: ✭ 21 (-93%)
Mutual labels:  ansi, ansi-colors

ansi-colors Donate NPM version NPM monthly downloads NPM total downloads Linux Build Status

Easily add ANSI colors to your text and symbols in the terminal. A faster drop-in replacement for chalk, kleur and turbocolor (without the dependencies and rendering bugs).

Please consider following this project's author, Brian Woodward, and consider starring the project to show your ❤️ and support.

Install

Install with npm:

$ npm install --save ansi-colors

image

Why use this?

ansi-colors is the fastest Node.js library for terminal styling. A more performant drop-in replacement for chalk, with no dependencies.

Usage

const c = require('ansi-colors');

console.log(c.red('This is a red string!'));
console.log(c.green('This is a red string!'));
console.log(c.cyan('This is a cyan string!'));
console.log(c.yellow('This is a yellow string!'));

image

Chained colors

console.log(c.bold.red('this is a bold red message'));
console.log(c.bold.yellow.italic('this is a bold yellow italicized message'));
console.log(c.green.bold.underline('this is a bold green underlined message'));

image

Nested colors

console.log(c.yellow(`foo ${c.red.bold('red')} bar ${c.cyan('cyan')} baz`));

image

Nested styling bug

ansi-colors does not have the nested styling bug found in colorette, chalk, and kleur.

const { bold, red } = require('ansi-styles');
console.log(bold(`foo ${red.dim('bar')} baz`));

const colorette = require('colorette');
console.log(colorette.bold(`foo ${colorette.red(colorette.dim('bar'))} baz`));

const kleur = require('kleur');
console.log(kleur.bold(`foo ${kleur.red.dim('bar')} baz`));

const chalk = require('chalk');
console.log(chalk.bold(`foo ${chalk.red.dim('bar')} baz`));

Results in the following

(sans icons and labels)

image

Toggle color support

Easily enable/disable colors.

const c = require('ansi-colors');

// disable colors manually
c.enabled = false;

// or use a library to automatically detect support
c.enabled = require('color-support').hasBasic;

console.log(c.red('I will only be colored red if the terminal supports colors'));

Strip ANSI codes

Use the .unstyle method to strip ANSI codes from a string.

console.log(c.unstyle(c.blue.bold('foo bar baz')));
//=> 'foo bar baz'

Available styles

Note that bright and bright-background colors are not always supported.

Colors Background Colors Bright Colors Bright Background Colors
black bgBlack blackBright bgBlackBright
red bgRed redBright bgRedBright
green bgGreen greenBright bgGreenBright
yellow bgYellow yellowBright bgYellowBright
blue bgBlue blueBright bgBlueBright
magenta bgMagenta magentaBright bgMagentaBright
cyan bgCyan cyanBright bgCyanBright
white bgWhite whiteBright bgWhiteBright
gray
grey

(gray is the U.S. spelling, grey is more commonly used in the Canada and U.K.)

Style modifiers

  • dim

  • bold

  • hidden

  • italic

  • underline

  • inverse

  • strikethrough

  • reset

Aliases

Create custom aliases for styles.

const colors = require('ansi-colors');

colors.alias('primary', colors.yellow);
colors.alias('secondary', colors.bold);

console.log(colors.primary.secondary('Foo'));

Themes

A theme is an object of custom aliases.

const colors = require('ansi-colors');

colors.theme({
  danger: colors.red,
  dark: colors.dim.gray,
  disabled: colors.gray,
  em: colors.italic,
  heading: colors.bold.underline,
  info: colors.cyan,
  muted: colors.dim,
  primary: colors.blue,
  strong: colors.bold,
  success: colors.green,
  underline: colors.underline,
  warning: colors.yellow
});

// Now, we can use our custom styles alongside the built-in styles!
console.log(colors.danger.strong.em('Error!'));
console.log(colors.warning('Heads up!'));
console.log(colors.info('Did you know...'));
console.log(colors.success.bold('It worked!'));

Performance

Libraries tested

  • ansi-colors v3.0.4
  • chalk v2.4.1

Mac

MacBook Pro, Intel Core i7, 2.3 GHz, 16 GB.

Load time

Time it takes to load the first time require() is called:

  • ansi-colors - 1.915ms
  • chalk - 12.437ms

Benchmarks

# All Colors
  ansi-colors x 173,851 ops/sec ±0.42% (91 runs sampled)
  chalk x 9,944 ops/sec ±2.53% (81 runs sampled)))

# Chained colors
  ansi-colors x 20,791 ops/sec ±0.60% (88 runs sampled)
  chalk x 2,111 ops/sec ±2.34% (83 runs sampled)

# Nested colors
  ansi-colors x 59,304 ops/sec ±0.98% (92 runs sampled)
  chalk x 4,590 ops/sec ±2.08% (82 runs sampled)

Windows

Windows 10, Intel Core i7-7700k CPU @ 4.2 GHz, 32 GB

Load time

Time it takes to load the first time require() is called:

  • ansi-colors - 1.494ms
  • chalk - 11.523ms

Benchmarks

# All Colors
  ansi-colors x 193,088 ops/sec ±0.51% (95 runs sampled))
  chalk x 9,612 ops/sec ±3.31% (77 runs sampled)))

# Chained colors
  ansi-colors x 26,093 ops/sec ±1.13% (94 runs sampled)
  chalk x 2,267 ops/sec ±2.88% (80 runs sampled))

# Nested colors
  ansi-colors x 67,747 ops/sec ±0.49% (93 runs sampled)
  chalk x 4,446 ops/sec ±3.01% (82 runs sampled))

About

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Running Tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

$ npm install && npm test
Building docs

(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)

To generate the readme, run the following command:

$ npm install -g verbose/verb#dev verb-generate-readme && verb

Related projects

You might also be interested in these projects:

Contributors

Commits Contributor
48 jonschlinkert
42 doowb
6 lukeed
2 Silic0nS0ldier
1 dwieeb
1 jorgebucaran
1 madhavarshney
1 chapterjason

Author

Brian Woodward

License

Copyright © 2019, Brian Woodward. Released under the MIT License.


This file was generated by verb-generate-readme, v0.8.0, on July 01, 2019.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].