* Colours leaking from RPROMPT
@ 2014-03-19 10:50 David Banks
2014-03-19 22:34 ` Bart Schaefer
0 siblings, 1 reply; 3+ messages in thread
From: David Banks @ 2014-03-19 10:50 UTC (permalink / raw)
To: zsh-users
Hi list,
I adapted a right-hand-side prompt for showing the run time of the
last command. Code looks like this:
function preexec() {
timer=${timer:-$(date "+%s.%N")}
}
function precmd() {
if [ -n "$timer" ]; then
new_timer=$(date "+%s.%N")
timer_accurate=$(printf "scale=2; %s - %s\n" "$new_timer"
"$timer" | bc)
timer_show=$(printf "%.2f" "$timer_accurate")
RPROMPT="%F{cyan}${timer_show}s %{$reset_color%}"
unset timer
fi
}
I see some strange colour behaviour when using completions, though.
For instance, when I complete something with more than one possible
match, the completion menu is all coloured cyan. And once I accept
one of the options from the completion menu, the unique substring that
was completed remains coloured cyan in the command string. There are
also a couple of other odd behaviours that are not so easy to trigger.
The value of PS1 is '%n@%{%}%m%{%} %(!.#.$) '.
What would be the cause of this? As far as I can see, the colour
should always be reset after the prompt string is printed, so it
should never show outside the prompt.
Thanks!
Dave
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Colours leaking from RPROMPT
2014-03-19 10:50 Colours leaking from RPROMPT David Banks
@ 2014-03-19 22:34 ` Bart Schaefer
2014-03-20 14:53 ` David Banks
0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2014-03-19 22:34 UTC (permalink / raw)
To: zsh-users
On Mar 19, 10:50am, David Banks wrote:
}
} RPROMPT="%F{cyan}${timer_show}s %{$reset_color%}"
Are you sure $reset_color is defined? You need to autoload and run
the "colors" function to initialize $reset_color.
However, you shouldn't need $reset_color at all ... you should use:
RPROMPT="%F{cyan}${timer_show}s %f"
You might also want to look at the zsh/datetime module and $EPOCHREALTIME
instead of doing all that "date" and "bc" stuff.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Colours leaking from RPROMPT
2014-03-19 22:34 ` Bart Schaefer
@ 2014-03-20 14:53 ` David Banks
0 siblings, 0 replies; 3+ messages in thread
From: David Banks @ 2014-03-20 14:53 UTC (permalink / raw)
To: zsh-users
On 19 March 2014 22:34, Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Mar 19, 10:50am, David Banks wrote:
> }
> } RPROMPT="%F{cyan}${timer_show}s %{$reset_color%}"
>
> Are you sure $reset_color is defined? You need to autoload and run
> the "colors" function to initialize $reset_color.
printf "%s" "$reset_color" | wc -c
=> 5
> However, you shouldn't need $reset_color at all ... you should use:
>
> RPROMPT="%F{cyan}${timer_show}s %f"
That fixed it, thanks!
> You might also want to look at the zsh/datetime module and $EPOCHREALTIME
> instead of doing all that "date" and "bc" stuff.
Great, I will check these out.
Cheers!
Dave
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-03-20 14:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-19 10:50 Colours leaking from RPROMPT David Banks
2014-03-19 22:34 ` Bart Schaefer
2014-03-20 14:53 ` David Banks
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).