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

Customise keybinds/text for window close confirmation #4545

Closed
cwqt opened this issue Jan 20, 2022 · 5 comments
Closed

Customise keybinds/text for window close confirmation #4545

cwqt opened this issue Jan 20, 2022 · 5 comments

Comments

@cwqt
Copy link

cwqt commented Jan 20, 2022

Is your feature request related to a problem? Please describe.
I use confirm_os_window_close -1 to stop myself from accidentally closing windows while in vim. To cancel/confirm you have to either press y/n which are a bit out of the way.

Describe the solution you'd like
It'd be great if there was an option to rebind these to enter/escape (or any other keys really) for faster confirm/cancelling.

Something like this?

def confirm(
    self,
    msg: str,
    callback: Callable[..., None],
    *args: Any,
    window: Optional[Window] = None,
    confirm_on_cancel: bool = False
) -> None:
    confirm_key = self.confirm_os_window_close_confirm_key or 'y'
    cancel_key = self.confirm_os_window_close_cancel_key or 'n'

    def callback_(res: Dict[str, Any], x: int, boss: Boss) -> None:
        callback(res.get("response") == confirm_key, *args)

    self._run_kitten(
        "ask",
        ["--type=yesno", "--message", msg],
        window=window,
        custom_callback=callback_,
        default_data={"response": confirm_key if confirm_on_cancel else cancel_key},
    )

def confirm(self, msg: str, callback: Callable[..., None], *args: Any,

I'm not so much fussed about faster confirming and more for the faster cancelling, since the context switch can be a bit annoying.


It'd also be neat if there was a way to customise the text shown in the window, since with no terminal padding it gets a bit clipped - I'd just add a \n and some spaces to shift the message a bit more down & to the right -- maybe a confirm_os_window_close_padding yes?

image

@page-down
Copy link
Contributor

I have to say that the previous presentation is not very pretty to look at, but it is a good design.

  • No need to worry about displaying in different layouts and about the window changing size.
  • You need to explicitly type y to quit.

The purpose of using this feature is to prevent accidental operation, which is already troublesome enough and does not require more easy confirmation.
Users who wish to make it easier would be better off not using it.

I think (1) adding a space at the beginning of the message text and (2) allowing esc to exit, would be sufficient.

Many cli programs have similar prompts that require you to explicitly enter y. The default enter is no (cancel).

Finally, I found that when the window has only three rows

  • Only "Yes No" can be seen
  • Mouse click does not work.

@kovidgoyal
Copy link
Owner

kovidgoyal commented Jan 21, 2022 via email

@kovidgoyal
Copy link
Owner

And I got the new design working with rows >= 2 windows. Exactly the same as before.

@page-down
Copy link
Contributor

Why is it easier to press enter than y after pressing a shortcut?

I can only say that this may be due to my personal preference.
In this scenario I consider anything not confirmed by y to be a cancellation.

... I am fine with requiring 4 rows for operation.
... working with rows >= 2 windows. Exactly the same as before.

Thanks for clarifying. If you think it's acceptable then that's fine. I don't have a need for this scenario for now.

Have thought about shrinking the message text when the window is too small. (e.g. Quit? Yes No)
Not sure if it's worth it.

@cwqt
Copy link
Author

cwqt commented Jan 21, 2022

@kovidgoyal thanks so much!

Users who wish to make it easier would be better off not using it.

Have to disagree on this, I have option+w bound in my editor to close buffer & cmd+w is bound in kitty to close the tab - which seems like a fairly common setup.

One slip of my finger and whatever I'm working on is gone, admittedly it's a fairly rare occurrence but the fallout of it is worth using the confirmation for. It's not like you can easily mis-hit enter after going from cmd+w also.

Why is it easier to press enter than y after pressing a shortcut?

Easier for my pinkie to hit, kind of a stretch for my hand to go for y, maybe I just have a weird typing style.

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

No branches or pull requests

3 participants