├── README.md ├── showcase.lua ├── lunacolors.spec ├── LICENSE └── init.lua /README.md: -------------------------------------------------------------------------------- 1 | # Lunacolors 2 | > 💫 ANSI colors library for Lua. 3 | 4 |
5 | 6 | Lunacolors is an elegant library for handling ANSI colors in Lua. 7 | 8 | # Usage 9 | ```lua 10 | local lunacolors = require 'lunacolors' 11 | 12 | print(lunacolors.bold(lunacolors.red('Hello') .. ' World!')) 13 | ``` 14 | 15 | # License 16 | Lunacolors is licensed under the BSD 3-Clause license. 17 | [Read here](LICENSE) for more info. 18 | -------------------------------------------------------------------------------- /showcase.lua: -------------------------------------------------------------------------------- 1 | local lunacolors = require 'lunacolors' 2 | 3 | local styles = { 4 | 'bold', 'dim', 'italic', 'underline', 'invert', 5 | 'strikethrough', 6 | 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 7 | 'white', 'blackBg', 'redBg', 'greenBg', 'yellowBg', 8 | 'blueBg', 'magentaBg', 'cyanBg', 'whiteBg' 9 | } 10 | 11 | for _, k in ipairs(styles) do 12 | if k == 'red' or k == 'redBg' then io.write '\n' end 13 | io.write(lunacolors[k](k) .. ' ') 14 | end 15 | 16 | io.write '\n' 17 | -------------------------------------------------------------------------------- /lunacolors.spec: -------------------------------------------------------------------------------- 1 | Name: {{{ git_dir_name }}} 2 | Version: {{{ git_dir_version }}} 3 | Release: 1%{?dist} 4 | Summary: ANSI colors library for Lua 5 | License: MIT 6 | 7 | Source: {{{ git_dir_pack }}} 8 | 9 | Url: https://github.com/Rosettea/lunacolors 10 | VCS: {{{ git_dir_vcs }}} 11 | BuildArch: noarch 12 | 13 | %description 14 | Lunacolors is an elegant library for handling ANSI colors in Lua. 15 | 16 | %prep 17 | {{{ git_dir_setup_macro }}} 18 | 19 | %build 20 | 21 | %install 22 | install -Dm644 init.lua -t %{buildroot}/usr/share/hilbish/libs/lunacolors/ 23 | 24 | %files 25 | %doc README.md 26 | %license LICENSE 27 | /usr/share/hilbish/libs/lunacolors/init.lua 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2021-2022 Rosettea 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /init.lua: -------------------------------------------------------------------------------- 1 | function ansi(open, close, text) 2 | if text == nil then return '\27[' .. open .. 'm' end 3 | return '\27[' .. open .. 'm' .. text .. '\27[' .. close .. 'm' 4 | end 5 | 6 | local Lunacolors = { 7 | formatColors = { 8 | boldOff = ansi(22), 9 | underlineOff = ansi(24) 10 | }, 11 | version = 'v0.2.1' 12 | } 13 | 14 | function init(name, codes) 15 | Lunacolors[name] = function(text) 16 | return ansi(codes[1], codes[2], text) 17 | end 18 | Lunacolors.formatColors[name] = ansi(codes[1]) 19 | end 20 | 21 | -- Define colors 22 | -- Modifiers 23 | init('reset', {0, 0}) 24 | init('bold', {1, 22}) 25 | init('dim', {2, 22}) 26 | init('italic', {3, 23}) 27 | init('underline', {4, 24}) 28 | init('invert', {7, 27}) 29 | init('hidden', {8, 28}) 30 | init('strikethrough', {9, 29}) 31 | 32 | -- Colors 33 | init('black', {30, 39}) 34 | init('red', {31, 39}) 35 | init('green', {32, 39}) 36 | init('yellow', {33, 39}) 37 | init('blue', {34, 39}) 38 | init('magenta', {35, 39}) 39 | init('cyan', {36, 39}) 40 | init('white', {37, 39}) 41 | 42 | -- Background colors 43 | init('blackBg', {40, 49}) 44 | init('redBg', {41, 49}) 45 | init('greenBg', {42, 49}) 46 | init('yellowBg', {43, 49}) 47 | init('blueBg', {44, 49}) 48 | init('magentaBg', {45, 49}) 49 | init('cyanBg', {46, 49}) 50 | init('whiteBg', {47, 49}) 51 | 52 | -- Bright colors 53 | init('brightBlack', {90, 39}) 54 | init('gray', {90, 39}) 55 | init('grey', {90, 39}) 56 | init('brightRed', {91, 39}) 57 | init('brightGreen', {92, 39}) 58 | init('brightYellow', {93, 39}) 59 | init('brightBlue', {94, 39}) 60 | init('brightMagenta', {95, 39}) 61 | init('brightCyan', {96, 39}) 62 | init('brightWhite', {97, 39}) 63 | 64 | -- Bright background 65 | init('brightBlackBg', {100, 49}) 66 | init('grayBg', {100, 49}) 67 | init('greyBg', {100, 49}) 68 | init('brightRedBg', {101, 49}) 69 | init('brightGreenBg', {102, 49}) 70 | init('brightYellowBg', {103, 49}) 71 | init('brightBlueBg', {104, 49}) 72 | init('brightMagentaBg', {105, 49}) 73 | init('brightCyanBg', {106, 49}) 74 | init('brightWhiteBg', {107, 49}) 75 | 76 | Lunacolors.format = function(text) 77 | for k, v in pairs(Lunacolors.formatColors) do 78 | text = text:gsub('{' .. k .. '}', v) 79 | end 80 | 81 | return text .. Lunacolors.formatColors.reset 82 | end 83 | 84 | return Lunacolors 85 | --------------------------------------------------------------------------------