pax_global_header00006660000000000000000000000064121115216600014505gustar00rootroot0000000000000052 comment=a209800d08a2b6a2445d2033cece0ed29fee1a2e ansicolors.lua-1.0.2/000077500000000000000000000000001211152166000144415ustar00rootroot00000000000000ansicolors.lua-1.0.2/.travis.yml000066400000000000000000000002751211152166000165560ustar00rootroot00000000000000language: erlang env: - LUA="" - LUA="luajit" install: - sudo apt-get install luajit - sudo apt-get install luarocks - sudo luarocks install telescope script: "tsc -f specs/*" ansicolors.lua-1.0.2/COPYING000066400000000000000000000021671211152166000155020ustar00rootroot00000000000000Copyright (c) 2009 Rob Hoelz Copyright (c) 2011 Enrique García Cota Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ansicolors.lua-1.0.2/README.textile000066400000000000000000000033251211152166000170010ustar00rootroot00000000000000h1. 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 underlined}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.lua
Notice 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@ ansicolors.lua-1.0.2/ansicolors-1.0-1.rockspec000066400000000000000000000010301211152166000207740ustar00rootroot00000000000000package = "ansicolors" version = "1.0-1" source = { url = "https://github.com/downloads/kikito/ansicolors.lua/ansicolors-1.0.tar.gz" } description = { summary = "Library for color Manipulation.", detailed = [[ Ansicolors is a simple Lua function for printing to the console in color. ]], homepage = "https://github.com/kikito/ansicolors.lua", license = "MIT " } dependencies = { "lua >= 5.1" } build = { type = "builtin", modules = { ["ansicolors"] = "ansicolors.lua" } } ansicolors.lua-1.0.2/ansicolors.lua000066400000000000000000000053441211152166000173260ustar00rootroot00000000000000-- ansicolors.lua v1.0.2 (2012-08) -- Copyright (c) 2009 Rob Hoelz -- Copyright (c) 2011 Enrique García Cota -- -- Permission is hereby granted, free of charge, to any person obtaining a copy -- of this software and associated documentation files (the "Software"), to deal -- in the Software without restriction, including without limitation the rights -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -- copies of the Software, and to permit persons to whom the Software is -- furnished to do so, subject to the following conditions: -- -- The above copyright notice and this permission notice shall be included in -- all copies or substantial portions of the Software. -- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -- THE SOFTWARE. -- support detection local function isWindows() return type(package) == 'table' and type(package.config) == 'string' and package.config:sub(1,1) == '\\' end local supported = not isWindows() if isWindows() then supported = os.getenv("ANSICON") end local keys = { -- reset reset = 0, -- misc bright = 1, dim = 2, underline = 4, blink = 5, reverse = 7, hidden = 8, -- foreground colors black = 30, red = 31, green = 32, yellow = 33, blue = 34, magenta = 35, cyan = 36, white = 37, -- background colors blackbg = 40, redbg = 41, greenbg = 42, yellowbg = 43, bluebg = 44, magentabg = 45, cyanbg = 46, whitebg = 47 } local escapeString = string.char(27) .. '[%dm' local function escapeNumber(number) return escapeString:format(number) end local function escapeKeys(str) if not supported then return "" end local buffer = {} local number for word in str:gmatch("%w+") do number = keys[word] assert(number, "Unknown key: " .. word) table.insert(buffer, escapeNumber(number) ) end return table.concat(buffer) end local function replaceCodes(str) str = string.gsub(str,"(%%{(.-)})", function(_, str) return escapeKeys(str) end ) return str end -- public local function ansicolors( str ) str = tostring(str or '') return replaceCodes('%{reset}' .. str .. '%{reset}') end return setmetatable({noReset = replaceCodes}, {__call = function (_, str) return ansicolors (str) end}) ansicolors.lua-1.0.2/specs/000077500000000000000000000000001211152166000155565ustar00rootroot00000000000000ansicolors.lua-1.0.2/specs/ansicolors_spec.lua000066400000000000000000000054041211152166000214520ustar00rootroot00000000000000local ansicolors = require 'ansicolors' local c27 = string.char(27) describe('ansicolors', function() it('should add resets if no options given', function() assert_equal(ansicolors('foo'), c27 .. '[0m' .. 'foo' .. c27 .. '[0m' ) end) it('should throw an error on invalid options', function() assert_error(function() ansicolors('%{blah}foo') end) end) it('should add red color to text', function() assert_equal(ansicolors('%{red}foo'), c27 .. '[0m' .. c27 .. '[31mfoo' .. c27 .. '[0m') end) it('should add red underlined text', function() assert_equal(ansicolors('%{red underline}foo'), c27 .. '[0m' .. c27 .. '[31m' .. c27 .. '[4mfoo' .. c27 .. '[0m') end) it('should with heterogeneous attributes', function() assert_equal(ansicolors('%{bright white}*%{bright red}BEEP%{bright white}*'), c27 .. '[0m' .. c27 .. '[1m' .. c27 .. '[37m*' .. c27 .. '[1m' .. c27 .. '[31mBEEP' .. c27 .. '[1m' .. c27 .. '[37m*' .. c27 .. '[0m') end) describe('noReset', function () it('should do nothing if no options given', function() assert_equal(ansicolors.noReset('foo'), 'foo' ) end) it('should throw an error on invalid options', function() assert_error(function() ansicolors.noReset('%{blah}foo') end) end) it('should add red color to text', function() assert_equal(ansicolors.noReset('%{red}foo'), c27 .. '[31mfoo') end) it('should add red underlined text', function() assert_equal(ansicolors.noReset('%{red underline}foo'), c27 .. '[31m' .. c27 .. '[4mfoo') end) it('should with heterogeneous attributes', function() assert_equal(ansicolors.noReset('%{bright white}*%{bright red}BEEP%{bright white}*'), c27 .. '[1m' .. c27 .. '[37m*' .. c27 .. '[1m' .. c27 .. '[31mBEEP' .. c27 .. '[1m' .. c27 .. '[37m*') end) end) describe('support detection', function() it('should return a plain text string on systems with no package.config', function() local prevConfig = package.config package.config = "\\" local colors = dofile 'ansicolors.lua' assert_equal(colors('%{red underline}foo'), 'foo') io.popen = prevIoPopen end) end) describe('under Windows', function() describe('without ANSICON', function() it('should return a plain text string', function() package.config = "\\" local colors = dofile 'ansicolors.lua' assert_equal(colors('%{red}foo'), 'foo') end) end) describe('with ANSICON', function() it('should add ANSI escapes to text', function() package.config = "\\" os.getenv = function () return true end local colors = dofile 'ansicolors.lua' assert_equal(colors('%{red}foo'), c27 .. '[0m' .. c27 .. '[31mfoo' .. c27 .. '[0m') end) end) end) end)