ansicolors.lua
ansicolors.lua copied to clipboard
Possibility to escape %{} sequences?
If the string passed to colors() contains %{...} sequences which aren't colours, then an exception is thrown:
> local colors = require 'ansicolors'; print(colors('%{red}%{example}'))
/usr/local/share/lua/5.2/ansicolors.lua:79: Unknown key: example
stack traceback:
[C]: in function 'assert'
/usr/local/share/lua/5.2/ansicolors.lua:79: in function </usr/local/share/lua/5.2/ansicolors.lua:71>
(...tail calls...)
[C]: in function 'gsub'
/usr/local/share/lua/5.2/ansicolors.lua:87: in function </usr/local/share/lua/5.2/ansicolors.lua:86>
(...tail calls...)
stdin:1: in main chunk
[C]: in ?
>
In my case I'm processing strings and doing colors("%{red}" .. subject). Would it be possible to pre-process my variables to avoid the problem? I've tried colors("%{red}\%{example}") and colors(%{red}%%{example}"), but both seem to attempt to dereference example.