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 1db14eef for ; Sat, 22 Jun 2019 20:50:01 +0000 (UTC) Received: (qmail 9288 invoked by alias); 22 Jun 2019 20:49: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: 23982 Received: (qmail 2829 invoked by uid 1010); 22 Jun 2019 20:49:51 -0000 X-Qmail-Scanner-Diagnostics: from mail-oi1-f170.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.167.170):SA:0(-2.0/5.0):. Processed in 3.725156 secs); 22 Jun 2019 20:49:51 -0000 X-Envelope-From: sgniazdowski@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.167.170 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=zi+224OMUPEO3wjLhg5B+4CJCsj2UtF9Okvmk/baAXI=; b=vamGZBJjSOd96/NHux5Biq6W0PAXs8/2FME/N0K8DWP4oih1lo3i2LqohuhpxfQclp w4qkUEHJOt8INZlnVioXNYpTHwMLGwGX0SKrCMEhw8usgtnX+g9qIFdD5Bnx4tFzC7+V SmO6zCcyddviP9y6K/o3jTawYbwGbUc8VsSygbivr5siB8CiR6v+PYnLh+U552qM4UUF +VTythZnokirGTvQHaXJWy1b1e+nkknxFmF19TjsfG88yOP27CuoZoHxZ+0h/RpC4KfC tIqIxW+VS72xFueWa0hMLaCsrcXyUDlPCXtAvBd/pfoTiIDTdI0O4BxKd3FqX21g8RRO hW8Q== 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=zi+224OMUPEO3wjLhg5B+4CJCsj2UtF9Okvmk/baAXI=; b=Pm1PykzRAsW+16bnrytPS9Vq9PihlrbUpqoTNytKQEZynxzusy7Tx+7CRhIi3eHLkB uFO7KEIcH9q/3SnciyE/BBcOorx6tREDEc7MYl4mbEIHgdh4Tym+73Ic5PyaT2te8+15 KxPCHxsHPVOZijEiwdm1QP0jTdIzMaZtvoXuIO2vAN8IcgkSfYX3MOgq6JMFRRohP3e9 4be8xlLqjWsf1jcMr/d8N9Gpv7rjQCnhNJWk3Del2OhgEKPNQYZC3RYljvMl4altfHMk WvJjiiSuNvqbcxQOW13qmutbZQYQTwHAYONGJZdjVOu9EtOFX2YRAPWsDv1FgFClxGFp ojKA== X-Gm-Message-State: APjAAAWTx3IQi2+ARim7KQ64tFBb4pKKp7SMAOt+8aPgibWVtMx+88Tv l7LQ1+nMVA8U/9PKGK1J025dcTY4LA4Vy4mpgBBKGQ== X-Google-Smtp-Source: APXvYqwQkzoQOiVUlE46JUJtDiIXdhgE83ol9xdWVKxpy+qD4zMCao3qK0a/rYa8N7D3uf4GTG6wGCbSSeSrU4BCTwI= X-Received: by 2002:aca:d6d7:: with SMTP id n206mr6385474oig.179.1561236554079; Sat, 22 Jun 2019 13:49:14 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Sebastian Gniazdowski Date: Sat, 22 Jun 2019 22:49:02 +0200 Message-ID: Subject: Re: A function to display message under the prompt without zle active To: Roman Perepelitsa Cc: Zsh Users Content-Type: text/plain; charset="UTF-8" On Sat, 22 Jun 2019 at 19:45, Roman Perepelitsa wrote: > > 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. The command line seems to be blcoked after first using the descriptor. > # 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 -- Sebastian Gniazdowski News: https://twitter.com/ZdharmaI IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin Blog: http://zdharma.org