Skip to content
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

Add support for rebinding/remapping keys #680

Open
alfonsrv opened this issue Jun 8, 2020 · 24 comments
Open

Add support for rebinding/remapping keys #680

alfonsrv opened this issue Jun 8, 2020 · 24 comments
Labels
area: config area: hotkeys enhancement New feature or request GSoC Possible GSoC project component high priority should be done as soon as possible

Comments

@alfonsrv
Copy link

alfonsrv commented Jun 8, 2020

In Terminal on macOS Ctrl + d closes processes, while everything including the Meta key (aka Alt) is translated to a special character instead – making Alt + Enter not possible to use, hence making the zulip-terminal client a read-only client on macOS if the native Terminal configuration is not altered.

This could also help prevent tmux collisions by giving users the freedom to choose their key-bindings freely.

@neiljp
Copy link
Collaborator

neiljp commented Jun 8, 2020

This is actually possible by editing the keys.py file in the source distribution, though granted this is not straightforward or sustainable with upgrades. We have discussed the issue in the context of an appropriate key for sending messages previously, including in #294 . Do you have any thoughts given that discussion?

@alfonsrv
Copy link
Author

alfonsrv commented Jun 8, 2020

Editing the keys.py file indeed does not seem sustainable over the long run. If you ask for my opinion, I think a seperate [keybindings] section within the config would be desirable.

We could either work with a prefix – such as tmux, e.g. C-z (^Z) (is not used by default for any application I know of) – and then s for send. I think that behavior while indeed having a steeper learning curve would be desirable as it would give way more flexibility instead of having to battle with previously existing shortcuts. Or we just work with static keyboard bindings, however I think the collisions are too likely given what terminal power users such as the one using zulip-terminal use on a regular basis.

As for a default shortcut for sending messages, I think C-Space (^@) could work?

@neiljp
Copy link
Collaborator

neiljp commented Jun 8, 2020

I agree that making keybindings configurable outside of the source is the long term solution, and we could reserve this issue for that.

Given the ongoing debate over #294, setting sending keys in particular seems like the priority for now, whether as a configuration option or resolving the problem in another way. I recommend we discuss this aspect in that issue, and also in #zulip-terminal. There are past topics in that stream on chat.zulip.org such as "Key for sending msg" and "Contributing & Send Message shortcut". Looking back in the history I'm wondering if we want to re-try using a modifier with enter.

Re MacOS I believe other known ZT users use alternative emulators due to issues with eg. color support, as per #662, which could be a workaround to the keyboard issue for you.

@sumanthvrao
Copy link
Member

sumanthvrao commented Jun 9, 2020

@alfonsrv A hack which makes Alt + Enter work for me with Mac OS was to toggle this setting under Terminal > preferences > Profiles > Keys from Meta to ESC+

Note: I use iTerm2 terminal emulator and not the default one.

image

@alfonsrv
Copy link
Author

alfonsrv commented Jun 9, 2020

@sumanthvrao as mentioned initially, I do not want to adapt my native Terminal to a product; it should be the other way around. Thanks for the suggestion tho!

@neiljp well as mentioned regarding #294, ^z or ^l could be a god global alternative. regarding #662; colors work fine in native Terminal under tmux – automatically choosing dark theme even.

@neiljp
Copy link
Collaborator

neiljp commented Jun 9, 2020

@alfonsrv ctrl + L is a readline key (clear text) and also is known as a screen-redraw key in terminals. ctrl + Z is the suspend key which we don't support right now but could support in future, so I'm wary of using it for such a significant key as sending messages. Selecting a good 'standard' is not as easy as it appears!

@neiljp
Copy link
Collaborator

neiljp commented Jun 10, 2020

@alfonsrv We're currently discussing the keys on chat.zulip.org, but it does seem like the use of mac Terminal is currently limited by the keybindings it has chosen compared to other systems. ctrl <space> seemed reasonable but itself fails under iterm2 based on reports so far (closing the terminal!), and presumably platform-specific combinations with cmd on mac are unwise much like use of the windows keys on windows/linux systems (and cmd <space> reportedly is taken).

This is continuing off-topic, but do the colors look like the screenshot at https://github.com/zulip/zulip-terminal for you in Terminal/tmux? That's great if they do, but we had reports they didn't work in mac Terminal before I think (as per #662)

@neiljp neiljp added the enhancement New feature or request label Jun 12, 2020
@alfonsrv
Copy link
Author

I see. Well as previously suggested I think life would be much easier if shortcuts were prefixed or if keys were more accessibly rebindable using the .zuliprc config.

As for the theme – whenever I am in tmux it seems to default to the zt_dark theme, even though it is not specified in the configuration file. Sorry I had to blur most of it out, but I'm sure you get the idea https://imgur.com/ox6iRUU

alfons@NullX ~ % zulip-term
Loading with:
   theme 'zt_dark' specified with no config.
   autohide setting 'no_autohide' specified with no config.
Welcome to Zulip.
Loading -

@neiljp
Copy link
Collaborator

neiljp commented Jun 18, 2020

For the record, with #662 merged we've recorded the state of various emulators that we know so far.

@zulipbot
Copy link
Member

Hello @zulip/server-hotkeys members, this issue was labeled with the "area: hotkeys" label, so you may want to check it out!

@neiljp neiljp added GSoC Possible GSoC project component high priority should be done as soon as possible labels Apr 5, 2021
@neiljp
Copy link
Collaborator

neiljp commented Apr 5, 2021

Supporting even a simple version of this would enable us to unblock use by more users and give details of how to work around this between releases.

We likely want to work on #678 first to enable separation of config for profiles and options, though we could always migrate to that later? We likely want a centralized config for this since generally this is unlikely to be specific to a profile, though we could support a --keymap mapname much like we propose having zulip-term profilename for #678.

@neiljp
Copy link
Collaborator

neiljp commented Aug 17, 2021

Just thinking of this issue again after further discussion on chat.zulip.org regarding use of non-latin keyboard inputs, which is related to an older server repo issue zulip/zulip#7517. That is in the direction of internationalization which is not a high priority right now. However, this is very similar to the intent of this issue, namely to allow for additional/custom keys - if I switch into a different keyboard layout, perhaps I want certain keys to still perform the same actions. See the linked server issue for more discussion.

@supermarin
Copy link

Resurrecting this thread after trying to figure out how to map Send to just Enter. Is there any plans to support configurable keys in zuliprc?

@neiljp
Copy link
Collaborator

neiljp commented Jul 28, 2023

@supermarin Thanks for showing an interest in the feature!

I had hoped that we might migrate the configuration file sooner since that could make things simpler (as above), but contributors have been involved with other areas. That does not mean that a configuration option for this could not be developed outside of that migration, and some recent changes could make integrating this a little easier too.

Any contributions toward this would be welcome, whether as a PR, discussion of minimal features, or in terms of what you would wish to change, or the configuration format. As per the start of my comment here #680 (comment), all that is necessary is an adjustment of the dict in keys.py; there I suggested it could be manually changed (and still can be), whereas this feature would involve at minimum a patching of that dict at runtime based upon string-pairs in a configuration file (command -> key).

A fuller implementation would likely require validating those keys (at least for a subset of commands), and supporting migration of command strings from one version of ZT to another, which was historically a reason why we did not prioritize this issue. Documentation would also be useful, of the updated configuration options, as well as what keys/values are possible (pointing to source files and urwid documentation, in the first instance).

@supermarin
Copy link

supermarin commented Aug 7, 2023

As per the start of my comment here #680 (comment), all that is necessary is an adjustment of the dict in keys.py

Yep seen that one, but unless you're running the project from source, this isn't a feasible option for majority of users IMO.

A fuller implementation would likely require validating those keys (at least for a subset of commands), and supporting migration of command strings from one version of ZT to another, which was historically a reason why we did not prioritize this issue.

If you keep the same key code names as the dict keys in KEY_BINDINGS, i.e. SEND_MESSAGE in this case, then an assertion somewhere on config load that the mapped key code is in KEY_BINDINGS would verify the mapped key code is indeed an existing one, and it should fail in the future if the key codes change. If I'm missing something obvious let me know, but IMO it's better to roll out something simple and improve over it later, vs the current status :)

@neiljp
Copy link
Collaborator

neiljp commented Aug 10, 2023

Re editing keys.py manually, yes, that is likely not feasible for those users who are not familiar with how python applications are installed. However, manual configuration files are not always easy for users - it depends on the audience. At one point we had a draft where settings could be toggled in the application, which would be the ideal final result :)

Regarding implementation, we can certainly simply error-out before loading, if a key code name from the configuration file is not in KEY_BINDINGS - and that would not be much more complex than an assert.

(note that the part you linked to for config load concerns the validity/consistency of default configuration settings)

@neiljp neiljp changed the title make it possible to rebind keys Add support for rebinding/remapping keys Nov 7, 2023
@WuMingIT
Copy link

Adding my experience here: on Terminal app v 2.8.3, bash v 3.2.57(1), Python v 3.8.12, Zulip Terminal v 0.7.0 CTRL+d does submit a new message. But UI sometimes isn't updated so user won't notice. I did notice only because one of my team asked why I submitted the same message three times.

@neiljp
Copy link
Collaborator

neiljp commented Nov 27, 2023

@WuMingIT If it does submit a new message, this doesn't sound quite like the same issue?

Which Terminal app is this? for Mac?

@WuMingIT
Copy link

WuMingIT commented Nov 27, 2023

From OP’s first line “In Terminal on macOS Ctrl + d” and from my own “on Terminal app v 2.8.3”. Yes, subject is macOS here.

As for the same issue, perhaps OP did not realize a new message was, in fact, submitted. With CTRL+d at least.

@neiljp
Copy link
Collaborator

neiljp commented Nov 28, 2023

@WuMingIT I appreciate your feedback here 👍 I've tried to explain my earlier response in more detail below.

The reason I wanted to clarify your platform, is that "Terminal app" doesn't narrow down the application name, unless perhaps it's the default one on Mac - and even then, it's not necessarily guaranteed.

From the beginning this specific issue focused on the idea of a general solution to the specific problem of ctrl d/alt enter in the default terminal emulator on MacOS, via being able to remap/rebind keys, which could benefit users in general. I'd like to retain that as the focus of this issue for now.

Regarding the known challenge with using the MacOS default Terminal app with zulip-terminal, we previously added a note to the supported terminal emulator section in the FAQ. That points to this issue, and we could certainly summarize alternatives based on some of the comments above - eg. if people are willing to adjust their terminal emulator settings, or use a different emulator. Even once the remapping of keys is added (this issue), this would be useful, since some may find it simpler to do so instead of adjusting zulip-terminal settings. I've just opened #1443 to track this.

What I meant by how it sounds like you are describing different (though related) issue(s), is that

  1. for some reason ctrl d is working for you, under the emulator which previously had problems, ie. it sends messages (so related to the original problem, not the original suggested general solution)
  2. it seems the UI doesn't always update for you, to show that a message has been sent

For point (1), I'd welcome any details from you which could help everyone understand the situation better, ie. why this is working for you, but didn't for others previously. This comes under the remit of #1443, so I'd suggest following up there, though it may be easier to discuss in the #zulip-terminal stream on chat.zulip.org in a new topic.

For point (2), this sounds like it could be an independent bug, so if you're able, please do file a bug report with as much detail as you can!

@WuMingIT
Copy link

WuMingIT commented Nov 29, 2023 via email

@WuMingIT
Copy link

WuMingIT commented Dec 1, 2023

I have been using -term yesterday and today and it seems to work as expected now. Message send, edit, delete, quote. After adding the proper configuration notifications work as well.

@Niloth-p
Copy link
Collaborator

@zulipbot claim

@zulipbot
Copy link
Member

Hello @Niloth-p!

Thanks for your interest in Zulip! You have attempted to claim an issue without the label "help wanted". You can only claim and submit pull requests for issues with the help wanted label.

If this is your first time here, we recommend reading our guide for new contributors before getting started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: config area: hotkeys enhancement New feature or request GSoC Possible GSoC project component high priority should be done as soon as possible
Projects
None yet
Development

No branches or pull requests

7 participants