Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[zsh] problem with my prompt
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
avx
Advocate
Advocate


Joined: 21 Jun 2004
Posts: 2152

PostPosted: Fri Jul 16, 2010 9:26 pm    Post subject: [zsh] problem with my prompt Reply with quote

While playing with my new prompt, I stumbled over a problem and I'm not really sure what exactly the matter is, so I'd be glad, if someone could have a look over it and tell me what the problem is.

prompt:
Code:
PS1=$'\e[1A\e[s\e[H\e[30;42;1m\e[K[%~][%M] \e[199C\e[8D\e[30;42;1m [%T]%(?,\e[32;32█,\e[31;41;1m█)\e[0m\e[u\n\e[32;40;0m>\e[0m '

reproduce: type 'rm<tab>'

thanks.

Edit, if someone has an idea, how to put this prompt always as the last line(like i.e. screen's hardstatus), I'd like to know that, too.
Back to top
View user's profile Send private message
username234
Guru
Guru


Joined: 09 May 2007
Posts: 332

PostPosted: Sat Jul 17, 2010 7:23 am    Post subject: Re: [zsh] problem with my prompt Reply with quote

avx wrote:
While playing with my new prompt, I stumbled over a problem and I'm not really sure what exactly the matter is, so I'd be glad, if someone could have a look over it and tell me what the problem is.

prompt:
Code:
PS1=$'\e[1A\e[s\e[H\e[30;42;1m\e[K[%~][%M] \e[199C\e[8D\e[30;42;1m [%T]%(?,\e[32;32█,\e[31;41;1m█)\e[0m\e[u\n\e[32;40;0m>\e[0m '

reproduce: type 'rm<tab>'

thanks.

Edit, if someone has an idea, how to put this prompt always as the last line(like i.e. screen's hardstatus), I'd like to know that, too.
zsh calculates where to put the cursor based on the number of characters (and meta-characters) in the prompt. Or put simply, it's counting the escape sequences in their entirety. The way you remedy this is to wrap the escape sequences in a '%{%}'. An example of your prompt with the proper escaping is given below:
Code:
PS1=$'%{\e[30;42;1m%}[%~][%M] %{\e[K\e[199C\e[8D\e[30;42;1m%} [%T]%(?,%{\e[32;32m%}, %{\e[31;41;1m%})%{\e[0m%}\n%{\e[0;32;40m%}>%{\e[0m%} '
However, I really suspect this isn't the best way to do this type of prompt. I recommend reading: http://aperiodic.net/phil/prompt/
_________________
Creating usernames when you're
in a creative slump is a bad idea
because if you are when you do
then you end up with uninspiring
alphanumeric cocktails like the
one directly above.
Back to top
View user's profile Send private message
avx
Advocate
Advocate


Joined: 21 Jun 2004
Posts: 2152

PostPosted: Sat Jul 17, 2010 1:46 pm    Post subject: Reply with quote

Quote:
An example of your prompt with the proper escaping is given below:
Thanks, that's working :)
Quote:
However, I really suspect this isn't the best way to do this type of prompt. I recommend reading
Maybe you can give a hint, on what exactly you mean? I know this page, but don't understand what specific points your talking about here. Do you mean stuff related to positioning and i.e. $COLUMNS or something else?

BTW, is there a way to use the $fg[something]-thingy's in this prompt, since it seems the $' is required, but than obviously the $something don't get expanded and the \e... notation of colors is a little clumsy.
Back to top
View user's profile Send private message
username234
Guru
Guru


Joined: 09 May 2007
Posts: 332

PostPosted: Sat Jul 17, 2010 2:42 pm    Post subject: Reply with quote

avx wrote:
Quote:
An example of your prompt with the proper escaping is given below:
Thanks, that's working :)
Quote:
However, I really suspect this isn't the best way to do this type of prompt. I recommend reading
Maybe you can give a hint, on what exactly you mean? I know this page, but don't understand what specific points your talking about here. Do you mean stuff related to positioning and i.e. $COLUMNS or something else?
Mainly your cursor positioning. While you seem to set it very wide (199 characters?) I can't help but think that on a large enough monitor you'd have to constantly recalculate that length based on your window. The link I provided, of course, gets around this by recomputing the size of the window at every prompt.
avx wrote:
BTW, is there a way to use the $fg[something]-thingy's in this prompt, since it seems the $' is required, but than obviously the $something don't get expanded and the \e... notation of colors is a little clumsy.
Doesn't appear to be a different way to specify colors in the prompt, but maybe I'm just missing something.
_________________
Creating usernames when you're
in a creative slump is a bad idea
because if you are when you do
then you end up with uninspiring
alphanumeric cocktails like the
one directly above.
Back to top
View user's profile Send private message
avx
Advocate
Advocate


Joined: 21 Jun 2004
Posts: 2152

PostPosted: Sat Jul 17, 2010 7:44 pm    Post subject: Reply with quote

Mh, just played a little and it seems, that while your modified version of my prompt fixes the problem, it introduces another. The green-bar doesn't stay always on the first line, but always comes right before the prompt. Strange.
Edit, it also kills the true/false thingy :(

Regarding your input, my question would be, how do I pack the needed info about term-width into the prompt, when $' is needed, but this also disallows variables to be expanded? Either I'm blind, too stupid or phil's prompt ain't too helpfull for that.
Back to top
View user's profile Send private message
username234
Guru
Guru


Joined: 09 May 2007
Posts: 332

PostPosted: Sun Jul 18, 2010 12:28 am    Post subject: Reply with quote

avx wrote:
Mh, just played a little and it seems, that while your modified version of my prompt fixes the problem, it introduces another. The green-bar doesn't stay always on the first line, but always comes right before the prompt. Strange.
Edit, it also kills the true/false thingy :(
oh oops. I can fix that.
avx wrote:
Regarding your input, my question would be, how do I pack the needed info about term-width into the prompt, when $' is needed, but this also disallows variables to be expanded? Either I'm blind, too stupid or phil's prompt ain't too helpfull for that.
He uses the precmd() function to build his prompt to pull this off. The precmd() is executed everytime the prompt is redrawn. He also uses some different techniques to expand the prompt, I don't fully understand it, but then again shell scripting isn't exactly my strong suit.
_________________
Creating usernames when you're
in a creative slump is a bad idea
because if you are when you do
then you end up with uninspiring
alphanumeric cocktails like the
one directly above.
Back to top
View user's profile Send private message
username234
Guru
Guru


Joined: 09 May 2007
Posts: 332

PostPosted: Sun Jul 18, 2010 2:33 am    Post subject: Reply with quote

Okay here's my latest attempt. I'm not 100% sure what symbol(s) you were using for your true/false mechanism, so I've replaced it with 'G' and 'B'. Feel free to change them back.

Code:
PS1=$'%{\e[s\e[H\e[30;42;1m%}[%~][%M] %{\e[K\e[199C\e[8D\e[30;42;1m%} [%T]%(?,%{\e[32;32m%}G,%{\e[31;41;1mB)%}%{\e[u\e[1A%}\n%{\e[0;32m%}> %{\e[0m%}'

_________________
Creating usernames when you're
in a creative slump is a bad idea
because if you are when you do
then you end up with uninspiring
alphanumeric cocktails like the
one directly above.
Back to top
View user's profile Send private message
avx
Advocate
Advocate


Joined: 21 Jun 2004
Posts: 2152

PostPosted: Sun Jul 18, 2010 11:54 am    Post subject: Reply with quote

That's working good, thanks again :)

For my used characters, they're from the box-drawing characters, so if a command exits with true/0, the bar stays completely green, if it returns false/1, the last part of the bar turns red.

Gotta have a look at the precmd-stuff tonight, so far, thank you very much :)
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum