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 #3692++ - Rearchitects drivers #3837

Open
wants to merge 157 commits into
base: v2_develop
Choose a base branch
from

Conversation

tznind
Copy link
Collaborator

@tznind tznind commented Nov 19, 2024

This is a super set of #3791 and exists to see diff and direction of v2 drivers as discussed in #3821

Fixes

Progress

  • Keyboard
    • Exit
    • Typing
    • Backspace
  • Views
    • Run/RequestStop
    • MenuBar
  • Mouse (see MouseInterpreter)
    • Button 1 click
    • Multi clicks
    • All buttons
    • Scroll wheel
  • Other
    • Clipboard

Proposed Changes/Todos

Splits drivers up into logical components, simplifies and centralizes shared code patterns.

image

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 changed the title V2 drivers Fixes #3692++ - Rearchitects drivers Nov 23, 2024
@tig
Copy link
Collaborator

tig commented Nov 23, 2024

Hope you're ok with me updating the title & first post...

@tznind
Copy link
Collaborator Author

tznind commented Nov 23, 2024

Hope you're ok with me updating the title & first post...

No problem! Always appreciate a clear naming

Now we have fledgling support for

  • Keyboard
  • Mouse
  • Screen size

Net (i.e. native dotnet) and Windows (i.e win 32 api) are the two implementations - I assume we can drop curses and don't need to port?

resize-etc

@tznind tznind mentioned this pull request Nov 23, 2024
@tznind
Copy link
Collaborator Author

tznind commented Jan 1, 2025

@BDisp EscSeqUtils.MapKey does not handle backspace. Here is the ConsoleKeyInfo that comes in direct from console when reading with console read:

image

Apparently:

When working with ConsoleKeyInfo in a console application (e.g., in .NET or similar environments), the behavior you're describing is common. Here's why:
Backspace and 127 (0x7F) Behavior

Historically, many systems followed terminal standards where the Backspace key sent the DELETE (0x7F) control character instead of the Backspace (0x08) character.

When you press the Backspace key, the console might interpret it as sending the 127 (0x7F) code instead of 0x08 (Backspace).

This happens because of differences in how the terminal emulator or console environment maps keyboard keys to control codes.

How is this handled in NetDriver? is MapKey the best place to put this new logic?

@BDisp
Copy link
Collaborator

BDisp commented Jan 1, 2025

The DEL (127) is handled on the EscSeqUtils.MapConsoleKeyInfo method.

image

@BDisp
Copy link
Collaborator

BDisp commented Jan 1, 2025

This code fixes the right button click to popup the context menu.

image

@tznind
Copy link
Collaborator Author

tznind commented Jan 2, 2025

The DEL (127) is handled on the EscSeqUtils.MapConsoleKeyInfo method.

Great, I have added in call to this function in the new architecture, see aa8bdd7

This code fixes the right button click to popup the context menu.

Right click works for v2 net but not v2 win, I will have to explore your suggestion further when I have some time.

@tznind
Copy link
Collaborator Author

tznind commented Jan 2, 2025

Windows right click working thanks! 6c55e11

@BDisp
Copy link
Collaborator

BDisp commented Jan 2, 2025

Great, I have added in call to this function in the new architecture, see aa8bdd7

Nice.

Right click works for v2 net but not v2 win, I will have to explore your suggestion further when I have some time.

Works with NetDriver because it rely in the EscSeqUtils API and WindowsDriver don't, and it's needed to point the right way how to handle it. Don't forget to deal with the warning.

@tznind
Copy link
Collaborator Author

tznind commented Jan 11, 2025

I have added metrics for Redraw in v2 drivers and Trace logging for the view that is responsible for wanting itself redrawn. This will let us fix issues e.g. this one where HexView is constantly saying it wants layout and redraw when nothing is going on in app:

 dotnet-counters monitor -n UICatalog --counters Terminal.Gui

image

@tznind
Copy link
Collaborator Author

tznind commented Jan 14, 2025

@BDisp @tig any feedback on this PR would be appreciated.

@BDisp
Copy link
Collaborator

BDisp commented Jan 14, 2025

@BDisp @tig any feedback on this PR would be appreciated.

I'm in vacancy mode sorry.

@tig
Copy link
Collaborator

tig commented Jan 15, 2025

@BDisp @tig any feedback on this PR would be appreciated.

Yes.

My lighthouse beam is focused on other things right now.

But it's swinging around and will be back on TG real soon now.

I'm really excited about this PR!

@tznind
Copy link
Collaborator Author

tznind commented Jan 18, 2025

@BDisp the EscSeqUtils.MapConsoleKeyInfo is broken for some keys e.g.

new ConsoleKeyInfo ('}', ConsoleKey.Oem6, true, false, false) 

Gets returned as

new ConsoleKeyInfo('}', ConsoleKey.None, true, false, false);

This then breaks EscSeqUtils.MapKey

MapConsoleKeyInfo and MapKey are the two methods I am chaining to turn ConsoleKeyInfo into Key

For now I am using workaround:

 /// <summary>
 /// Converts terminal raw input class <see cref="ConsoleKeyInfo"/> into
 /// common Terminal.Gui event model for keypresses (<see cref="Key"/>)
 /// </summary>
 /// <param name="input"></param>
 /// <returns></returns>
 public static Key ConsoleKeyInfoToKey (ConsoleKeyInfo input)
 {
     ConsoleKeyInfo adjustedInput = EscSeqUtils.MapConsoleKeyInfo (input);
     
     // TODO : EscSeqUtils.MapConsoleKeyInfo is wrong for e.g. '{' - it winds up clearing the Key
     //        So if the method nuked it then we should just work with the original.
     if (adjustedInput.Key == ConsoleKey.None && input.Key != ConsoleKey.None)
     {
         return EscSeqUtils.MapKey (input);
     }

     return EscSeqUtils.MapKey (adjustedInput);
 }

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