reorganising and screen clearing and whatnot

This commit is contained in:
2020-02-07 23:44:33 -08:00
parent ee653ade34
commit 7e837ca751
6 changed files with 116 additions and 36 deletions

40
main.c
View File

@@ -5,6 +5,8 @@
#include <termios.h>
#include <unistd.h>
#include "display.h"
#include "keys.h"
#include "terminal.h"
#include "util.h"
@@ -12,42 +14,8 @@
void
loop()
{
char c;
int command = 0;
while (1) {
c = '\0';
/*
* Note that Cygwin, apparently, will treat a read time-
* out as an error with errno == EAGAIN. I don't really
* have any interest in supporting code for Cygwin.
*/
if ((read(STDIN_FILENO, &c, 1) == -1)) {
die("failed to read from the terminal");
}
if (c == 0x00) {
continue;
}
if (command && ((c == 'q') || (c == 0x11))) {
break;
}
if (c == 0x0b) {
if (!command) {
command = 1;
continue;
}
} else {
command = 0;
}
if (iscntrl(c)) {
printf("%02x\r\n", c);
} else {
printf("%02x ('%c')\r\n", c, c);
}
process_keypress();
}
}
@@ -56,6 +24,8 @@ int
main()
{
setup_terminal();
display_clear();
loop();
return 0;