From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 28286 invoked from network); 15 Dec 2022 01:32:40 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 15 Dec 2022 01:32:40 -0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Message-ID:Date:Content-ID: Content-Type:MIME-Version:Subject:To:References:From:In-reply-to:Reply-To:Cc: Content-Transfer-Encoding:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=Qow21rnGUpf2D62aO/yM8gnOEAM7HlUhfF94oD1q39A=; b=Eaj//uNpWu8QALoJ+qQHE32zwM I8b3WgR56ELkiPt/IiTbtOYoADpRo0hr19YQhp1IGMJycNDjrR8vrbY8bzrDirEBW3kWGId3L5iTp JY8GFDMwdudz9cE8ROeAYjkaRuXjnCABj6lpfaCEBIaHVzOUIME/cIjsZKhUKyVLq4bkN6nUnZREq Rx3xQU4l75rx0DQJ8/yrz0bZDxywGI3vJuwOTT/aZNbIMUYR03tr0QB5Cf2XjAhGzxGvO88ijRFd/ pOCNZxOlIGYkb3blvYeX8ebexdKuu+UWfZ7FuxjzP3AgA7LMA+rXtpM4v3X2ld7OQMpR5lMQLEVDj cxnL5BhQ==; Received: by zero.zsh.org with local id 1p5d70-0002JH-U3; Thu, 15 Dec 2022 01:32:38 +0000 Received: by zero.zsh.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1p5d6V-00020V-TS; Thu, 15 Dec 2022 01:32:08 +0000 Received: from [192.168.178.21] (helo=hydra) by mail.kiddle.eu with esmtp(Exim 4.95) (envelope-from ) id 1p5d6U-000EC8-Hb for zsh-workers@zsh.org; Thu, 15 Dec 2022 02:32:06 +0100 In-reply-to: <11286-1670634245.024361@Cn3a.dvUs.EJET> From: Oliver Kiddle References: <45486-1670284091.713245@QrNT.Ugrc.e_6U> <11286-1670634245.024361@Cn3a.dvUs.EJET> To: Zsh Workers Subject: Re: one time in 20 error MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <54566.1671067926.1@hydra> Date: Thu, 15 Dec 2022 02:32:06 +0100 Message-ID: <54567-1671067926.542452@5dFf.Unco.iZC5> X-Seq: 51215 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: Below is an update to the CSI key sequence patch I posted in 51160. It adds a couple of test cases. There's also a new test case for the related code that ensures it loops for vi widgets that need to wait for an operator. After thinking about it, I changed the condition when it finds a complete CSI sequence. It will now keep a key binding for the first part of the CSI sequence if that binding extends into the parameters. There may be some use for this I haven't forseen and there isn't much gained in preventing it. A binding for the CSI prefix (escape or escape bracket) is still dropped in favour of undefined-key and consuming the full CSI sequence from the input buffer. I also added a comment to that condition. Oliver diff --git a/Src/Zle/zle_keymap.c b/Src/Zle/zle_keymap.c index d90838f03..48691e8d0 100644 --- a/Src/Zle/zle_keymap.c +++ b/Src/Zle/zle_keymap.c @@ -1586,7 +1586,7 @@ getkeymapcmd(Keymap km, Thingy *funcp, char **strp) Thingy func = t_undefinedkey; char *str = NULL; int lastlen = 0, lastc = lastchar; - int timeout = 0; + int timeout = 0, csi = 0, startcsi; keybuflen = 0; keybuf[0] = 0; @@ -1636,7 +1636,30 @@ getkeymapcmd(Keymap km, Thingy *funcp, char **strp) } #endif } - if (!ispfx) + + /* CSI key sequences have a well defined structure so if we currently + * have an incomplete one, loop so the rest of it will be included in + * the key sequence if that arrives within the timeout. */ + if (keybuflen >= 3 && !csi) { + startcsi = keybuflen - 3; + csi = keybuf[startcsi] == '\033' && keybuf[keybuflen - 2] == '['; + } + if (csi) { + csi = keybuf[keybuflen - 2] != Meta && keybuf[keybuflen - 1] >= 0x20 + && keybuf[keybuflen - 1] <= 0x3f; + /* If we reach the end of a valid CSI sequence and the matched key + * binding is for part of the CSI introduction, select instead the + * undefined-key widget and consume the full sequence from the + * input buffer. */ + if (!csi && keybuf[keybuflen - 1] >= 0x40 && + keybuf[keybuflen - 1] <= 0x7e && lastlen > startcsi && + lastlen <= startcsi + 2) { + func = t_undefinedkey; + lastlen = keybuflen; + } + } + + if (!ispfx && !csi) break; } if(!lastlen && keybuflen) diff --git a/Test/X02zlevi.ztst b/Test/X02zlevi.ztst index 203c13c32..ccfb7b1c6 100644 --- a/Test/X02zlevi.ztst +++ b/Test/X02zlevi.ztst @@ -596,6 +596,13 @@ >BUFFER: 1ls `2` $(3) "4" $'5' ${6} >CURSOR: 0 + zpty_run 'bindkey -s -a "cw" "dwi"' + zletest $'one two\e0cwyksi' + zpty_run 'bindkey -r -a "cw"' +0:for a vi command, wait to allow a longer binding to be used +>BUFFER: yksitwo +>CURSOR: 4 + %clean zmodload -ui zsh/zpty diff --git a/Test/X03zlebindkey.ztst b/Test/X03zlebindkey.ztst index 5277332a7..1b63b3920 100644 --- a/Test/X03zlebindkey.ztst +++ b/Test/X03zlebindkey.ztst @@ -37,6 +37,28 @@ >"^Xy" "bar" >"^Xy" undefined-key + zpty_run 'bindkey -s "\e[" altbracket' + zletest $'$\C-A\e[17~' + zpty_run 'bindkey -r "\e["' +0:binding to CSI introduction is not used if a full sequence arrives +>BUFFER: $ +>CURSOR: 0 + + zpty_run 'bindkey -s "\e[1" altbracketone' + zletest $'$\C-A\e[17~' + zpty_run 'bindkey -r "\e[1"' +0:binding to longer prefix of a CSI sequence is used +# we assume the user knows what they're doing +>BUFFER: altbracketone7~$ +>CURSOR: 15 + + zpty_run 'bindkey -s "\e[" altbracket' + zletest $'$\C-A\e[177' + zpty_run 'bindkey -r "\e["' +0:use prefix binding where we don't have a CSI sequence +>BUFFER: altbracket177$ +>CURSOR: 13 + # As we're only looking at definitions here, we don't # bother using the pseudo-terminal; just test in the normal fashion. bindkey -e