module ddhx.tests.input; import std.stdio; import os.terminal; @system unittest { // NOTE: altscreen to get more events! // Terminal emulators will send scrollwheel events terminalInit(TermFeat.rawInput|TermFeat.altScreen); // enables capturing ^C scope(exit) terminalRestore(); terminalResizeHandler(&onresize); // This tests (Phobos') stdout writeln("Exit by CTRL+C"); Lread: TermInput input = terminalRead(); if (input.type == InputType.signal && input.signal == TerminalSignal.interrupted) return; int basekey = input.key; switch (input.type) { case InputType.keyDown: writef( "[TerminalInput] key: type=%s key=%s", cast(InputType)input.type, cast(Key)(basekey & 0xff_ffff) ); if (input.key & Mod.ctrl) write("+ctrl"); if (input.key & Mod.alt) write("+alt"); if (input.key & Mod.shift) write("+shift"); writeln; if (input.key == (Mod.ctrl|Key.C)) return; break; case InputType.mouseDown: writeln("[TerminalInput] mouseDown"); break; case InputType.mouseUp: writeln("[TerminalInput] mouseUp"); break; default: } goto Lread; } void onresize() { TerminalSize size = terminalSize(); writefln("Resized to %dx%d", size.columns, size.rows); }