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

tcsh rprompt doesn't clear colors at the end of the string #18

Open
daveola opened this issue Nov 26, 2019 · 4 comments
Open

tcsh rprompt doesn't clear colors at the end of the string #18

daveola opened this issue Nov 26, 2019 · 4 comments

Comments

@daveola
Copy link

daveola commented Nov 26, 2019

I am experimenting with colors in tcsh prompts, and I use a prompt and rprompt.

I'm able to add colors to the prompt (and then turn off the color formatting fine), but when I add colors to the rprompt, I am unable to turn off the formatting.

As an example, for red:

%{\033[1;31m%}     turn on red
%{\033[0m%}        turn off formatting

So I tried these simple prompt settings:

set prompt="prompt> "
set rprompt="%{\033[1;31m%} rprompt %{\033[0m%}"

And it turns everything red, including what I type and all my command results.

On the other hand, if you add any characters after the clear formatting codes, then the colors work as expected:

set rprompt="%{\033[1;31m%} rprompt %{\033[0m%} "

(Note the extra space)

This happens on multiple terminal types - is this a tcsh bug?

@zoulasc
Copy link
Member

zoulasc commented Nov 26, 2019

This is a mis-feature because the attribute is attached to the next character after the attribute specifier. The same happens for the regular prompt. Perhaps there should be special NUL attributed character that just sets the attribute and does not print the character, followed by a regular NUL terminator.

@daveola
Copy link
Author

daveola commented Nov 27, 2019

So by mis-feature you mean that this is a terminal issue and there's nothing that can be done about it? Is there not a zero-width character that I can place after?

@suominen
Copy link
Member

There is a zero-width space in UTF-8, but it won't help, as the code doesn't understand it being zero-width, so the rprompt is displayed one column too early. Thus it visually looks the same as if you used a normal space at its end.

Getting the zero-width space into rprompt was an exercise in quoting (once again):

> perl -CO -e'print "set rprompt='"'"'%{\\033[1;31m%} rprompt%{\\033[0m%}\x{200b}'"'"'\n"' | vis
set rprompt='%{\134033[1;31m%} rprompt%{\134033[0m%}\M-b\M^@\M^K'

I saved that to a file to source it:

> perl -CO -e'print "set rprompt='"'"'%{\\033[1;31m%} rprompt%{\\033[0m%}\x{200b}'"'"'\n"' > rprompt.csh
> source rprompt.csh

By the way, vi(1) will not work correctly with that file, either, as it doesn't understand the zero-widthness of the zero-width space. So it e.g. $ places you one column too far (into "nothing"). Having the zero width space on the screen also confused screen(1) and/or mosh(1) so that some lines were stuck on the terminal display...

But taking your example:

set rprompt="%{\033[1;31m%} rprompt %{\033[0m%}"

You could just move the space preceding the colour code to be after it:

set rprompt="%{\033[1;31m%} rprompt%{\033[0m%} " 

This would effectively give you the same appearance on screen, wouldn't it?

The tcsh(1) manual page does document the fact that a literal escape sequence cannot be the last sequence in a prompt.

@daveola
Copy link
Author

daveola commented Nov 17, 2021

Thanks for the ideas.

I tried the zero-width space and, at least on my terminal (xterm-256color) it still left my color stuck at red.

And yes, there was a space after "rprompt" in my example, but that was for readability. I want the "rprompt" to be fully right-justified, so having that space after the color is admittedly a fix for my example, but doesn't actually solve the problem.

On top of that I just realized that there seems to be an additional space added after rprompt regardless. I.e., if I have 80 columns, then the last character of even just a simple "set rprompt='hi'" will actually be at col 79, which doesn't make sense to me and is not consistent with the "left" prompt. So now I've got two spaces to deal with.. :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants