This commit is contained in:
Adam D. Ruppe 2018-12-19 09:05:07 -05:00
parent af47ae19c2
commit 732cba5bff
1 changed files with 19 additions and 2 deletions

View File

@ -1,4 +1,3 @@
// FIXME: have a simple function that integrates with sdpy event loop. it can be a template
// for optional dependency // for optional dependency
/++ /++
Module for interacting with the user's terminal, including color output, cursor manipulation, and full-featured real-time mouse and keyboard input. Also includes high-level convenience methods, like [Terminal.getline], which gives the user a line editor with history, completion, etc. See the [#examples]. Module for interacting with the user's terminal, including color output, cursor manipulation, and full-featured real-time mouse and keyboard input. Also includes high-level convenience methods, like [Terminal.getline], which gives the user a line editor with history, completion, etc. See the [#examples].
@ -78,6 +77,8 @@ unittest {
string line = terminal.getline(); string line = terminal.getline();
terminal.writeln("You wrote: ", line); terminal.writeln("You wrote: ", line);
} }
main; // exclude from docs
} }
/++ /++
@ -88,6 +89,7 @@ unittest {
+/ +/
unittest { unittest {
import arsd.terminal; import arsd.terminal;
void main() { void main() {
auto terminal = Terminal(ConsoleOutputType.linear); auto terminal = Terminal(ConsoleOutputType.linear);
terminal.color(Color.green, Color.black); terminal.color(Color.green, Color.black);
@ -95,6 +97,8 @@ unittest {
terminal.color(Color.DEFAULT, Color.DEFAULT); terminal.color(Color.DEFAULT, Color.DEFAULT);
terminal.writeln("And back to normal."); terminal.writeln("And back to normal.");
} }
main; // exclude from docs
} }
/++ /++
@ -105,6 +109,7 @@ unittest {
+/ +/
unittest { unittest {
import arsd.terminal; import arsd.terminal;
void main() { void main() {
auto terminal = Terminal(ConsoleOutputType.linear); auto terminal = Terminal(ConsoleOutputType.linear);
auto input = RealTimeConsoleInput(&terminal, ConsoleInputFlags.raw); auto input = RealTimeConsoleInput(&terminal, ConsoleInputFlags.raw);
@ -113,6 +118,8 @@ unittest {
auto ch = input.getch(); auto ch = input.getch();
terminal.writeln("You pressed ", ch); terminal.writeln("You pressed ", ch);
} }
main; // exclude from docs
} }
/* /*
@ -1587,6 +1594,16 @@ struct RealTimeConsoleInput {
void delegate(InputEvent) userEventHandler; void delegate(InputEvent) userEventHandler;
/++
If you are using [arsd.simpledisplay] and want terminal interop too, you can call
this function to add it to the sdpy event loop and get the callback called on new
input.
Note that you will probably need to call `terminal.flush()` when you are doing doing
output, as the sdpy event loop doesn't know to do that (yet). I will probably change
that in a future version, but it doesn't hurt to call it twice anyway, so I recommend
calling flush yourself in any code you write using this.
+/
void integrateWithSimpleDisplayEventLoop()(void delegate(InputEvent) userEventHandler) { void integrateWithSimpleDisplayEventLoop()(void delegate(InputEvent) userEventHandler) {
this.userEventHandler = userEventHandler; this.userEventHandler = userEventHandler;
import arsd.simpledisplay; import arsd.simpledisplay;