zsh-workers
 help / color / mirror / code / Atom feed
From: Roman Perepelitsa <roman.perepelitsa@gmail.com>
To: Mikael Magnusson <mikachu@gmail.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: [BUG] Crash when accessing WIDGETSTYLE from SIGINT trap
Date: Wed, 13 Nov 2019 17:11:04 +0100	[thread overview]
Message-ID: <CAN=4vMq0wBc8PfvVa0hJ1D=GCcRHrgCkk0-XTJhjmxy1gZXLFw@mail.gmail.com> (raw)
In-Reply-To: <CAHYJk3SZC9n2Rm9mjPiuB607g9-Q6o1aoC4s+HyMHcP996ZeTw@mail.gmail.com>

On Tue, Nov 12, 2019 at 3:56 PM Mikael Magnusson <mikachu@gmail.com> wrote:
> Have you tried restoring the long prompt in zle-line-init instead?

No, I haven't. zle-line-init is a bit too late. Prompt is already
expanded and printed out at that point. I could still change PROMPT
there and call `zle reset-prompt` but it would be slower than changing
PROMPT in precmd. As I mentioned, I've found a workaround for the bug
that causes the first element of precmd_functions to get skipped over
after Ctrl-C, so the part of my code that restores long prompt works
correctly in all cases where I've tried it.

The unresolved problem is that my code calls set-short-prompt in some
cases when it shouldn't after Ctrl-C. zle can effectively be in two
states and I don't know how to distinguish between the two when my
SIGINT trap triggers.

Normal state: Keyboard input goes into BUFFER. When Ctrl-C is pressed
in this state, new prompt is created. When my SIGINT trap triggers, I
want to shorten prompt.

    Before Ctrl-C:
        /tmp% echo hello█

    After Ctrl-C:
        /tmp% echo hello
        /tmp% █

Modal state: Keyboard input goes into some place other than BUFFER.
When Ctrl-C is pressed, zle state changes to normal but a new prompt
is not created. When my SIGINT trap triggers, I want to do nothing.
(This is where my current code works incorrectly because it always
shortens prompt on SIGINT.)

    Before Ctrl-C:
        /tmp% grep -
        zsh: do you wish to see all 180 possibilities (45 lines)? █

    After Ctrl-C:
        /tmp% grep -█

    Before Ctrl-C:
        /tmp% echo hello
        bck-i-search: hell█

    After Ctrl-C:
        /tmp% █

How can I distinguish between these states? How can I figure out from
within a SIGINT trap whether zle will or won't create new prompt after
my trap function returns?

Roman.

      reply	other threads:[~2019-11-14  0:26 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20191111143952eucas1p2784d9821f292f2c9c136b19da5a56ade@eucas1p2.samsung.com>
2019-11-11 14:38 ` Roman Perepelitsa
2019-11-11 14:58   ` Peter Stephenson
2019-11-11 15:37     ` Daniel Shahaf
2019-11-11 15:40     ` Roman Perepelitsa
2019-11-11 15:46       ` Peter Stephenson
2019-11-12 14:56       ` Mikael Magnusson
2019-11-13 16:11         ` Roman Perepelitsa [this message]

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='CAN=4vMq0wBc8PfvVa0hJ1D=GCcRHrgCkk0-XTJhjmxy1gZXLFw@mail.gmail.com' \
    --to=roman.perepelitsa@gmail.com \
    --cc=mikachu@gmail.com \
    --cc=zsh-workers@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).