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

Fixes #3516. Changes default QuitKey to Esc #3555

Merged
merged 8 commits into from
Jun 24, 2024

Conversation

tig
Copy link
Collaborator

@tig tig commented Jun 20, 2024

Fixes

Proposed Changes/Todos

  • Change to Esc
  • Fix tests
  • Fix scenarios (if any)
  • Update docs

Pull Request checklist:

  • I've named my PR in the form of "Fixes #issue. Terse description."
  • My code follows the style guidelines of Terminal.Gui - if you use Visual Studio, hit CTRL-K-D to automatically reformat your files before committing.
  • My code follows the Terminal.Gui library design guidelines
  • I ran dotnet test before commit
  • I have made corresponding changes to the API documentation (using /// style comments)
  • My changes generate no new warnings
  • I have checked my code and corrected any poor grammar or misspellings
  • I conducted basic QA to assure all features are working

@tig tig marked this pull request as ready for review June 20, 2024 23:36
@BDisp
Copy link
Collaborator

BDisp commented Jun 21, 2024

There is something strange when clicking a button in a Dialog. Try opening the InteractiveTree scenario and clicking Add Root in the status bar. The Dialog will open and after typing the node name click on the Ok button. The Dialog closes and opens again despite Application.RequestStop having been called. Therefore, the Dialog should not open and the same happens with the Cancel button.
It is a good idea to create a unit test to prevent this bad behavior from happening.

@tig
Copy link
Collaborator Author

tig commented Jun 21, 2024

Do you think this has something to do with this PR?

Does this reproduce on v2_develop. I'm not a computer to check.

@BDisp
Copy link
Collaborator

BDisp commented Jun 21, 2024

Do you think this has something to do with this PR?

Does this reproduce on v2_develop. I'm not a computer to check.

Yes it reproduce on v2_develop branch and so has nothing with this PR.

@dodexahedron
Copy link
Collaborator

I have a question.

What happens when an escape literal is received on stdin? Quit, by default?

Because I ran into stuff today that has drastically altered my stance, if that's the proposed change to default behavior, which I'm glad to share if that is, in fact, what it is.

@BDisp
Copy link
Collaborator

BDisp commented Jun 22, 2024

I have a question.

What happens when an escape literal is received on stdin? Quit, by default?

Because I ran into stuff today that has drastically altered my stance, if that's the proposed change to default behavior, which I'm glad to share if that is, in fact, what it is.

If only an escape is received it will Quit, otherwise the ANSI escape sequence will be processed if the terminal supports it, otherwise it will be echoed as text.

@dodexahedron
Copy link
Collaborator

dodexahedron commented Jun 23, 2024

OK. That I think mostly jives with expectations.

I think it would be good to include some tests for it that do some things such as redirecting stdin and writing esc to it, to test/prove at least that particular case.

Most other ways of testing scenarios and environments that I thought up aren't really things that can be done in that unit test project, but that one is simple and good enough for a basic case that should cover at least some of them, I think.

Here were scenarios I thought up last night (food for thought, maybe, but not hard suggestions really):

  • Asymmetric input if multiple processes are watching stdin (loggers, input filters, password managers, certain keyboard drivers and macros, and a whole range of other things)
  • What if they're kibitzing with another user (That's almost the same as the previous point, but now multiple humans are directly involved)
  • What if they feed it from a pipe or other stream for automation?
  • What if there's an automated process involved? That includes people's UI testing.
  • What if they redirect stdin? Maybe that input comes from a formatted file or even a remote session?
  • What if their mouse input is dependent on it?
    • This isn't uncommon, and is part of why sometimes terminals get screwed up and mouse input causes garbage at the prompt.
  • What if they want to actually format text they're storing in a text field?
  • What if they're using UI theming software (such as Oh My Posh, even), which might want to use escape sequences to change cursor shapes and stuff like that, depending on themes and preferences of course?

And if you've already got that covered by your planned implementation, awesome! 🥳

Copy link
Collaborator

@dodexahedron dodexahedron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a quick scan taken over the changes to the Terminal.Gui code.

Didn't do in-depth analysis yet and didn't bother with the tests or samples either.

Nothing critical popped out at me anyway on scan.

Only things that prompted any questions were a nullable bool return and a hidden method. But both are pretty minor.

Oh, and some empty XmlDoc elements.

@@ -631,7 +631,7 @@ private void UpdateKeyBinding ()
/// - if the user presses the HotKey specified by CommandView
/// - if HasFocus and the user presses Space or Enter (or any other key bound to Command.Accept).
/// </summary>
protected new bool? OnAccept (CommandContext ctx)
protected bool? OnAccept (CommandContext ctx)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the nullable necessary here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so.

Part of the design of Command/KeyBinding is described here. For this, I believe we need to support propogating "don't know/yes/no" up and down the stack. OnAccept is right in the middle of all this.

// * If no key binding was found, `InvokeKeyBindings` returns `null`.
// Continue passing the event (return `false` from `OnInvokeKeyBindings`).
// * If key bindings were found, but none handled the key (all `Command`s returned `false`),
// `InvokeKeyBindings` returns `false`. Continue passing the event (return `false` from `OnInvokeKeyBindings`)..
// * If key bindings were found, and any handled the key (at least one `Command` returned `true`),
// `InvokeKeyBindings` returns `true`. Continue passing the event (return `false` from `OnInvokeKeyBindings`).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me.

An opportunity for a small future optimization is there, but it's fairly minor.

I also have been starting to think more about accessibility modifiers, as we get closer to completion. This one, being a kinda non-standard handler, because of not being void, might be a candidate for private protected instead of just protected.

The resulting visibility is the intersection of protected and internal, so it's visible to derived types in the same assembly only.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That also lets it continue to do what it needs to do, without having to worry about it being overridden outside of the library.

Terminal.Gui/View/ViewKeyboard.cs Outdated Show resolved Hide resolved
Terminal.Gui/Resources/config.json Outdated Show resolved Hide resolved
@tig tig merged commit 37ade48 into gui-cs:v2_develop Jun 24, 2024
1 check passed
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

Successfully merging this pull request may close these issues.

3 participants