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 8978 invoked from network); 5 Dec 2022 23:49:04 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 5 Dec 2022 23:49:04 -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:cc:Reply-To: Content-Transfer-Encoding:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=aS5WPQkIDhlKsEQyld67aPD9HgwJEML3ksl1VrAv49Y=; b=cZY05QWoJo9dVWjcgmJRos/5xh G2RSPvrjn1y2kZj0Y3j6v+H9/6euIscg22R4fUlaI6aNG9wnw3zffHAK8rmnNz7lx9yTLpdPVN5a5 ASG81fi/EGylbsWQh0ep3TAM2ZZLP/392GmQ9vz4Y3zzHaqiT93PH813a/tCN8yo0Rw16d/bWAGMk GsLoe2Oaw++PnRh0aFA0ap2jdDtB+JwtHq8MQmaRV3rWgp9g78OZA4dJn9tAfxg9Lm79x73dgchBc f/4mHqKIC4A1Bk4ilZz4aY3fQ7XqMSL4Ol/eK7f1k1CnYoC7GAhG4M7bBcIAzsuTr4saLwWOO278O I5QoQl4A==; Received: by zero.zsh.org with local id 1p2LCp-000Au1-QV; Mon, 05 Dec 2022 23:49:03 +0000 Received: by zero.zsh.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1p2LC1-000AZy-A4; Mon, 05 Dec 2022 23:48:13 +0000 Received: from [192.168.178.21] (helo=hydra) by mail.kiddle.eu with esmtp(Exim 4.95) (envelope-from ) id 1p2LBz-000Bpf-NF; Tue, 06 Dec 2022 00:48:11 +0100 cc: Zsh Workers In-reply-to: From: Oliver Kiddle References: To: Roman Perepelitsa Subject: Re: one time in 20 error MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <45485.1670284091.1@hydra> Date: Tue, 06 Dec 2022 00:48:11 +0100 Message-ID: <45486-1670284091.713245@QrNT.Ugrc.e_6U> X-Seq: 51102 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: On 29 Nov, Roman Perepelitsa wrote: > I have the following in my .zshrc: > > function skip-csi-sequence() { > local key > while read -sk key && (( $((#key)) < 0x40 || $((#key)) > 0x7E )); do > # empty body > done > } > > zle -N skip-csi-sequence > bindkey '\e[' skip-csi-sequence > > With this binding a buggy script that leaks mouse events into zle > won't have any effect. This is a nice idea. I've occasionally had unwanted effects from unintentionally hitting a function key. I thought I'd try this in C. After testing this, I'm inclined to think it would be better to special case the CSI sequence in getkeymapcmd() instead. Currently, you would need to bind this in every local keymap because most local keymaps will include a binding starting with the \e[ sequence. It is also common for Alt-[ to generate \e[. Binding that would override the skip-csi-sequence binding but we could discern between the two based on KEYTIMEOUT. Any other thoughts on this. Or objections to such an approach? Are there terminals out there that eschew CSI sequences and for which such special handling could be problematic? Is anyone especially attached to the current behaviour where unbound function keys and mouse movements cause chaos? I notice that bash has a skip-csi-sequence widget but leaves it disabled by default. Would be interesting ot know why. The patch below tries the widget approach. Rather than look for the termination character, I thought it better to bail out given any out-of-range parameter byte or KEYTIMEOUT being exceeded. As yet, I'm not planning to apply this. Oliver diff --git a/Src/Zle/iwidgets.list b/Src/Zle/iwidgets.list index c95c7a491..8d1b64e58 100644 --- a/Src/Zle/iwidgets.list +++ b/Src/Zle/iwidgets.list @@ -112,6 +112,7 @@ "self-insert-unmeta", selfinsertunmeta, ZLE_MENUCMP | ZLE_KEEPSUFFIX "send-break", sendbreak, 0 "set-mark-command", setmarkcommand, ZLE_MENUCMP | ZLE_KEEPSUFFIX | ZLE_LASTCOL +"skip-csi-sequence", skipcsisequence, ZLE_MENUCMP | ZLE_KEEPSUFFIX | ZLE_LASTCOL "split-undo", splitundo, ZLE_MENUCMP | ZLE_KEEPSUFFIX | ZLE_LASTCOL | ZLE_NOTCOMMAND "spell-word", spellword, 0 "set-local-history", setlocalhistory, ZLE_LASTCOL diff --git a/Src/Zle/zle_keymap.c b/Src/Zle/zle_keymap.c index d90838f03..737d3cd72 100644 --- a/Src/Zle/zle_keymap.c +++ b/Src/Zle/zle_keymap.c @@ -1430,6 +1430,11 @@ default_bindings(void) bindkey(emap, "\30\30", refthingy(t_exchangepointandmark), NULL); bindkey(emap, "\30=", refthingy(t_whatcursorposition), NULL); + /* skip unbound CSI sequence in all keymaps */ + bindkey(emap, "\33[", refthingy(t_skipcsisequence), NULL); + bindkey(vmap, "\33[", refthingy(t_skipcsisequence), NULL); + bindkey(amap, "\33[", refthingy(t_skipcsisequence), NULL); + /* bracketed paste applicable to all keymaps */ bindkey(emap, "\33[200~", refthingy(t_bracketedpaste), NULL); bindkey(vmap, "\33[200~", refthingy(t_bracketedpaste), NULL); diff --git a/Src/Zle/zle_misc.c b/Src/Zle/zle_misc.c index eba28d1ec..1b996fb8a 100644 --- a/Src/Zle/zle_misc.c +++ b/Src/Zle/zle_misc.c @@ -152,6 +152,19 @@ selfinsertunmeta(char **args) return selfinsert(args); } + +/**/ +mod_export int +skipcsisequence(char **args) +{ + int next, timeout; + do { + next = getbyte(1L, &timeout, 1); + } while (!timeout && next >= 0x20 && next <= 0x3f); + + return 1; +} + /**/ int deletechar(char **args)