All Projects → bokub → Gradient String

bokub / Gradient String

Licence: mit
🌈 Beautiful color gradients in terminal output

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Gradient String

Chalk
🖍 Terminal string styling done right
Stars: ✭ 17,566 (+3590.34%)
Mutual labels:  terminal, console, color
Crossterm
Cross platform terminal library rust
Stars: ✭ 1,023 (+114.92%)
Mutual labels:  terminal, console, color
Closestx11color
Find the closest xterm-256 colors (between 0 and 255) to an arbitrary HTML hexa color (e.g. #ABCDEF)
Stars: ✭ 13 (-97.27%)
Mutual labels:  terminal, console, color
Rang
A Minimal, Header only Modern c++ library for terminal goodies 💄✨
Stars: ✭ 1,080 (+126.89%)
Mutual labels:  terminal, console, color
Box Cli Maker
Make Highly Customized Boxes for your CLI
Stars: ✭ 115 (-75.84%)
Mutual labels:  terminal, console, color
Chalk Animation
🎬 Colorful animations in terminal output
Stars: ✭ 1,489 (+212.82%)
Mutual labels:  terminal, console, color
Crossline
A small, self-contained, zero-config, MIT licensed, cross-platform, readline and libedit replacement.
Stars: ✭ 53 (-88.87%)
Mutual labels:  terminal, console, color
Php Console Spinner
Colorful highly configurable spinner for php cli applications (suitable for async apps)
Stars: ✭ 225 (-52.73%)
Mutual labels:  terminal, console, color
Mordant
Full-featured text styling for Kotlin command-line applications
Stars: ✭ 382 (-19.75%)
Mutual labels:  terminal, console, color
Hues
Colored terminal text made easy for Python and happiness.
Stars: ✭ 345 (-27.52%)
Mutual labels:  terminal, color
Console
The Hoa\Console library.
Stars: ✭ 354 (-25.63%)
Mutual labels:  terminal, console
Stig
TUI and CLI for the BitTorrent client Transmission
Stars: ✭ 360 (-24.37%)
Mutual labels:  terminal, console
Bcal
🔢 Storage and general-purpose calculator
Stars: ✭ 329 (-30.88%)
Mutual labels:  terminal, console
Tqdm
A Fast, Extensible Progress Bar for Python and CLI
Stars: ✭ 20,632 (+4234.45%)
Mutual labels:  terminal, console
Colorls
A Ruby gem that beautifies the terminal's ls command, with color and font-awesome icons. 🎉
Stars: ✭ 3,896 (+718.49%)
Mutual labels:  terminal, color
Cfiles
A ncurses file manager written in C with vim like keybindings
Stars: ✭ 319 (-32.98%)
Mutual labels:  terminal, console
Nord Emacs
An arctic, north-bluish clean and elegant Emacs theme.
Stars: ✭ 379 (-20.38%)
Mutual labels:  terminal, color
Mle
Flexible terminal-based text editor (C)
Stars: ✭ 378 (-20.59%)
Mutual labels:  terminal, console
Coolhue
Coolest Gradient Hues and Swatches
Stars: ✭ 3,307 (+594.75%)
Mutual labels:  color, gradient
Lazykube
⎈ The lazier way to manage kubernetes.
Stars: ✭ 369 (-22.48%)
Mutual labels:  terminal, console

gradient-string

Build Status Version Codecov Downloads XO code style Mentioned in Awesome Node.js

Beautiful color gradients in terminal output

gradient-string

Install

$ npm i gradient-string

Usage

const gradient = require('gradient-string');

console.log(gradient('cyan', 'pink')('Hello world!'));

Initialize a gradient

// Using varargs
let coolGradient = gradient('red', 'green', 'blue');

// Using array
let coolGradient = gradient(['#FF0000', '#00FF00', '#0000FF']);

The colors are parsed with TinyColor, multiple formats are accepted.

let coolGradient = gradient([
  tinycolor('#FFBB65'),       // tinycolor object
  {r: 0, g: 255, b: 0},       // RGB object
  {h: 240, s: 1, v: 1, a: 1}, // HSVa object
  'rgb(120, 120, 0)',         // RGB CSS string
  'gold'                      // named color
]);

Use a gradient

let coolString = coolGradient('This is a fancy string!');
console.log(coolString);

Built-in gradients

Usage

const gradient = require('gradient-string');

// Use the rainbow gradient
console.log(gradient.rainbow('I love gradient-strings!'))

Available built-in gradients

Built-in gradients

Multi line gradients

In some cases, you may want to apply the same horizontal gradient on each line of a long text (or a piece of ASCII art).

You can use the multiline() method of a gradient to ensure that the colors are vertically aligned.

const gradient = require('gradient-string');

// Use the same gradient on every line
let duck = gradient('orange', 'yellow').multiline([
    "  __",
    "<(o )___",
    " ( ._> /",
    "  `---'",
].join('\n'));
console.log(duck);

// Works with aliases
gradient.atlas.multiline('Multi line\nstring');

// Works with advanced options
gradient('cyan', 'pink').multiline('Multi line\nstring', {interpolation: 'hsv'});

Advanced gradients

There are also more advanced options for gradient customization, such as custom color stops, or choice of color interpolation

Custom color stops

By default, the gradient color stops are distributed equidistantly.

You can specify the position of each color stop (between 0 and 1), using the following syntax:

let coolGradient = gradient([
  {color: '#d8e0de', pos: 0},
  {color: '#255B53', pos: 0.8},
  {color: '#000000', pos: 1}
]);

Color interpolation

When using a gradient, you can actually add a second parameter to choose how the colors will be generated.

Here is the full gradient API:

myGradient(text, [options])

text

Type: string
String you want to color.

options

Type: Object

interpolation

Type: string
The gradient can be generated using RGB or HSV interpolation. HSV usually produces brighter colors. interpolation can be set to rgb for RGB interpolation, orhsv for HSV interpolation.
Defaults to rgb. Case insentitive

hsvSpin

Type: string
Used only in the case of HSV interpolation.
Because hue can be considered as a circle, there are two ways to go from a color to another color.
hsvSpin can be either short or long, depending on if you want to take the shortest or the longest way between two colors.
Defaults to short. Case insensitive

Example

Code
const redToGreen = gradient('red', 'green');
const str = '■'.repeat(48);

// Standard RGB gradient
console.log(redToGreen(str)); 

// Short HSV gradient: red -> yellow -> green
console.log(redToGreen(str, {interpolation: 'hsv'}));

// Long HSV gradient: red -> magenta -> blue -> cyan -> green
console.log(redToGreen(str, {interpolation: 'hsv', hsvSpin: 'long'}));
Result

Example result

Typescript

Typescript definitions of gradient-string are available on DefinitelyTyped

npm i @types/gradient-string

Dependencies

License

MIT © Boris K

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].