From a43aba4e589d14330faa724bed23ad32379540e1 Mon Sep 17 00:00:00 2001 From: "Adam D. Ruppe" Date: Thu, 10 Apr 2014 21:24:04 -0400 Subject: [PATCH] rewrite getch in terms of the event system --- terminal.d | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/terminal.d b/terminal.d index ae9231a..159e039 100644 --- a/terminal.d +++ b/terminal.d @@ -1264,11 +1264,16 @@ struct RealTimeConsoleInput { } } - /// Get one character from the terminal - char getch() { - terminal.flush(); - import core.stdc.stdio; - return cast(char) fgetc(stdin); + /// Get one character from the terminal, discarding other + /// events in the process. + dchar getch() { + auto event = nextEvent(); + while(event.type != InputEvent.Type.CharacterEvent) { + if(event.type == InputEvent.Type.UserInterruptionEvent) + throw new Exception("Ctrl+c"); + event = nextEvent(); + } + return event.characterEvent.character; } //char[128] inputBuffer;