mirror of https://github.com/adamdruppe/arsd.git
more docs
This commit is contained in:
parent
f924d9b42a
commit
f5d0747ea5
41
terminal.d
41
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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue