From f5d0747ea5b3df110d59ddc2158a203b96270199 Mon Sep 17 00:00:00 2001 From: "Adam D. Ruppe" Date: Tue, 20 May 2025 10:05:47 -0400 Subject: [PATCH] more docs --- terminal.d | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/terminal.d b/terminal.d index 3fabd14..9f3ec97 100644 --- a/terminal.d +++ b/terminal.d @@ -145,7 +145,16 @@ unittest { $(H3 Single Key) This shows how to get one single character press using - the [RealTimeConsoleInput] structure. + the [RealTimeConsoleInput] structure. The return value + is normally a character, but can also be a member of + [KeyboardEvent.Key] for certain keys on the keyboard such + as arrow keys. + + For more advanced cases, you might consider looping on + [RealTimeConsoleInput.nextEvent] which gives you full events + including paste events, mouse activity, resizes, and more. + + See_Also: [KeyboardEvent], [KeyboardEvent.Key], [kbhit] +/ unittest { import arsd.terminal; @@ -162,6 +171,34 @@ unittest { version(demos) main; // exclude from docs } +/// ditto +unittest { + import arsd.terminal; + + void main() { + auto terminal = Terminal(ConsoleOutputType.linear); + auto rtti = RealTimeConsoleInput(&terminal, ConsoleInputFlags.raw); + loop: while(true) { + switch(rtti.getch()) { + case 'q': // other characters work as chars in the switch + break loop; + case KeyboardEvent.Key.F1: // also f-keys via that enum + terminal.writeln("You pressed F1!"); + break; + case KeyboardEvent.Key.LeftArrow: // arrow keys, etc. + terminal.writeln("left"); + break; + case KeyboardEvent.Key.RightArrow: + terminal.writeln("right"); + break; + default: {} + } + } + } + + version(demos) main; // exclude from docs +} + /++ $(H3 Full screen) @@ -3248,6 +3285,8 @@ struct RealTimeConsoleInput { function is really only meant to be used in conjunction with getch. Typically, you should use a full-fledged event loop if you want all kinds of input. kbhit+getch are just for simple keyboard driven applications. + + See_Also: [KeyboardEvent], [KeyboardEvent.Key], [kbhit] */ bool kbhit() { auto got = getch(true);