Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [BUG] Crash when accessing WIDGETSTYLE from SIGINT trap
- X-seq: zsh-workers 44908
- From: Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx>
- To: Peter Stephenson <p.stephenson@xxxxxxxxxxx>
- Subject: Re: [BUG] Crash when accessing WIDGETSTYLE from SIGINT trap
- Date: Mon, 11 Nov 2019 16:40:35 +0100
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- 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=EM4yVLfxBoIjLO2DiefyaGgqfk/7ej7e1BsySEkqByY=; b=cyohmghwvVxDLXpTu5od+N9w0+WiZCfvUSolF6+cjx+mlgbaW4WbrLz7PLdMkM2j9Z Vm9OMmPGP3AOH5m0r8K/SLxVqfNdH16S2DFKCNPRRt9tztpufNNtcstUvXBceqIIk9Bb eOtHKpShdXFpD+9JFs4AJY8D3WNXocD5UgBI4mNFBr78eA9yYIDgHVxWxQdiRHkIx6nb LDrYYV58IlaPZtD/j6WIb0vQCvtcvU1Ck8cI3HNcEjMO8a/DsjXWbKBI+LPt5zCFBAiQ BO+VOQmB5q3MUzcl08nowIo63+J0rCk1NSgKNsMi20JzOhj5NMwXwtKuYiUuOjF5Ik/7 12ng==
- In-reply-to: <1573484293.4561.8.camel@samsung.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <CGME20191111143952eucas1p2784d9821f292f2c9c136b19da5a56ade@eucas1p2.samsung.com> <CAN=4vMoahC2c4XHV9vE+Ohkx9rO00unZ0rC=E39yWfoSm4KKiw@mail.gmail.com> <1573484293.4561.8.camel@samsung.com>
On Mon, Nov 11, 2019 at 3:58 PM Peter Stephenson
<p.stephenson@xxxxxxxxxxx> wrote:
>
> On Mon, 2019-11-11 at 15:38 +0100, Roman Perepelitsa wrote:
> > Crash at zle_params.c:436 due to bindk being null:
> >
> > Widget widget = bindk->widget;
>
> Looks to me like returning the empty string in that case would be fine?
I don't know. I haven't sent a patch because I'm not sure whether the
fix should be right there in get_widgetstyle or somewhere earlier so
that bindk is not null to begin with.
I should've explained what I'm trying to do. I want to use a long
prompt for the current command line and a short prompt for complete
commands. Sort of like transient_rprompt option but instead of hiding
just right prompt I want to hide most of left prompt too. Here's a
short demo: https://raw.githubusercontent.com/romkatv/powerlevel10k-media/master/transient-prompt.gif.
Here's how I'm doing it:
- Set long prompt in precmd.
- Set short prompt in zle-line-finish and on SIGINT.
The code:
set-long-prompt() { PROMPT='%~%# ' }
precmd_functions=(set-long-prompt)
set-short-prompt() {
if [[ $PROMPT != '%# ' ]]; then
PROMPT='%# '
zle .reset-prompt
fi
}
zle-line-finish() { set-short-prompt }
zle -N zle-line-finish
trap 'set-short-prompt; return 130' INT
One issue with this code is that after hitting Ctrl-C, set-long-prompt
doesn't get called, so I end up with a short current prompt. I don't
know why this happens but apparently I can work around this by adding
another precmd hook before set-current-prompt. This extra hook won't
be called after Ctrl-C but set-current-prompt will.
do-nothing() {}
precmd_functions=(do-nothing set-current-prompt)
Unfortunately, there are a few other cases where hitting Ctrl-C will
result in the current prompt ending up short rather than long. For
example, if I this Ctrl-C after typing this:
autoload -U compinit
compinit
zstyle ':completion:*' menu select
grep -i<TAB>
If I didn't trap SIGINT, Ctrl-C would simply close the completion menu
here without reexpanding prompt. But now prompt will become short. To
deal with this issue I tried changing my trap so that it doesn't reset
prompt if SIGINT arrives during completions:
trap '[[ $WIDGETSTYLE == .expand-or-complete ]] || set-complete-prompt
return 130' INT
Unfortunately it crashes zsh as I've described in the original email.
It also doesn't really solve the problem. If I press Ctrl-S to trigger
fwd-i-search and then hit Ctrl-C, I'll end up with short prompt, too.
fwd-i-search is not a completion widget, so the condition in my trap
doesn't help.
What I really want is to follow the same logic as transient_rprompt
but instead of hiding right prompt I want to change left prompt. Any
hints on how I should do this? I feel like I'm digging in the wrong
direction.
Roman.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author