supernova
supernova copied to clipboard
Terminal string styling. Put some color in your console! Support for Fennel, Lua, and Shell.
Supernova
Terminal string styling. Put some color in your console! Support for Fennel, Lua, and Shell.

fortune | cowsay | supernova
- Flavors:
- Fennel
- Lua
- Shell
-
Installing
- Installing for Fennel
-
Principles
- Portability
-
Room for Improvement
- Chaining
- Color Proximity
- Gradient
- VGA Mode 13h
- Packages
-
Contributing
- Style Guide
- Acknowledgments
- References
- Screenshots
Fennel
"Fennel is a programming language that brings together the speed, simplicity, and reach of Lua with the flexibility of a lisp syntax and macro system." fennel-lang.org
(local supernova (require :supernova))
(print (supernova.italic.yellow "WARNING: Intense color found."))
(print (supernova.underline.color "Beautiful pink." "#e317e0"))
(print (supernova.gradient
"Reflection, refraction and dispersion."
["#FF0000" "#FFFF00" "#00FF00" "#0FF0FE" "#233CFE"]))
Check the installation instructions.
Check the complete documentation for the Fennel library.
Lua
local supernova = require 'supernova'
print(supernova.italic.yellow('WARNING: Intense color found.'))
print(supernova.underline.color('Beautiful pink.', '#e317e0'))
print(supernova.gradient(
'Reflection, refraction and dispersion.',
{ '#FF0000', '#FFFF00', '#00FF00', '#0FF0FE', '#233CFE' }
))
Check the complete documentation for the Lua library.
Shell
supernova inspect '#eb4934'
echo WARNING: Intense color found. | supernova italic.yellow
echo Beautiful pink. | supernova underline.color '#e317e0'
echo Reflection, refraction and dispersion. | \
supernova gradient \
'#FF0000' '#FFFF00' '#00FF00' '#0FF0FE' '#233CFE'
Check the complete documentation for the Shell CLI.
Installing
Ensure that you have Lua and LuaRocks installed.
Installation through LuaRocks:
Installing for the user (recommended):
luarocks install supernova --local
Installing for the system:
sudo luarocks install supernova
Installing for Fennel
To install through fnx, add to your .fnx.fnl
:
:supernova {:lua/rock ">= 0.0.2"}
; Example:
{:name "my-project"
:version "0.0.1"
:dependencies {
:supernova {:lua/rock ">= 0.0.2"}}}
Principles
This project is a spark towards a higher purpose. There are principles to ensure that we are on track. These principles should help with discussions and decision making:
1) Portability
There must be no external dependencies other than Lua. There must be no need to use LuaJIT or any special implementation than the standard Lua. The code must work on any platform where it is possible to run Lua.
Maintainers' priority in the pursuit of this principle:
- Free Software and Free Hardware
- Open Source Software and Open Source Hardware
- Proprietary Software and Proprietary Hardware
Room for Improvement
Chaining
The current strategy with metatables has its flaws. You can explore the problem by analyzing these samples of code:
Color Proximity
The math for the distance between two colors ain't flawless. We can do better. Current code:
local distance = (
((rgb_color[1] - cadidate_color.rgb[1]) ^ 2) +
((rgb_color[2] - cadidate_color.rgb[2]) ^ 2) +
((rgb_color[3] - cadidate_color.rgb[3]) ^ 2)
)
Gradient
We have a naive approach for gradient generation. Other algorithms could produce better results: Color gradient algorithm
Current code:
local color = {
math.floor((from_rgb[1] * (1 - mix)) + (to_rgb[1] * mix)),
math.floor((from_rgb[2] * (1 - mix)) + (to_rgb[2] * mix)),
math.floor((from_rgb[3] * (1 - mix)) + (to_rgb[3] * mix))
}
VGA Mode 13h
The current 256 VGA color representation may not be accurate enough. Some references that are worth exploring:
Packages
We currently only have luarocks packages. We have some experiments with standalone binaries and AUR packages that could be released.
Contributing
Style Guide
We ensure that Luacheck is valid for any Pull Request or commit.
Also, we follow the Olivine Labs' Lua Style Guide. The LuaRocks' Lua Style Guide is a great reference as well. If their suggestions conflict with each other, the Olivine Labs' Guide prevails.
Acknowledgments
The names for the colors come from the color-names project.
References
- https://en.wikipedia.org/wiki/ANSI_escape_code
- https://codepen.io/meodai/full/zdgXJj/
- https://gist.github.com/XVilka/8346728