Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

Conceal ANSI escape codes and colour text #65

Open
fcying opened this issue Jul 22, 2020 · 7 comments
Open

Conceal ANSI escape codes and colour text #65

fcying opened this issue Jul 22, 2020 · 7 comments
Labels
enhancement New feature or request

Comments

@fcying
Copy link

fcying commented Jul 22, 2020

I try to use Hexokinase_palettes to set up ansi color, but not success.
Can you help me see how to set this situation?

text:

\e[00;32m2020-07-22 22:46:19.260\e[00;34m TEST\e[0m end

display in term:

print "\e[00;32m2020-07-22 22:46:19.260\e[00;34m TEST\e[0m end"

image

color flag is \e[, 00;32m is color name, text after this flag add color(not display color flag), \e[0m stop add color, or another color flag change the next text color \e[00;34m

@fcying fcying changed the title [question] How do I set up for ansi color by useing Hexokinase_palettes? [question] How do I set up for ansi escape code by useing Hexokinase_palettes? Jul 22, 2020
@RRethy
Copy link
Owner

RRethy commented Jul 26, 2020

I'm not sure I understand. So you have a text file with the following text:

\e[00;32m2020-07-22 22:46:19.260\e[00;34m TEST\e[0m end

And you want it to be highlighted as something along the lines of this:

image

Is this the behaviour you are looking for?

@fcying
Copy link
Author

fcying commented Jul 27, 2020

I want it to be highlighted like this:
image

\e[00;32m \e[00;34m \e[0m is Escape sequences, it only set text color which after it, it does not show itself.

More explanation:
ANSI_escape_code#Colors

@noscript
Copy link

noscript commented Jul 27, 2020

+1 Very useful for coloring the output inside quickfix window.

This is somehow similar to html tags. The codes may appear in any order, these will produce the same output:

$ echo -en \
'\n^[[1m^[[34mTEST^[[0m' \
'\n^[[34m^[[1mTEST^[[0m' \
'\n^[[1;34mTEST^[[0m'

2020 07 27_12:05:37

@RRethy RRethy added the enhancement New feature or request label Jul 27, 2020
@RRethy
Copy link
Owner

RRethy commented Jul 27, 2020

I want it to be highlighted like this:
image

\e[00;32m \e[00;34m \e[0m is Escape sequences, it only set text color which after it, it does not show itself.

More explanation:
ANSI_escape_code#Colors

If you are looking for the text to change (\e[00;32m to disappear, as in your screenshot and how a terminal displays it), then vim-hexokinase does not have this functionality currently since that would require use of :h :syn-conceal. I'll mark this as a feature request and I may get to it, but to be honest I avoided adding any :h :syn-conceal highlighters because the conceal api is quite painful to deal with.

If someone wants to try adding this functionality you can do so by extending https://github.com/rrethy/hexokinase and adding the ability to recognize ansi escapes codes, then you would add a highlighter based on :h hexokinase-custom-highlighters.

Alternatively, Colorizer has this functionality.

@RRethy RRethy changed the title [question] How do I set up for ansi escape code by useing Hexokinase_palettes? Conceal ANSI escape codes and colour text Jul 27, 2020
@noscript
Copy link

At least highlighting would be nice to have, concealing may not be so important.

@Olical
Copy link

Olical commented Sep 9, 2020

This would be a REALLY nice solution to Olical/conjure#53 - I think I hacked colorizer or something to get it to do what I wanted, I think this plugin could be a massive improvement on that!

(conjure introduces a log that's kind of like a REPL and CAN contain ansi escape sequences, so having them displayed correctly is a really nice experience)

In my experience, AnsiEsc works but had a bunch of weird quirks, like it would break the rest of the syntax highlighting and vanish when you switched windows sometimes. I hacked it to get it to overlay the escape code colouring on top of my existing theme, you can find that hacked version here, maybe people can just use that: https://github.com/Olical/AnsiEsc

I think colorizer had a bunch of issues too, see the issue I linked for more info on the state of colouring and hiding ansi escape sequences in nvim.

@vizcay
Copy link

vizcay commented Jan 5, 2021

This will be very nice to have, In my case only https://github.com/chrisbra/Colorizer supported this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants