zsh-users
 help / color / mirror / code / Atom feed
* Disabling prompt refresh
@ 2017-02-13 14:31 Jesper Nygårds
  2017-02-13 17:54 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Jesper Nygårds @ 2017-02-13 14:31 UTC (permalink / raw)
  To: Zsh Users

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

I have the following function, written by Peter years ago, in my .zshrc:

schedprompt() {
    emulate -L zsh
    zmodload -i zsh/sched

    integer i=${"${(@)zsh_scheduled_events#*:*:}"[(I)schedprompt]}
    (( i )) && sched -$i

    zle && zle reset-prompt

    sched +30 schedprompt
}

It refreshes the prompt every 30 seconds, which is very nice.

I also have the following little widget, which displays the current dir
stack below the command line:

_show_dirs() {
    zle -M "$(dirs -vl)"
}

However, the schedprompt-function makes the output from "zle -M" disappear,
so that sometimes when I have used the widget to display the dir stack, it
disappears because of the refresh.

Is there a way to either disable the prompt refresh while the message is
displayed, or, alternatively, to redisplay the message after a prompt
refresh?

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

* Re: Disabling prompt refresh
  2017-02-13 14:31 Disabling prompt refresh Jesper Nygårds
@ 2017-02-13 17:54 ` Bart Schaefer
  2017-02-14  7:20   ` Jesper Nygårds
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2017-02-13 17:54 UTC (permalink / raw)
  To: Zsh Users

On Feb 13,  3:31pm, Jesper Nygards wrote:
}
} Is there a way to either disable the prompt refresh while the message is
} displayed, or, alternatively, to redisplay the message after a prompt
} refresh?

The simplest approach might be to not use "zle -M" at all:

  _show_dirs() {
    POSTDISPLAY=$'\n'"${$(dirs -vl)//$'\t'/  }" 
  }

To answer your question, though -- you would need to have the functions
coordinate somehow, e.g.:

  typeset -gH _prompt_message
  _show_dirs() {
    _prompt_message="${$(dirs -vl)//$'\t'/  }"
    zle -M "_prompt_message"
  }
  schedprompt() {
    emulate -L zsh
    zmodload -i zsh/sched

    integer i=${"${(@)zsh_scheduled_events#*:*:}"[(I)schedprompt]}
    (( i )) && sched -$i

    zle && zle reset-prompt &&
    [[ -n $_prompt_message ]] && zle -M "$_prompt_message"

    sched +30 schedprompt
  }
  clear-prompt-message() {
    _prompt_message=
  }
  autoload add-zsh-hook
  add-zsh-hook precmd clear-prompt-message

(I'm guessing schedprompt is also a precmd hook but didn't want to assume.)

You could instead in schedprompt do

    [[ -z $_prompt_message ]] && zle && zle reset-prompt

to disable the redraw.


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

* Re: Disabling prompt refresh
  2017-02-13 17:54 ` Bart Schaefer
@ 2017-02-14  7:20   ` Jesper Nygårds
  0 siblings, 0 replies; 3+ messages in thread
From: Jesper Nygårds @ 2017-02-14  7:20 UTC (permalink / raw)
  To: Zsh Users

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

This is perfect for my needs. Thank you, Bart.


On Mon, Feb 13, 2017 at 6:54 PM, Bart Schaefer <schaefer@brasslantern.com>
wrote:

> On Feb 13,  3:31pm, Jesper Nygards wrote:
> }
> } Is there a way to either disable the prompt refresh while the message is
> } displayed, or, alternatively, to redisplay the message after a prompt
> } refresh?
>
> The simplest approach might be to not use "zle -M" at all:
>
>   _show_dirs() {
>     POSTDISPLAY=$'\n'"${$(dirs -vl)//$'\t'/  }"
>   }
>
> To answer your question, though -- you would need to have the functions
> coordinate somehow, e.g.:
>
>   typeset -gH _prompt_message
>   _show_dirs() {
>     _prompt_message="${$(dirs -vl)//$'\t'/  }"
>     zle -M "_prompt_message"
>   }
>   schedprompt() {
>     emulate -L zsh
>     zmodload -i zsh/sched
>
>     integer i=${"${(@)zsh_scheduled_events#*:*:}"[(I)schedprompt]}
>     (( i )) && sched -$i
>
>     zle && zle reset-prompt &&
>     [[ -n $_prompt_message ]] && zle -M "$_prompt_message"
>
>     sched +30 schedprompt
>   }
>   clear-prompt-message() {
>     _prompt_message=
>   }
>   autoload add-zsh-hook
>   add-zsh-hook precmd clear-prompt-message
>
> (I'm guessing schedprompt is also a precmd hook but didn't want to assume.)
>
> You could instead in schedprompt do
>
>     [[ -z $_prompt_message ]] && zle && zle reset-prompt
>
> to disable the redraw.
>

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

end of thread, other threads:[~2017-02-14  7:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-13 14:31 Disabling prompt refresh Jesper Nygårds
2017-02-13 17:54 ` Bart Schaefer
2017-02-14  7:20   ` Jesper Nygårds

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