plugin-technicolor
plugin-technicolor copied to clipboard
Easy colorisation for Fish shell
Technicolor
A composable way to format and colorize text. For Oh My Fish.
Technicolor is a declarative DSL which provides a DRY approach to shell text colorization.
Function DSL
Each function does one, and only one thing, and is named accordingly to its duty, with a reduced character count whenever possible. All public DSL functions are ended by :
.
Colorisation
You can make text coloured using tint:
.
tint: red 'The London bridge is falling down!'
tint: 555 'The London bridge is falling down!'
echo (tint: red 'Error!') 'Something went wrong!'
Set a background color using bg:
bg: blue 'Violets are blue'
bg: 400 'Want some wine, sir?'
Use both via command substitution!
bg: red (tint: white 'You better read this text!')
tint: white (bg: red 'You better read this text!')
Stylization
Make text bold:
bold: 'The quick brown fox jumps over the lazy dog'
Output text verbatim, without adding newlines or trailing spaces using inline:
function oompa
inline: 'Oompa Loompa '
inline: 'doom-pa-dee-do '
inline: 'I have another '
inline: 'puzzle for you'
end
Sometimes you want to wrap text in a specific column. Use wrap:
function lorem
wrap: 80 'Lorem ipsum dolor sit amet, consectetur' \
'adipiscing elit. Nulla in purus quis erat' \
'aliquet tristique eget et risus. Pellentesque' \
'eget leo id urna dignissim elementum quis ut' \
'libero. Vivamus interdum at nunc sagittis cursus.'
end
What Technicolor fixes
Fish shell provides the builtin function set_color
, which abstracts terminal text colorization in a orthogonal function.
Note that even using this abstraction, shell colors still continue to be stateful, so once you switch to a color you need to reset the changes manually. This fact makes producing beautiful CLIs a true nightmare:
function explode
set_color --bold red
printf "Error: "
set_color normal
set_color red
echo "You can't explode"
set_color normal
end
Using Technicolor it's possible to transform the above function into the one below:
function explode
echo (tint: red (bold: 'Error:')) (tint: red 'You can\'t explode')
end
License
MIT © Derek Stavis et al