Action to Wait for Next Input and Use Input to Execute Second Action #19755

Closed
opened 2026-01-31 06:52:42 +00:00 by claunia · 4 comments
Owner

Originally created by @ljtpetersen on GitHub (Apr 22, 2023).

Description of the new feature/enhancement

This is inspired by the Vim method of switching panes, which is to do ^W followed by an arrow key pointing
in the direction of the pane to switch to. The idea would be to have some keybind which, when activated,
listens for the next keystroke. Whichever keystroke it receives is then compared in a user specified map
to check which action to execute. If there is no corresponding entry for the entered key, both the activation command and the following keystroke are forwarded to the tty. There may also be a timeout.

This feature would allow a user to have many more possible keybind combinations by executing these sequences.

Proposed technical implementation details (optional)

I'll try to describe the method again here, in a clearer manner. When the user enters the specific key combination, the terminal waits for the next input, perhaps timing out after a few seconds. Once the next input is received, the terminal compares it to a user specified mapping of keystrokes to actions. If the keystroke is in the mapping, the corresponding action is executed. If the keystroke is not in the mapping, the preceding key combination is passed first, then the following key stroke.

For example, imagine a key combination ^W with an mapping rightarrow to move to the pane to the right.
If the user enters ^W followed by rightarrow, the terminal will switch to the pane to the right, and the tty will receive no input. If the user enters ^W followed by l, which is not a key in the mapping, the tty will receive the input ^W followed by l. It may also be possible to configure a default action for when the user enters a key not within the mapping.

Originally created by @ljtpetersen on GitHub (Apr 22, 2023). <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 I ACKNOWLEDGE THE FOLLOWING BEFORE PROCEEDING: 1. If I delete this entire template and go my own path, the core team may close my issue without further explanation or engagement. 2. If I list multiple bugs/concerns in this one issue, the core team may close my issue without further explanation or engagement. 3. If I write an issue that has many duplicates, the core team may close my issue without further explanation or engagement (and without necessarily spending time to find the exact duplicate ID number). 4. If I leave the title incomplete when filing the issue, the core team may close my issue without further explanation or engagement. 5. If I file something completely blank in the body, the core team may close my issue without further explanation or engagement. All good? Then proceed! --> # Description of the new feature/enhancement This is inspired by the Vim method of switching panes, which is to do `^W` followed by an arrow key pointing in the direction of the pane to switch to. The idea would be to have some keybind which, when activated, listens for the next keystroke. Whichever keystroke it receives is then compared in a user specified map to check which action to execute. If there is no corresponding entry for the entered key, both the activation command and the following keystroke are forwarded to the tty. There may also be a timeout. <!-- A clear and concise description of what the problem is that the new feature would solve. Describe why and how a user would use this new functionality (if applicable). --> This feature would allow a user to have many more possible keybind combinations by executing these sequences. # Proposed technical implementation details (optional) <!-- A clear and concise description of what you want to happen. --> I'll try to describe the method again here, in a clearer manner. When the user enters the specific key combination, the terminal waits for the next input, perhaps timing out after a few seconds. Once the next input is received, the terminal compares it to a user specified mapping of keystrokes to actions. If the keystroke is in the mapping, the corresponding action is executed. If the keystroke is not in the mapping, the preceding key combination is passed first, then the following key stroke. For example, imagine a key combination `^W` with an mapping rightarrow to move to the pane to the right. If the user enters ^W followed by rightarrow, the terminal will switch to the pane to the right, and the tty will receive no input. If the user enters ^W followed by `l`, which is not a key in the mapping, the tty will receive the input `^W` followed by `l`. It may also be possible to configure a default action for when the user enters a key not within the mapping.
claunia added the Issue-FeatureNeeds-TriageNeeds-Tag-FixNeeds-Attention labels 2026-01-31 06:52:42 +00:00
Author
Owner

@237dmitry commented on GitHub (Apr 22, 2023):

The difference between WT and Vim is that Vim runs inside its own runspace and knows nothing about key bindings outside of it. In turn, the terminal does not know anything about the key bindings in the applications that are running in it. Therefore, there is a high possibility that keyboard shortcuts can conflict with applications. Let's configure a Ctrl-W as a WT's compose hotkey and see how the Vim will work in this case.

@237dmitry commented on GitHub (Apr 22, 2023): The difference between WT and Vim is that Vim runs inside its own runspace and knows nothing about key bindings outside of it. In turn, the terminal does not know anything about the key bindings in the applications that are running in it. Therefore, there is a high possibility that keyboard shortcuts can conflict with applications. Let's configure a Ctrl-W as a WT's compose hotkey and see how the Vim will work in this case.
Author
Owner

@ljtpetersen commented on GitHub (Apr 22, 2023):

The difference between WT and Vim is that Vim runs inside its own runspace and knows nothing about key bindings outside of it. In turn, the terminal does not know anything about the key bindings in the applications that are running in it. Therefore, there is a high possibility that keyboard shortcuts can conflict with applications. Let's configure a Ctrl-W as a WT's compose hotkey and see how the Vim will work in this case.

I tried my best to distinguish the case with VIM compared to the case with WT. The case with VIM was purely an example I used to preface my proposal, whereas I would intend for a much more customizable implementation.

My idea was more that instead of a fixed keybind, the setup would be highly configurable. That way, the user can avoid keybind conflicts within their applications. In my proposal, the user would be able to configure which keybinds would trigger the detection and configure their own mapping which would map specific followup keys to actions. Then, if the user presses a key that isn't mapped, it gets sent to the terminal application. In this manner, the user can avoid losing the functionality of the underlying application by configuring their keybinds around it. I specially took this into account for my own use case, where I would like ^W followed by any arrow to move around the terminal pane, while ^W followed by the hjkl keys wouldn't be mapped, and so would be passed entirely to the underlying application, with the ^W included as well.

This was my idea. However, I am unsure of the feasibility of it, specifically the timing of the forwarded keypresses. This is due to my unfamiliarity with the windows terminal codebase.

@ljtpetersen commented on GitHub (Apr 22, 2023): > The difference between WT and Vim is that Vim runs inside its own runspace and knows nothing about key bindings outside of it. In turn, the terminal does not know anything about the key bindings in the applications that are running in it. Therefore, there is a high possibility that keyboard shortcuts can conflict with applications. Let's configure a Ctrl-W as a WT's compose hotkey and see how the Vim will work in this case. I tried my best to distinguish the case with VIM compared to the case with WT. The case with VIM was purely an example I used to preface my proposal, whereas I would intend for a much more customizable implementation. My idea was more that instead of a fixed keybind, the setup would be highly configurable. That way, the user can avoid keybind conflicts within their applications. In my proposal, the user would be able to configure which keybinds would trigger the detection and configure their own mapping which would map specific followup keys to actions. Then, if the user presses a key that isn't mapped, it gets sent to the terminal application. In this manner, the user can avoid losing the functionality of the underlying application by configuring their keybinds around it. I specially took this into account for my own use case, where I would like ^W followed by any arrow to move around the terminal pane, while ^W followed by the hjkl keys wouldn't be mapped, and so would be passed entirely to the underlying application, with the ^W included as well. This was my idea. However, I am unsure of the feasibility of it, specifically the timing of the forwarded keypresses. This is due to my unfamiliarity with the windows terminal codebase.
Author
Owner

@zadjii-msft commented on GitHub (Apr 22, 2023):

You mean something like #1334/?

@zadjii-msft commented on GitHub (Apr 22, 2023): You mean something like #1334/?
Author
Owner

@ljtpetersen commented on GitHub (Apr 22, 2023):

Yeah! I guess I didn't use the right keywords when I was looking for similar issues.

@ljtpetersen commented on GitHub (Apr 22, 2023): Yeah! I guess I didn't use the right keywords when I was looking for similar issues.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#19755