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

unable to quit app from the keyboard within vscode #5385

Open
jjallaire-aisi opened this issue Dec 12, 2024 · 17 comments
Open

unable to quit app from the keyboard within vscode #5385

jjallaire-aisi opened this issue Dec 12, 2024 · 17 comments

Comments

@jjallaire-aisi
Copy link

With the recent change to trapping Ctrl+C and asking the user to press Ctrl+Q, it is no longer possible to quit textual applications from the keyboard within VS Code (as VS Code takes the Ctrl+Q and executes another command, preventing textual from seeing the key-compo.

Here is a video where I attempt to press Ctrl+C, get the message, then press Ctrl+Q twice (note VS code takes the key):

textual-quit.mov

Textual Diagnostics

Versions

Name Value
Textual 1.0.0
Rich 13.9.4

Python

Name Value
Version 3.10.12
Implementation CPython
Compiler GCC 11.4.0
Executable /home/ubuntu/UKGovernmentBEIS/inspect_ai/.venv/bin/python3

Operating System

Name Value
System Linux
Release 6.8.0-1018-aws
Version #19~22.04.1-Ubuntu SMP Wed Oct 9 16:48:22 UTC 2024

Terminal

Name Value
Terminal Application vscode (1.95.3)
TERM xterm-256color
COLORTERM truecolor
FORCE_COLOR Not set
NO_COLOR Not set

Rich Console options

Name Value
size width=115, height=14
legacy_windows False
min_width 1
max_width 115
is_terminal True
encoding utf-8
max_height 14
justify None
overflow None
no_wrap False
highlight None
markup None
height None
Copy link

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory

@TomJGooding
Copy link
Contributor

I'm not a VS Code user, but apparently you can use this setting to send the keybinding to the terminal instead:

https://code.visualstudio.com/docs/terminal/advanced#_keybinding-and-the-shell

@ihorh
Copy link

ihorh commented Dec 15, 2024

In my opinion, proper solution would be to change vscode keyboard shortcuts. Anyway I worked around this situation by adding custom key binding to my textual app. I just use 'q', I actually like it more than Ctrl+'q':

    BINDINGS = [
        Binding(key="q", action="quit", description="Quit the app"),
        ...
    ]

@darrenburns
Copy link
Member

darrenburns commented Dec 16, 2024

In my opinion, proper solution would be to change vscode keyboard shortcuts.

We're definitely not going to get into the business of having different keybinds for different terminals/environments. If it matters to you you can add a custom binding (as you did) or use keymaps to load a different key when VSCode is in use.

(On re-reading I'm not sure if you mean Textual should detect VSCode and offer different shortcuts, or VSCode users should change their own keyboard shortcuts)

@jjallaire-aisi
Copy link
Author

IMO the real trouble here is that for many users they simply won't be able to figure out how to quit without hard-aborting the terminal (a SIGKILL, which will likely block any standard cleanup the process does). Remember, Ctrl+C (the gesture that most user instinctively know) is now blocked entirely and the user is told to use Ctrl+Q instead. If they then try this and it fails due to VS Code taking, they have to (a) Realise that this is what the problem is; and (b) Sort out how to block the Ctrl+Q keyboard shortcut can be disabled in VS Code. My bet is that most users won't be able to sort this out, leaving the situation that Textual apps in VS Code are difficult to quit and impossible to interrupt gracefully. A reasonable compromise position might be to stop blocking Ctrl+C?

@darrenburns
Copy link
Member

A reasonable compromise position might be to stop blocking Ctrl+C?

You can still assign ctrl+c to the quit keybinding if you want. It won't be blocked unless an Input or TextArea is focused.

The problem is ctrl+c is now used for the copy keybinding in Input and TextArea. So ctrl+c would have a dual purpose if it were to also quit.

@jjallaire-aisi
Copy link
Author

You can still assign ctrl+c to the quit keybinding if you want. It won't be blocked unless an Input or TextArea is focused.

The problem is ctrl+c is now used for the copy keybinding in Input and TextArea. So ctrl+c would have a dual purpose if it were to also quit.

Yes, that's what we did. While I'm happy we found a workaround I was just wondering if textual (in general via its defaults) wanted to make it easy to quit apps in VS Code (I think right now it's quite difficult for users to figure out how to quit apps, at least in a way that enables the app to clean up).

There is plenty of precedent for keys that behave differently inside text inputs -- i.e. in modal dialogs the enter key usually accepts the dialog but while in a text area it inserts a newline. I don't think it would be incoherent at all to say that Ctrl+C works to quit unless you are in a textarea.

@willmcgugan
Copy link
Collaborator

ctrl+q works fine for me in VSCode on macOS. Perhaps it's an issue with VSCode on Linux.

Having ctrl+c both copy and quit would mean that users will almost certainly do it accidentally. It would also means that if you have a screen with a single input or textarea, you would not be able to quit. So I don't think the dual functionality is viable.

If it is an issue for you, then I think remapping that key in your app is the only solution.

@jjallaire-aisi
Copy link
Author

Interesting, if you execute the Preferences: Open Default Keyboard Shortcuts (JSON) command on a Mac and look for ctrl+q it does appear mapped to the workbench.action.quickOpenView command. Here is where that comes from in the source code.

From my standpoint this is completely resolved as I have the workaround you mentioned in hand, was just trying make sure you understood that users may in general struggle with quitting textual apps (of course only if I am correct about Ctrl+Q).

@darrenburns
Copy link
Member

ctrl+q doesn't work for me on MacOS. @willmcgugan I think you've got some keys rebound or something as the delete line thing also didn't work in your VSCode the other week.

@willmcgugan
Copy link
Collaborator

It does look like ctrl+q is bound. I don't think I have changed anything.

Screenshot 2024-12-16 at 18 09 57

And yet ctrl+q works just fine for quitting. 🤷‍♂️

Screen.Recording.2024-12-16.at.18.12.10.mov

@willmcgugan
Copy link
Collaborator

Can you guys see ctrl+q when you run textual keys ?

@jjallaire-aisi
Copy link
Author

No, it doesn't show up when I press it while running textual keys

@darrenburns
Copy link
Member

Also no, unless I set "terminal.integrated.sendKeybindingsToShell": true in my config. I'm guessing you have that set @willmcgugan?

@TomJGooding
Copy link
Contributor

There are a number of keybindings that will "skip the shell" in VS Code, as explained in the link above. Presumably Will you have some configuration or extension that overrides those defaults.

Trying to run TUIs in embedded IDE terminals inherently has some limitations. I don't expect Textual to change its keybindings just to accommodate VS Code.

@cobalt-e
Copy link

It might be related to the terminal in use. Notice Will is running zsh. I've had no problems on Windows using MingW as the default terminal.

@pugillum
Copy link

pugillum commented Jan 5, 2025

You can reproduce this behaviour by running this repo in Codespaces and then running one of the examples (I chose calculator.py). The first time you select ctrl-q VS Code pops up a notification that "Some keybindings don't go to the terminal by default and are handled by Visual Studio Code instead". If you ignore this message it disappears and isn't shown again.

If you select the button in the message it directs you to Settings where there's a setting "Terminal > Integrated: Send Keybindings To Shell" which is off by default.

I guess this is more a VS Code issue but as a Textual noob I encountered it recently and was somewhat vexed that I had to then remove those shortcuts (which, true, I wasn't using anyway). I only recently found out about the Send Keybindings To Shell setting and am hesitant to enable it lest there be side-effects.

Rather than enabling the use of ctrl-c or choosing a different default for quitting, maybe just a note in the setup docs would be a solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants