micro: Binding raw escape sequences doesn't work

Description of the problem or steps to reproduce

I’m using MobaXterm on Windows to connect to my Debian machine via SSH. The default key bindings for SelectWordLeft and SelectWordRight (CtrlShiftLeft and CtrlShiftRight) don’t work. I checked in the raw mode (in micro) what it receives when I’m pressing these combinations and it says: EventKey: Left: “\x1bOD” EventKey: Right: “\x1bOC”

So following the instructions for binding raw escape sequences, I added this to my ~/.config/micro/bindings.json: “\x1bOC”: “SelectWordRight”, “\x1bOD”: “SelectWordLeft”,

But after that, when launching micro, it says “Error reading bindings.json: invalid character ‘x’ in string escape code”. Exactly like in this older issue #1863 .

Specifications

Commit hash: c2cebaa3 OS: Debian Stretch (connecting from MobaXterm on Windows, through SSH) Terminal: MobaXterm

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 37

Most upvoted comments

  1. either \x1b should work in config file or raw should be fixed?

It would work with the config files as well, when zyedidia/json5#1 would be merged. Unfortunately I can’t speed this up, since I’ve no merge rights. Afterwards the dependency within micro needs to be bumped.

  1. a few words about what’s expected through xterm->ssh->tmux (I get \x1b[1;5C for CtrlRight which shall be in fact WordRight in config).

From my perspective this highly depends on the users local scenario and mentioned every possibility is too much for the documentation of micro itself. But I confirm, that the documentation should be consistent.

  1. doc as well: […]

Currently it makes no sense, at least in my opinion, because that part need to be changed again after the above mentioned PR is merged (if and when ever). But everyone is encouraged to support with his own PR. 😉

I have to confess that I was not patient enough to read all the 100+ comments here. Still I hope I can be relevant.

I am new to micro, so I read the documentation. When I realise that micro does not work through ssh/tmux/… because it gets the escape sequences and does not interpret them, I started looking for why and failed (it seems either documentation is oblivious about escapes not supported [yes I see the mention, but not the resolution], or maybe it’s supported but my version isn’t latest, v2.11).

Anyway. The documentation talks about \x1b, and 0x1b and it seems neither works (as they are) in the config. \uXXXX seems to be vaguely mentioned but it’s not obvious for the causal reader that despite how it’s referred to and how raw mode displays the \u001b form is what works, others aren’t. This is mainly the problem of the documentation (it should be spelled out that \x1b shall be written as \u001b), but inconsistent with raw output as well.

Summarizing:

  1. the page keybindings.md >> Binding raw escape sequences shall be consistent about ESC format and be unabiguous about how the config file expects it.
  2. either \x1b should work in config file or raw should be fixed?
  3. a few words about what’s expected through xterm->ssh->tmux (I get \x1b[1;5C for CtrlRight which shall be in fact WordRight in config).
  4. doc as well: may mention that how the current bindings could be printed. If possible, I mean. 😃

Quoting myself:

Yeah, arguably it is a bug: micro does not attempt to properly parse \x-escaped strings, instead it simply relies on the JSON parser which does not support \x either, so the resulting behavior is non-intuitive and undocumented.

I was a bit wrong: the documentation in help keybindings does mention the \u notation.

But users don’t necessarily carefully read the documentation or are very familiar with json, so adding support for \x notation in bindings.json would still be nice. (Even though micro will forcefully rewrite bindings.json every time, replacing \x with the canonical \u, which is BTW also something users wouldn’t expect, but at least keybindings will keep working.)

One of the problems here is that JSON does not support the \x notation, so in bindings.json the raw sequence bindings need to be specified slightly differently:

    "\u001bOC": "SelectWordRight",
    "\u001bOD": "SelectWordLeft",

(Yeah, arguably it is a bug: micro does not attempt to properly parse \x-escaped strings, instead it simply relies on the JSON parser which does not support \x either, so the resulting behavior is non-intuitive and undocumented.)

The bad news here is that it is not the only problem. With the above \u notation, micro does not print any errors, and I can see that micro does call screen.Screen.RegisterRawSeq(), however the bindings themselves still don’t work (i.e. nothing happens when I press the corresponding keys). I remember it used to work for me some (rather long) time ago, so I think it is a regression, either in micro or in tcell.