Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kikito/ansicolors.lua
ANSI terminal color manipulation for Lua.
https://github.com/kikito/ansicolors.lua
Last synced: about 2 months ago
JSON representation
ANSI terminal color manipulation for Lua.
- Host: GitHub
- URL: https://github.com/kikito/ansicolors.lua
- Owner: kikito
- License: mit
- Fork: true (hoelzro/ansicolors)
- Created: 2011-05-12T14:43:35.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2019-07-02T21:22:14.000Z (almost 5 years ago)
- Last Synced: 2024-04-29T21:20:55.792Z (about 2 months ago)
- Language: Lua
- Homepage:
- Size: 507 KB
- Stars: 127
- Watchers: 10
- Forks: 32
- Open Issues: 0
-
Metadata Files:
- Readme: README.textile
- License: COPYING
Lists
- awesome-lua - ansicolors - Simple function for printing to the console in color. (Resources / Command-line Utilities)
- awesome-lua-zh - ansicolors - Simple function for printing to the console in color. (资源 / Command-line Utilities)
README
h1. ansicolors.lua
!https://travis-ci.org/kikito/ansicolors.lua.png?branch=master!:https://travis-ci.org/kikito/ansicolors.lua
ansicolors is a simple Lua function for printing to the console in color.
h1. Installation
Put the file ansicolors.lua somewhere where your Lua interpreter will be able to find it. Then:
local ansicolors = require 'ansicolors'h2. Usage
local colors = require 'ansicolors'
print(colors('%{red}hello'))
print(colors('%{redbg}hello%{reset}'))
print(colors('%{bright red underline}hello'))The @colors@ function makes sure that color attributes are reset at each end of the generated string. If you want to generate complex strings piece-by-piece, use @colors.noReset@, which works exactly the same, but without adding the reset codes at each end of the string.
h2. Testing
This application uses telescope in order to perform the tests. Install telescope, and then execute
tsc specs/ansicolors_spec.luaNotice that the tests will only work on an ANSI-compatible machine (windows isn't ANSI-compatible)
h2. 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).
h2. 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@