zsh-users
 help / color / mirror / code / Atom feed
* Constantly updated clock in prompt
@ 2013-12-10  6:10 Samuel Laverdière
  2013-12-10  7:03 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Samuel Laverdière @ 2013-12-10  6:10 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 623 bytes --]

I found a way to update the time in my prompt, but it breaks the completion
menu (items in the menu become invisible). I found the solution on the
Internet, so I know other people are looking for the same thing (updated
time in prompt), but I can't believe they all learn to live with the bugs I
have to deal with. Does it happen to anyone else? Is there a way to avoid
it?

I use something like this:
RPROMPT="%{$fg_bold[blue]%}%n@%M, %D %T%{$reset_color%}"
TMOUT=1
TRAPALRM() { zle reset-prompt }

More details here:
http://stackoverflow.com/questions/20231533/constantly-updated-clock-in-zsh-prompt-without-any-drawback

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Constantly updated clock in prompt
  2013-12-10  6:10 Constantly updated clock in prompt Samuel Laverdière
@ 2013-12-10  7:03 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2013-12-10  7:03 UTC (permalink / raw)
  To: zsh-users

On Dec 10,  1:10am, Samuel Laverdière wrote:
} 
} I found a way to update the time in my prompt, but it breaks the completion
} menu (items in the menu become invisible). I found the solution on the
} Internet, so I know other people are looking for the same thing (updated
} time in prompt), but I can't believe they all learn to live with the bugs I
} have to deal with. Does it happen to anyone else? Is there a way to avoid
} it?

The menu-select widget isn't prepared to have its display interrupted by
reset-prompt (menu-select is in the separate zsh/complist module, and
IIRC reset-prompt was added after that module was written).

I keep the time in the window title bar instead of the prompt, and update
it with

	print -nP "%{$top${*:-%m.%l:%2c - %t}$back%}"

(where $top and $back are the terminal-specific control codes update the
title bar).

You could easily do this with, say, the upper right corner of the screen
instead of the title bar.

(In more detail, I update the title bar in my precmd hook, and set the
initial TMOUT to 10 minutes so the title bar only starts updating itself
when I've been idle for a while.)

Other suggestions:

Create TRAPALRM before you assign TMOUT, or you're asking for a race to
occur where the signal arrives before it is trapped.

If you're only tracking time to the minute (%T), use TMOUT=10 so there
are fewer interrupts.  Or to be really minimalist:

    zmodload zsh/datetime
    TRAPALARM() {
      print -nP "%{$top${*:-%m.%l:%2c - %t}$back%}"	# or whatever
      TMOUT=$(( EPOCHSECONDS % 60 ))
    }
    TRAPALRM

One wakeup per minute, exactly on the minute!


Aside for zsh-workers:

With

    TRAPALRM() { zle reset-prompt; zle redisplay }

(or pretty much any zle thing after reset-prompt) I get:

    Src/Zle/zle_thingy.c:660: line metafied

However, that does NOT happen if I do

    TRAPALRM() { zle -I; zle reset-prompt; zle redisplay }

Whatever that bug is, has no effect on the menu-select redraw problem.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-12-10  7:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-10  6:10 Constantly updated clock in prompt Samuel Laverdière
2013-12-10  7:03 ` Bart Schaefer

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).