zsh-users
 help / color / mirror / code / Atom feed
From: Sebastian Gniazdowski <sgniazdowski@gmail.com>
To: Zsh Users <zsh-users@zsh.org>
Subject: A function to display message under the prompt without zle active
Date: Sat, 22 Jun 2019 19:17:36 +0200	[thread overview]
Message-ID: <CAKc7PVA4gB_6FqObagdn8EBrFLdrUfJVAFHMyph2=YXUDWtExg@mail.gmail.com> (raw)

Hello,
I've forged as I think an interesting function, which will display
given message under the prompt regardless if ran from within zle or
not. It uses the exec <(...) / zle -F trick to dispatch a callback
that does have the zle active (zle -F -w isn't needed, zle -M works
fine from no-widget callback):

# deploy-message Hello world
# deploy-message @sleep:5.5 "Hello world"
deploy-message() {
    [[ "$1" = <-> && ${#} -eq 1 ]] && { zle && {
            local alltext text IFS=$'\n' nl=$'\n'
            repeat 25; do read -u"$1" text; alltext+="${text:+$text$nl}"; done
            [[ -n "$alltext" ]] && zle -M "$alltext"
        }
        zle -F "$1"; exec {1}<&-
        return 0
    }
    local THEFD
    # The expansion is: if there is @sleep: pfx, then use what's after
    # it, otherwise substitute 0
    exec {THEFD} < <(LANG=C sleep $(( 0.01 +
${${${(M)1#@sleep:}:+${1#@sleep:}}:-0} )); print -r --
${1:#(@msg|@sleep:*)} "${@[2,-1]}")
    zle -F "$THEFD" -deploy-message
}

There's a gist with the function as well, in case of any updates:
https://gist.github.com/psprint/b6503c0c37de483f68d055e9c47981b3
-- 
Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin
Blog: http://zdharma.org

             reply	other threads:[~2019-06-22 17:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-22 17:17 Sebastian Gniazdowski [this message]
2019-06-22 17:45 ` Roman Perepelitsa
2019-06-22 20:49   ` Sebastian Gniazdowski
2019-06-22 21:17     ` Roman Perepelitsa
2019-06-22 21:19       ` Roman Perepelitsa
2019-06-22 21:31       ` Sebastian Gniazdowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAKc7PVA4gB_6FqObagdn8EBrFLdrUfJVAFHMyph2=YXUDWtExg@mail.gmail.com' \
    --to=sgniazdowski@gmail.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).