rcmdnk / sentaku

Utility to make sentaku (selection, 選択(sentaku)) window with shell command.
http://rcmdnk.github.io/blog/2014/01/24/computer-bash-zsh/
MIT License
140 stars 6 forks source link

text coloring wretches selected line #7

Closed Arnaudv6 closed 8 years ago

Arnaudv6 commented 8 years ago

I ran into this in the morning. It is more of a glitch than a bug:

echo "amaury" | grep --color=always -i "a" | sentaku | xargs echo

sentaku will work as expected when piped colored input. And coloring passes through, which is sane behavior IMO. But some colored text ends the inverted background of selected line, which can be a pity for long lists of long lines. Thanks for your awesome support, I am glad you make it a lively project.

xrat commented 8 years ago

I think @rcmdnk will not be able to fix this due to how sentaku works. Maybe you want to use a different approach like

echo "amaury" | grep -i "a" | sentaku | grep --color=always -i "a" | xargs echo
Arnaudv6 commented 8 years ago

Thanks, then I will work with the glitch.

...Some coloring works well in sentaku. Could sentaku replace not working colors with working ones and work with them ?

As a user I would understand all coloring gets ditched in output, but I like to pipe colored text, and I guess there are cases you don't have a choice.

rcmdnk commented 8 years ago

I added an option SENTAKU_COLOR_NUM_ONLY. If you set:

export SENTAKU_COLOR_NUM_ONLY=1

then, only numbers are highlighted instead of entire line. If you want to use it temporary, use like:

echo "amaury" | grep --color=always -i "a" | SENTAKU_COLOR_NUM_ONLY=1 sentaku | xargs echo

In addition, if the line includes escape characters (^[), then only the number is highlighted for that line. So, for above example, you don't need to change anything but only the number is highlithed for amaury.

It is implemented in v0.4.9. I hope it suits for your usage.

Arnaudv6 commented 8 years ago

Thanks, but not really: I actually use -N flag to hide numbers. I would turn it back on, I would: I try not to be stuborn, but then again, having just the number highlighted is not convenient when options are long, quite identical lines: we don't really see which line is selected.

rcmdnk commented 8 years ago

ok, I updated to v0.5.0.

It can highlight entire line even if the line includes colors. I think it can satisfy your need.

In addition, I added -U option, which changes highlighting from negative image to underline. It can be set by environmental variable: SENTAKU_LINE_HIGHLIGHT=0 (default is 1).

FYI. there is a command s at selection view, which shows full words of current line temporary. It would be useful if you are using for very long line.

Arnaudv6 commented 8 years ago

Wow, thanks: I'm impressed and grateful. Sentaku works perfectly for my use !

I went through the patch meaning to understand it but I managed not... It seems to me that when fed with colored input, sentaku highlights a certain number of character. At home, this number is big enough to cover all my lines, but not so big that it reached terminal's border. I think If you make it twice as long, you will cover every screen-size and font-size out there.

I mark it resolved anyway, and again, thanks.

xrat commented 8 years ago

I am afraid there's a regression of some sort, that introduced ":" in case of -N: Running echo a b | _SENTAKU_NOHEADER=1 sentaku -N shows with version 0.4.6

2 values in total             

a                                                                               
b

but version 0.5.1 shows

2 values in total             

: a                                                                               
: b
rcmdnk commented 8 years ago

@Arnaudv6 The problem was that it needs to use exact number of characters in the line as terminal width, and character counting includes these characters for colored, but not shown. I thought it is a bit messy and left as is, but I could fix it.

Note: Normally "color" character is like \e[31ma\e[m, but somehow grep --color=always -i "a"'s result contains \e[31m\e[Ka\e[m\e[K. I don't know what is this \e[K and how it works, but currently I just remove it from counting (that is enough).

@xrat Thanks for finding it. It is actually bug that I didn't take into account no number mode. Now it is fixed.

Both fixes are in v0.5.2.

Arnaudv6 commented 8 years ago

I enjoy your software (and your work/support), I really do.