How to pipe colored output to vim and show it correctly?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

How to pipe colored output to vim and show it correctly?

Peng Yu
Hi

I have the following alias which works fine when uncolored input.

~/linux/test/gnu/ack-grep/--color$ alias less
alias less='vim -R -'

~/linux/test/gnu/ack-grep/--color$ cat.sh *.txt
==> test1.txt <==
ABC

==> test2.txt <==
AXY
~/linux/test/gnu/ack-grep/--color$ printf "%s\n" *.txt|ack --color -x A
test1.txt
1:ABC

test2.txt
1:AXY

But when the input is colored,
~/linux/test/gnu/ack-grep/--color$ printf "%s\n" *.txt|ack --color -x A|less

I see the following in vim. Does anybody know how to make the correct
alias of less that it works for both colored cases and uncolored
cases? Thanks.

  1 ^[[1;32mtest1.txt^[[0m:^[[1;33m1^[[0m:^[[30;43mA^[[0mBC^[[0m^[[K
  2 ^[[1;32mtest2.txt^[[0m:^[[1;33m1^[[0m:^[[30;43mA^[[0mXY^[[0m^[[K

--
Regards,
Peng

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: How to pipe colored output to vim and show it correctly?

Gabriele Lana
On Nov 23, 2013, at 6:07 PM, Peng Yu <[hidden email]> wrote:

> Hi
>
> I have the following alias which works fine when uncolored input.
>
> ~/linux/test/gnu/ack-grep/--color$ alias less
> alias less='vim -R -'
>

> […]
>
>  1 ^[[1;32mtest1.txt^[[0m:^[[1;33m1^[[0m:^[[30;43mA^[[0mBC^[[0m^[[K
>  2 ^[[1;32mtest2.txt^[[0m:^[[1;33m1^[[0m:^[[30;43mA^[[0mXY^[[0m^[[K


I'm unable to reproduce your problem, seems like whenever I pipe something in my shell the ansi escapes are stripped… maybe one of the zsh magic tricks? I don't know

Anyway, something like

alias less='sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" | vim -R -'

should work (not tested)

--
Gabriele Lana
contact me at gabrielelana at cleancode dot it
http://www.cleancode.it - what we do and what we believe in
http://www.gabrielelana.it - agile methodologies and programming

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: How to pipe colored output to vim and show it correctly?

Peng Yu
Something like 'grep --color' (although it produces colored output)
won't cause the problem. You have to use ack. Did you use ack?

~$ ack --version
ack 2.02
Running under Perl 5.14.2 at /usr/local/ActivePerl-5.14/bin/perl

Copyright 2005-2013 Andy Lester.

This program is free software.  You may modify or distribute it
under the terms of the Artistic License v2.0.

On Sat, Nov 23, 2013 at 11:29 AM, Gabriele Lana <[hidden email]> wrote:

> On Nov 23, 2013, at 6:07 PM, Peng Yu <[hidden email]> wrote:
>
>> Hi
>>
>> I have the following alias which works fine when uncolored input.
>>
>> ~/linux/test/gnu/ack-grep/--color$ alias less
>> alias less='vim -R -'
>>
>
>> […]
>>
>>  1 ^[[1;32mtest1.txt^[[0m:^[[1;33m1^[[0m:^[[30;43mA^[[0mBC^[[0m^[[K
>>  2 ^[[1;32mtest2.txt^[[0m:^[[1;33m1^[[0m:^[[30;43mA^[[0mXY^[[0m^[[K
>
>
> I'm unable to reproduce your problem, seems like whenever I pipe something in my shell the ansi escapes are stripped… maybe one of the zsh magic tricks? I don't know
>
> Anyway, something like
>
> alias less='sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" | vim -R -'
>
> should work (not tested)
>
> --
> Gabriele Lana
> contact me at gabrielelana at cleancode dot it
> http://www.cleancode.it - what we do and what we believe in
> http://www.gabrielelana.it - agile methodologies and programming
>
> --
> --
> You received this message from the "vim_use" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
> ---
> You received this message because you are subscribed to a topic in the Google Groups "vim_use" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/vim_use/Ba1SfjC7J-M/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to [hidden email].
> For more options, visit https://groups.google.com/groups/opt_out.



--
Regards,
Peng

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: How to pipe colored output to vim and show it correctly?

Gabriele Lana

On Nov 23, 2013, at 6:43 PM, Peng Yu <[hidden email]> wrote:

> Something like 'grep --color' (although it produces colored output)
> won't cause the problem. You have to use ack. Did you use ack?


You are right sorry, now I'm able to confirm that

alias less='sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" | vim -R -'

Works like a charm :-)

--
Gabriele Lana
contact me at gabrielelana at cleancode dot it
http://www.cleancode.it - what we do and what we believe in
http://www.gabrielelana.it - agile methodologies and programming

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: How to pipe colored output to vim and show it correctly?

Nikolay Aleksandrovich Pavlov
In reply to this post by Peng Yu


On Nov 23, 2013 9:43 PM, "Peng Yu" <[hidden email]> wrote:
>
> Something like 'grep --color' (although it produces colored output)
> won't cause the problem. You have to use ack. Did you use ack?

It will. Just make sure you use 'grep --color=always'. By default 'grep --color=auto' is used which will not cause problems.

> ~$ ack --version
> ack 2.02
> Running under Perl 5.14.2 at /usr/local/ActivePerl-5.14/bin/perl
>
> Copyright 2005-2013 Andy Lester.
>
> This program is free software.  You may modify or distribute it
> under the terms of the Artistic License v2.0.
>
> On Sat, Nov 23, 2013 at 11:29 AM, Gabriele Lana <[hidden email]> wrote:
> > On Nov 23, 2013, at 6:07 PM, Peng Yu <[hidden email]> wrote:
> >
> >> Hi
> >>
> >> I have the following alias which works fine when uncolored input.
> >>
> >> ~/linux/test/gnu/ack-grep/--color$ alias less
> >> alias less='vim -R -'
> >>
> >
> >> […]
> >>
> >>  1 ^[[1;32mtest1.txt^[[0m:^[[1;33m1^[[0m:^[[30;43mA^[[0mBC^[[0m^[[K
> >>  2 ^[[1;32mtest2.txt^[[0m:^[[1;33m1^[[0m:^[[30;43mA^[[0mXY^[[0m^[[K
> >
> >
> > I'm unable to reproduce your problem, seems like whenever I pipe something in my shell the ansi escapes are stripped… maybe one of the zsh magic tricks? I don't know
> >
> > Anyway, something like
> >
> > alias less='sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" | vim -R -'
> >
> > should work (not tested)
> >
> > --
> > Gabriele Lana
> > contact me at gabrielelana at cleancode dot it
> > http://www.cleancode.it - what we do and what we believe in
> > http://www.gabrielelana.it - agile methodologies and programming
> >
> > --
> > --
> > You received this message from the "vim_use" maillist.
> > Do not top-post! Type your reply below the text you are replying to.
> > For more information, visit http://www.vim.org/maillist.php
> >
> > ---
> > You received this message because you are subscribed to a topic in the Google Groups "vim_use" group.
> > To unsubscribe from this topic, visit https://groups.google.com/d/topic/vim_use/Ba1SfjC7J-M/unsubscribe.
> > To unsubscribe from this group and all its topics, send an email to [hidden email].
> > For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
> --
> Regards,
> Peng
>
> --
> --
> You received this message from the "vim_use" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
> ---
> You received this message because you are subscribed to the Google Groups "vim_use" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
> For more options, visit https://groups.google.com/groups/opt_out.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
 
---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: How to pipe colored output to vim and show it correctly?

Nikolay Aleksandrovich Pavlov
In reply to this post by Peng Yu


On Nov 23, 2013 9:07 PM, "Peng Yu" <[hidden email]> wrote:
>
> Hi
>
> I have the following alias which works fine when uncolored input.
>
> ~/linux/test/gnu/ack-grep/--color$ alias less
> alias less='vim -R -'
>
> ~/linux/test/gnu/ack-grep/--color$ cat.sh *.txt
> ==> test1.txt <==
> ABC
>
> ==> test2.txt <==
> AXY
> ~/linux/test/gnu/ack-grep/--color$ printf "%s\n" *.txt|ack --color -x A
> test1.txt
> 1:ABC
>
> test2.txt
> 1:AXY
>
> But when the input is colored,
> ~/linux/test/gnu/ack-grep/--color$ printf "%s\n" *.txt|ack --color -x A|less
>
> I see the following in vim. Does anybody know how to make the correct
> alias of less that it works for both colored cases and uncolored
> cases? Thanks.
>
>   1 ^[[1;32mtest1.txt^[[0m:^[[1;33m1^[[0m:^[[30;43mA^[[0mBC^[[0m^[[K
>   2 ^[[1;32mtest2.txt^[[0m:^[[1;33m1^[[0m:^[[30;43mA^[[0mXY^[[0m^[[K

There is :AnsiEsc command provided by vimscript #302. It will make this output colored in vim, hiding (assuming vim was compiled with +conceal) or removing this sequences. It will disable other highlighting though if you use any with this buffer.

> --
> Regards,
> Peng
>
> --
> --
> You received this message from the "vim_use" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
> ---
> You received this message because you are subscribed to the Google Groups "vim_use" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
> For more options, visit https://groups.google.com/groups/opt_out.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
 
---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.