aboutsummaryrefslogtreecommitdiff
path: root/src/cInput.cpp
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2019-05-06 18:18:32 +0200
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2019-05-06 18:18:32 +0200
commit99107be8a997eb453b989e1b31123708685696dc (patch)
tree3e822201c2662097ac7c294596e15395de5ab96c /src/cInput.cpp
parent3fec03eeaa7dbe5152255ebdc0aae9841c241565 (diff)
downloadtermgl-99107be8a997eb453b989e1b31123708685696dc.tar.gz
Changed color handling to take ANSI 8bit colors
added ansi_color_fg(R,G,B) and ..._bg(...) to generate ANSI-colors from RGB values replaced two spaces with tabs in every file to fix terrible tabbing (thanks atom...)
Diffstat (limited to 'src/cInput.cpp')
-rw-r--r--src/cInput.cpp110
1 files changed, 55 insertions, 55 deletions
diff --git a/src/cInput.cpp b/src/cInput.cpp
index 32da417..891be1f 100644
--- a/src/cInput.cpp
+++ b/src/cInput.cpp
@@ -2,73 +2,73 @@
cInput::cInput()
{
- // Save original serial communication configuration for stdin
- tcgetattr( STDIN_FILENO, &original);
+ // Save original serial communication configuration for stdin
+ tcgetattr( STDIN_FILENO, &original);
- // Put stdin in raw mode so keys get through directly without
- // requiring pressing enter.
- cfmakeraw (&raw);
- tcsetattr (STDIN_FILENO, TCSANOW, &raw);
+ // Put stdin in raw mode so keys get through directly without
+ // requiring pressing enter.
+ cfmakeraw (&raw);
+ tcsetattr (STDIN_FILENO, TCSANOW, &raw);
- // Enable mouse tracking
- write (STDOUT_FILENO, "\e[?1000h", 8);
+ // Enable mouse tracking
+ write (STDOUT_FILENO, "\e[?1000h", 8);
}
cInput::~cInput()
{
- //revert changes to console
- write (STDOUT_FILENO, "\e[?1000l", 8);
- tcsetattr (STDIN_FILENO, TCSANOW, &original);
+ //revert changes to console
+ write (STDOUT_FILENO, "\e[?1000l", 8);
+ tcsetattr (STDIN_FILENO, TCSANOW, &original);
}
sInputEvent cInput::poll()
{
- const unsigned int buff_len = 5;
- sInputEvent ret;
- unsigned char buff [buff_len];
+ const unsigned int buff_len = 5;
+ sInputEvent ret;
+ unsigned char buff [buff_len];
- //setup for select
- fd_set rfds;
- struct timeval tv;
- FD_ZERO(&rfds);
- FD_SET(STDIN_FILENO, &rfds);
- tv.tv_sec = 0;
- tv.tv_usec = 0;
+ //setup for select
+ fd_set rfds;
+ struct timeval tv;
+ FD_ZERO(&rfds);
+ FD_SET(STDIN_FILENO, &rfds);
+ tv.tv_sec = 0;
+ tv.tv_usec = 0;
- ret.type = _EVENT_NULL;
+ ret.type = _EVENT_NULL;
- //Check for Input. return of none
- if(!select(1, &rfds, NULL, NULL, &tv))
- return ret;
+ //Check for Input. return of none
+ if(!select(1, &rfds, NULL, NULL, &tv))
+ return ret;
- read (STDIN_FILENO, &buff, 1);
- if (buff[0] == 3) {
- // User pressd Ctr+C
- ret.type = _EVENT_TERM;
- }
- else if (buff[0] == '\x1B') //Escape sequence
- {
- read (STDIN_FILENO, &buff, buff_len);
- if(buff[0] == '[')
- {
- if(buff[1] == 'M') //Mouse Event
- {
- ret.b = buff[2] - 32;
- ret.x = buff[3] - 32 - 1; //Console sees origin at 1,1
- ret.y = buff[4] - 32 - 1; //Program at 0,0
- ret.type = _EVENT_MOUSE;
- }
- else //e.g. Arrow Keys
- {
- ret.c = buff[1];
- ret.type = _EVENT_KEY;
- }
- }
- }
- else
- {
- ret.type = _EVENT_CHAR;
- ret.c = buff[0];
- }
- return ret;
+ read (STDIN_FILENO, &buff, 1);
+ if (buff[0] == 3) {
+ // User pressd Ctr+C
+ ret.type = _EVENT_TERM;
+ }
+ else if (buff[0] == '\x1B') //Escape sequence
+ {
+ read (STDIN_FILENO, &buff, buff_len);
+ if(buff[0] == '[')
+ {
+ if(buff[1] == 'M') //Mouse Event
+ {
+ ret.b = buff[2] - 32;
+ ret.x = buff[3] - 32 - 1; //Console sees origin at 1,1
+ ret.y = buff[4] - 32 - 1; //Program at 0,0
+ ret.type = _EVENT_MOUSE;
+ }
+ else //e.g. Arrow Keys
+ {
+ ret.c = buff[1];
+ ret.type = _EVENT_KEY;
+ }
+ }
+ }
+ else
+ {
+ ret.type = _EVENT_CHAR;
+ ret.c = buff[0];
+ }
+ return ret;
}