Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility to escape %{} sequences? #12

Open
darac opened this issue Jan 11, 2025 · 0 comments
Open

Possibility to escape %{} sequences? #12

darac opened this issue Jan 11, 2025 · 0 comments

Comments

@darac
Copy link

darac commented Jan 11, 2025

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.

@darac darac changed the title Possibilitty to escape %{} sequences? Possibility to escape %{} sequences? Jan 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant