From 3cfea2815e3edfeb15fd7f0173957254babc7326 Mon Sep 17 00:00:00 2001 From: jonas Date: Thu, 27 Dec 2018 11:35:34 +0100 Subject: Added _EVENT_TERM to cInput _EVENT_TERM is returned when Cmd + C is pressed --- cInput.cpp | 7 +++++-- cInput.h | 1 + main.cpp | 6 ++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/cInput.cpp b/cInput.cpp index 2a6e11c..a862127 100644 --- a/cInput.cpp +++ b/cInput.cpp @@ -45,8 +45,11 @@ sInputEvent cInput::poll() return ret; read (STDIN_FILENO, &buff, 1); - - if (buff[0] == '\x1B') //Escape sequence + if (buff[0] == 3) { + // User pressd Ctr+C + ret.type = _EVENT_TERM; + } + else if (buff[0] == '\x1B') //Escape sequence { read (STDIN_FILENO, &buff, 5); if(buff[0] == '[') diff --git a/cInput.h b/cInput.h index 8e3481c..9ff2041 100644 --- a/cInput.h +++ b/cInput.h @@ -23,6 +23,7 @@ #define _EVENT_CHAR 1 #define _EVENT_KEY 2 #define _EVENT_MOUSE 3 +#define _EVENT_TERM 4 struct sInputEvent { diff --git a/main.cpp b/main.cpp index f0f6f50..786194a 100644 --- a/main.cpp +++ b/main.cpp @@ -42,10 +42,16 @@ int main() pos.x = ie.x; pos.y = ie.y; } + else if (ie.type == _EVENT_TERM) + { + return 0; + } a.clear(); a.drawPoint('X', pos, true, _COL_GREEN); a.render(); + + usleep(10*1000); } } -- cgit v1.2.3