-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Binding raw escape sequences doesn't work #2950
Comments
My complete bindings.json file:
|
We need to check, if the prefix of
After some local hacking I assume, that the |
@JoeKar I tried to change the lines to:
Now micro says at launch:
I'm not sure but maybe the cause is that micro already assigns these events to the Left and Right keys? Just guessing but this is what I gather from the initial check in raw mode which produced this output when I pressed the aforementioned key combinations:
Edit: Maybe I misunderstood you and you meant that something needs to be changed in the program code? If so, I'll wait for something I can test. Unfortunately, I don't know Go and I'm not acquainted with the code here, so I can't really fix this in the code. |
Ah, you're right...so while changing the stuff locally I didn't realized, that escaping the backslash in the But at the end I've to ask the question, why not simply assign When I understood |
Well, Left and Right are the arrow keys. I need to use them with the default actions to move around the text. My current workaround is to use AltRight and AltLeft for actions SelectWordRight and SelectWordLeft. So it's not a critical issue for me. But of course, I would prefer to use CtrlShiftRight etc because these are the defaults in most text editing applications. |
Sorry, I didn't get what you mean by that last paragraph and I don't even know what tcell is. |
Ok, check, understood. Didn't read your description carefully enough, sorry for that.
No worries. According to my current understanding it looks like a bug of So long story short, it's a bit tricky to solve this issue. |
One of the problems here is that JSON does not support the
(Yeah, arguably it is a bug: micro does not attempt to properly parse The bad news here is that it is not the only problem. With the above |
@dmaluka I just tried binding this. I'm not getting any error either, and I don't get the assigned function either (SelectWordRight etc). What I get is the same as pressing the Left and Right arrow keys (which is also the behavior without the bindings). |
Yep, but this is something which seems to be fixed easily (see below).
I was able with Already prepared...
...and working to register the |
@dmaluka |
I'll try to find time to take a close look into it. In the meantime, I think I like the idea of adding ...Actually there is one more thing that is not working: cannot bind raw sequences in micro via |
I will have a look on that too, since I'm more or less comfortable with that topic. Edit: |
@blunderful-scripts While micro's existing support for raw escape bindings is indeed not quite perfect and could be improved (e.g. with JoeKar's fixes), I think it would not help you with your specific problem. If you see this when pressing
it means that your problem is that your terminal sends So, if these raw bindings worked:
the result would be: So the only advice here: fix your terminal. |
@JoeKar So IIUC, raw escape bindings generally work, they only don't work if the same escape sequence is also recognized as a known key event (and your PR zyedidia/tcell#25 fixes that), right? So IIUC it is not a very critical issue ( Still, it is probably worth fixing, at least to avoid the user's confusion when the user does use a raw keybinding (even though doesn't need to) and it doesn't work. |
Quoting myself:
I was a bit wrong: the documentation in But users don't necessarily carefully read the documentation or are very familiar with json, so adding support for |
It is not the same sequence though. I get this for LeftArror and Right Arror (checking in raw): This for CtrlSfhitLeft and Right: |
I really don't understand much about how the interpretation of escape sequences works, But I'd like to ask: maybe the way to go is detect the terminal more carefully and bind different sequences to different terminals? I don't know if there is a way for micro to know that I'm using Mobaxterm, so this may be a moot point, but I thought i'd ask it anyway. |
Got it. I've been assuming that if the event received by micro from tcell is the same, e.g. So yeah, I was wrong, using raw escape keybindings should be a good workaround for this particular problem. (Only that it doesn't work, as you've found. But it should work with @JoeKar's PRs. I haven't tested them myself yet, but I'm going to.)
It's a moot topic. The tcell library (the library used by micro, in particular, for receiving events from the terminal) distinguishes between terminals via the |
Ok, then another question: is there a way to manually communicate to tcell (or micro) the correct terminal so one of them knows to assign correct actions to correct sequences? I know that there is an option to launch micro with --xterm (or something similar) option, so maybe there is a way to add a similar option for other terminals (as the need arises)? or is this too complicated? |
I mean, personally I'm fine with figuring out the correct escape sequences and manually changing the config. But then I'm not the only one using this software, and wouldn't it be nice to have this option so people don't need to figure all this out on their own? |
Yes, it was, but...
|
On Linux and other Unix systems, the way you tell micro the correct terminal is by setting the ...I've just realized that your situation is a bit peculiar: micro is running on Linux (via SSH), while the terminal is running on Windows, right? So, micro (and tcell) actually thinks that it is running in a Unix terminal, not a Windows one. And yet micro is working for you, so I guess MobaXTerm behaves like a Unix terminal, so it might be good news: you may not need to care about the fact that it is running on Windows, so you may try to add missing support for MobaXterm to https://github.com/zyedidia/tcell/tree/master/terminfo as a unix terminal, and then accordingly set e.g. Or maybe the entire problem should be approached differently, e.g. maybe MobaXterm properly emulates xterm (so no need to add special support for MobaXterm) but there is some bug in tcell. So I would try debugging tcell, to figure out why exactly does it e.g. report the same ...I don't use Windows, but if I was you, I would maybe start with simple experiments like: try using other Windows terminals and compare the behavior (to see if this is an issue with MobaXterm or with Windows terminals in general), try running micro locally on Windows instead of SSH and compare the behavior, try running apps other than micro (e.g. vim) and compare the behavior, and so on. |
On Putty, it's exact same behavior as in MobaXterm, and exact same raw escape sequences. on Kitty, CtrlShiftRight & Left work in micro correctly. Raw output: (for CtrlShiftLeft & Right) (for Left & Right) I'm starting to wonder if the Putty escape sequences for CtrlShiftLeft & Right are specific to Putty and Putty-like terminals (which MobaXterm might be for this matter), in which case it would make sense to just map them to the correct commands in tcell (or in micro). I can try to look at the tcell code but chances that I can figure this out are quite slim, since I really know nothing about Go. Edit: When running natively on Windows, CtrlShiftLeft & Right work correctly, although micro doesn't detail escape sequences in raw mode. Edit2: I see that x1bOC and x1bOD are specifically assigned to Left and Right in https://github.com/zyedidia/tcell/blob/master/terminfo/x/xterm/term.go I'm wondering why? Checking natively (not through SSH) on my second Linux Mint machine, I'm getting |
I did find some references to x1bOC and x1bOD being used by vt100 terminals or similar. References: https://studmed.uio.no/elaring/voila/venv/lib/python3.9/site-packages/prompt_toolkit/input/ansi_escape_sequences.py I may be wrong but I suspect that someone mistakenly copy-pasted these escape sequences into tcell without checking whether they indeed apply to xterm. |
After some google-fu, I found this website which goes into (very much) detail about keyboard escape seqeunces. To say that I understand less than 5% of it is an understatement. However, this passage seems quite clear. Here's the page, in case someone smarter than myself can decode what's written in it. |
It seems you already gave the answer by yourself between the lines:
PuTTY isn't able to transmit the correct key code not matter if application mode is set or not and how
What you can try to do is if |
As I mentioned above, the actual escape sequences are not the same for c-s-left and for left. The escape sequence MobaXterm transmits for c-s-left (as reported by cat) is So what I'm saying is, perhaps there is no need to force everyone who uses Putty and Putty-based terminals to "live with it" or to modify the config file, if there is a simple solution of programmatically interpreting the (likely no-longer used) VT100 escape sequence for 'left' as (actually actively used by many people) Putty escape sequence for c-s-left. |
Ok, then we've at least the chance to handle this.
With the last hint
The option |
Tested in putty (because I don't know if it's even possible to switch between application mode and normal mode in mobaxterm - I couldn't find this setting). Both settings don't affect transmitted/received escape sequences for c-s-left and c-s-right. Now according to that manual, this is supposed to be set by the server, although the client (putty) can disable the application mode. I can't tell whether anybody or anything is still using the application mode, but it sounds like it's safe for a server application (such as micro) to disable application mode while it's running and then (just in case) to restore the previous mode when exiting. I assume that there is an API to do that (and possibly micro or tcell is already doing that?) The idea for disabling the application mode while micro is running is to avoid a (possible?) regression where someone's cursor keys stop working because of c-s-left and c-s-right escape sequences override. |
Forgot to mention that also, changing both settings doesn't affect how micro reacts to c+s+left and c+s+right when editing (i.e. the result is still the same as pressing 'left' and 'right'). |
Ok, tried it myself and realized that PuTTY simply doesn't forward the Shift as a modifier key and therefore Left = Shift+Left and Ctrl+Left = Ctrl+Shift+Left. From my point of view this is a limitation/bug of PuTTY and can't be (simply) solved, without changing PuTTY itself. |
Interesting - I confirm that this is the behavior in putty. However, this is not the behavior in mobaxterm. raw in micro: |
That said, I don't want to waste your time on mobaxterm-specific solution, specifically for me. So unless other people need this, probably this issue can be closed. (especially if I can assign the raw escape sequence in the config file after your fix gets merged) |
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 Summarizing:
|
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
From my perspective this highly depends on the users local scenario and mentioned every possibility is too much for the documentation of
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 meant a brief list what's included and what's not, like:
I have started writing bindings for ESC[ sequences but I was wondering whether it's already have been created somewhere by someone, since I do not like to reinvent warm water. I am too fresh meat here to start rewriting the docs, so I ask around first! :-) |
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: c2cebaa
OS: Debian Stretch (connecting from MobaXterm on Windows, through SSH)
Terminal: MobaXterm
The text was updated successfully, but these errors were encountered: