Replies: 2 comments
-
Would be really useful! Not being able to cancel out of prompts etc is a real grind. :( |
Beta Was this translation helpful? Give feedback.
0 replies
-
I am trying to write a 'mini command shell' (think of "diskpart" in Windows cmd). This would be very helpful to implement a History on the ArrowUp/Down-Keys during the TextPrompt. Currently I did implement my own GetLine() with calls to ReadKey(). But there I now have to 'fight' against the (Ansi)Console Cursor Positioning (e.g. with Tab)... I am new to Spectre Console so is there any other way to achieve this? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I would like to propose the addition of a key listener mechanism to Spectre.Console. This feature would allow developers to handle specific key presses (e.g., Esc) in a non-blocking, event-driven manner, significantly improving the interactivity and flexibility of console applications.
Problem:
Currently, handling key presses in Spectre.Console is limited by the use of Console.ReadKey, which is a blocking call and not well-suited for multi-threaded applications. This limitation makes it challenging to implement features such as "press Esc to return to the previous menu" without running into performance issues or key event handling delays.
Proposed Solution:
Introduce a key listener that operates in an asynchronous, non-blocking manner. This listener would capture key events, allowing developers to register specific actions to be triggered by key presses. This feature would enable smoother and more responsive user interactions in console applications.
Benefits:
Enhanced Usability: Developers can easily implement intuitive keyboard shortcuts, such as pressing Esc to navigate backward in a menu.
Improved Performance: By avoiding the limitations of Console.ReadKey, applications can maintain better responsiveness, even with high-frequency input.
Greater Flexibility: The key listener can be used in various scenarios beyond simple command input, making Spectre.Console even more versatile.
Example Usage:
Context:
I attempted to implement this functionality using a combination of Console.ReadKey and Task.Run, but the inherent limitations of Console.ReadKey—especially its blocking nature and lack of multi-threading support—led to suboptimal results. A dedicated key listener within Spectre.Console would resolve these issues and open up new possibilities for interactive console applications.
Conclusion:
Adding a key listener to Spectre.Console would greatly enhance the library's input handling capabilities, providing developers with a more powerful toolset to create responsive and user-friendly console applications.
Beta Was this translation helpful? Give feedback.
All reactions