Skip to content

Simple opinionated terminal coloring, identical to infamous `npm colors`

Notifications You must be signed in to change notification settings

thing-king/colors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Colors

A simple, powerful terminal coloring and styling library for Nim.

Warning

colors clashes with std/colors, ensure using import pkg/colors

Features

  • Easy-to-use text coloring and styling for terminal output
  • Support for 16 different colors (standard and bright variants)
  • Multiple text styling options (bold, italic, underline, etc.)
  • Flexible API with both function calls and method chaining
  • Background color support
  • Programmatic color selection by name

Installation

nimble install colors

Usage

This library's API is inspired by the popular npm 'colors' package for JavaScript, providing a similar intuitive experience for Nim developers.

Basic Colors

import pkg/colors

echo red("This is red text")
echo green("This is green text")
echo blue("This is blue text")
echo yellow("This is yellow text")
echo magenta("This is magenta text")
echo cyan("This is cyan text")
echo white("This is white text")
echo grey("This is grey text")  # gray() also works

Method Chaining

Just like the npm 'colors' package, you can chain multiple methods together to apply different styles:

echo "This is blue".blue
echo "This is green".green
echo "This is blue underlined".blue.underline
echo "This is bold red text".red.bold
echo "Custom styled text".color(Color.BrightGreen)

Text Styling

echo bold("This is bold text")
echo italic("This is italic text")
echo underline("This is underlined text")
echo strikethrough("This is strikethrough text")

Background Colors

echo bgRed("This has a red background")
echo "This has a green background".bgGreen
echo bgBlue("This has a blue background")

Combining Styles

echo red("This is ") & "a ".italic.green & bold("colorful ") & underline("string!").yellow
echo "Red on green".red.bgGreen & " and " & "Blue on yellow".blue.bgYellow

Custom Styling

echo colorize("Custom styled text", Color.BrightGreen, styles = [TextStyle.Bold, TextStyle.Underline])
echo colorize("Text with background", Color.White, Color.Blue, hasBg = true)

Programmatic Color Selection

let userColor = "grey"
echo colorize("This text is colored programmatically", userColor)
echo "This text is also colored programmatically".color(userColor)
echo "This has a programmatic background".onColor(userColor)

Available Colors

  • Black
  • Red
  • Green
  • Yellow
  • Blue
  • Magenta
  • Cyan
  • White
  • Grey/Gray
  • BrightRed
  • BrightGreen
  • BrightYellow
  • BrightBlue
  • BrightMagenta
  • BrightCyan
  • BrightWhite

Available Text Styles

  • Bold
  • Dim
  • Italic
  • Underline
  • Blink
  • RapidBlink
  • Reverse
  • Hidden
  • Strikethrough

About

Simple opinionated terminal coloring, identical to infamous `npm colors`

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages