Skip to content

Latest commit

 

History

History
67 lines (49 loc) · 1.33 KB

README.textile

File metadata and controls

67 lines (49 loc) · 1.33 KB

ansicolors.lua

ansicolors is a simple Lua function for printing to the console in color.

Installation

Put the file ansicolors.lua somewhere where your Lua interpreter will be able to find it. Then:

  local ansicolors = require 'ansicolors'

Usage

  local colors = require 'ansicolors'
  print(colors('%{red}hello'))
  print(colors('%{redbg}hello{%reset}'))
  print(colors('%{bright red underlined}hello'))

Testing

This application uses telescope in order to perform the tests. Install telescope, and then execute


tsc specs/ansicolors_spec.lua

Notice that the tests will only work on an ANSI-compatible machine (windows isn’t ANSI-compatible)

Windows

Windows console, by default, isn’t capable of handling ANSI color codes correctly. This library tries to detect whether it is on a windows machine (by looking at package.path) and in that case it suppresses all ANSI control characters (the text appears devoid of color, but legible).

Valid attribute list:

Misc. attributes:

  • reset
  • bright
  • dim
  • underline
  • blink
  • reverse
  • hidden

Foreground colors:

  • black
  • red
  • green
  • yellow
  • blue
  • magenta
  • cyan
  • white

Background colors:

  • blackbg
  • redbg
  • greenbg
  • yellowbg
  • bluebg
  • magentabg
  • cyanbg
  • whitebg