ref: 850af54157f2fd111576750e2028435de05dbf5f
parent: 94161e0468b38fd44affe58bf000825161df1eb7
author: cinap_lenrek <[email protected]>
date: Sat May 28 20:51:08 EDT 2016
raw mode
--- a/gui-win32/screen.c
+++ b/gui-win32/screen.c
@@ -649,3 +649,21 @@
CloseClipboard();
return n;
}
+
+void
+setterm(int raw)
+{
+ DWORD mode;
+ HANDLE h;
+
+ h = GetStdHandle(STD_INPUT_HANDLE);
+ if(!GetConsoleMode(h, &mode))
+ return;
+ if(raw)
+ mode &= ~(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT);
+ else
+ mode |= (ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT);
+ SetConsoleMode(h, mode);
+ FlushConsoleInputBuffer(h);
+ _setmode(0, raw? _O_BINARY: _O_TEXT);
+}
--- a/gui-x11/x11.c
+++ b/gui-x11/x11.c
@@ -10,6 +10,8 @@
#include <cursor.h>
#include "screen.h"
+#include <termios.h>
+
#define argv0 "drawterm"
typedef struct Cursor Cursor;
@@ -1205,3 +1207,16 @@
return 0;
}
+void
+setterm(int raw)
+{
+ struct termios t;
+
+ if(tcgetattr(0, &t) < 0)
+ return;
+ if(raw)
+ t.c_lflag &= ~(ECHO|ICANON);
+ else
+ t.c_lflag |= (ECHO|ICANON);
+ tcsetattr(0, TCSAFLUSH, &t);
+}
--- a/kern/devcons.c
+++ b/kern/devcons.c
@@ -548,6 +548,8 @@
qlock(&kbd.lk);
if(--kbd.ctl == 0)
kbd.raw = 0;
+ if(screenputs == 0)
+ setterm(kbd.raw);
qunlock(&kbd.lk);
}
break;
@@ -568,7 +570,6 @@
}
}
-
static int
readcons(Queue *q, char *buf, int n)
{
@@ -776,11 +777,15 @@
kbd.x = 0;
}
kbd.raw = 1;
+ if(screenputs == 0)
+ setterm(1);
qunlock(&kbd.lk);
} else if(strncmp(a, "rawoff", 6) == 0){
qlock(&kbd.lk);
kbd.raw = 0;
kbd.x = 0;
+ if(screenputs == 0)
+ setterm(0);
qunlock(&kbd.lk);
} else if(strncmp(a, "ctlpon", 6) == 0){
kbd.ctlpoff = 0;
--- a/kern/fns.h
+++ b/kern/fns.h
@@ -381,4 +381,5 @@
void osinit(void);
void screeninit(void);
extern void terminit(void);
+extern void settierm(int raw);