From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id a914cb33 for ; Sat, 22 Jun 2019 17:45:58 +0000 (UTC) Received: (qmail 13605 invoked by alias); 22 Jun 2019 17:45:51 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: List-Unsubscribe: X-Seq: 23981 Received: (qmail 23883 invoked by uid 1010); 22 Jun 2019 17:45:51 -0000 X-Qmail-Scanner-Diagnostics: from mail-io1-f49.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.101.2/25482. spamassassin: 3.4.2. Clear:RC:0(209.85.166.49):SA:0(-2.0/5.0):. Processed in 1.88204 secs); 22 Jun 2019 17:45:51 -0000 X-Envelope-From: roman.perepelitsa@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.166.49 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=GsnSttei73VrkAH1fngnDevBnqlicjG0HX62VWQyyEU=; b=FavVe+BgGlLClLuuf4RUXk4149hNQmG/3Yr6usi2UecunAX0ld1/sbXD8sItpILc/m V+yC/PP77CMgKBgDcJ8mdjtQWZKaNhmvQWFl/LMKOmfoUqS0q0mQUHtORC1LnGpMC2Lv QKghR8rGm6Xs4qzKLKjZIM9sPaIaeiqzdD/UNJinGLJS1tKsua3k8Nr5J9TcoJlHQ+hb YVrc+Cte9dQ73U699+/zhJ5VIcy0Mxh3mym34E4H3Caam028yjckoiBJQoqNKldX3ROP GOY6b7nPiNzd3Bq7jYMmFuxUTbycMpjTfes5Zyb9M0KJgsGIE5S7Qr6T1pkWkh+ypT7y vt1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=GsnSttei73VrkAH1fngnDevBnqlicjG0HX62VWQyyEU=; b=Vst8mP+GVz4a1JNs4LoBwgGalwL3RR3PTrWWKWrwfi4UugWmMVFhSbOEfbR6Bv7XNN ewG0JaE+M6yarT+FDFAXBN4w7aLvFn/zqYB+/6G7qQ5iWzx4WU3uUV4pi3U6dEf8b/fi WguyIfBZ3bTsb6Kxrz0W5NFxCA6/vYTKXdVSmf/0m2p6YTgsff1q+wzfGxnDi6fmRFYw Re+bf0Bea1CZ82DQeDfkhH83nUiuQbAZHdcV/pkldhk/MjATaVGm77a41p3hvLqZ1PVu MPw5Ilwe07XXqTfrm4FOAG5+WiyIkUpBOioHSP7qEcJUof6UoTx2/uA6APKAda5kR7qv oB3w== X-Gm-Message-State: APjAAAVzyttPi0pc2GLkJ947QqJr5NpVozxIW0q+dgCshhXlHrwKJrT5 tZpxsDXpbLzqNf4ydvoVLasBaHRQVqycHNjQM+o= X-Google-Smtp-Source: APXvYqzARJmSzaQWgcfUqC8SA1NHIzg669p9jV7FLh/48sNZY2xshjfJa9wOvbP0M8RwNmkipAbr3IY09aYpeUooq40= X-Received: by 2002:a5d:8890:: with SMTP id d16mr12071984ioo.274.1561225516538; Sat, 22 Jun 2019 10:45:16 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Roman Perepelitsa Date: Sat, 22 Jun 2019 19:45:05 +0200 Message-ID: Subject: Re: A function to display message under the prompt without zle active To: Sebastian Gniazdowski Cc: Zsh Users Content-Type: text/plain; charset="UTF-8" This should work as long as you don't write too much stuff without giving ZLE a chance to read it. # After executing this, you can write stuff to file descriptor $zle_msg_fd # and it'll be shown in the ZLE status line. # # echo "Hello World" >&$zle_msg_fd # ( echo 'Hello'; sleep 1; echo 'World' ) >&$zle_msg_fd &! () { emulate -L zsh && setopt err_return local fifo && fifo=$(mktemp -u "${TMPDIR:-/tmp}"/fifo.XXXXXXXXXX) mkfifo $fifo exec {zle_msg_fd} <> $fifo rm $fifo function _zle_msg_process() { emulate -L zsh while IFS='' read -r -u $zle_msg_fd line && zle -M $line } zle -F $zle_msg_fd _zle_msg_process } Roman. On Sat, Jun 22, 2019 at 7:18 PM Sebastian Gniazdowski wrote: > > 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