History

move setterm() to kern/posix.c and kern/win32.c (thanks j-xy)

cinap_lenrek committed 8 years ago

Commit fe1f7fa1 parent d06ed885 files · +33 −39Browse files

Unified · Split

5 files
  1. gui-cocoa/screen.m +0 −5
  2. gui-win32/screen.c +0 −18
  3. gui-x11/x11.c +0 −16
  4. kern/posix.c +15 −0
  5. kern/win32.c +18 −0
gui-cocoa/screen.m+0−5
@@ -157,11 +157,6 @@ mouseset(Point p) · 156 unmodified lines
157157 });
158158 }
159159
160−void
161−setterm(int x)
162−{
163−}
164−
165160 @interface AppDelegate : NSObject <NSApplicationDelegate>
166161 @end
167162
gui-win32/screen.c+0−18
@@ -672,24 +672,6 @@ clipwrite(char *buf) · 671 unmodified lines
672672 return n;
673673 }
674674
675−void
676−setterm(int raw)
677−{
678− DWORD mode;
679− HANDLE h;
680−
681− h = GetStdHandle(STD_INPUT_HANDLE);
682− if(!GetConsoleMode(h, &mode))
683− return;
684− if(raw)
685− mode &= ~(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT);
686− else
687− mode |= (ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT);
688− SetConsoleMode(h, mode);
689− FlushConsoleInputBuffer(h);
690− _setmode(0, raw? _O_BINARY: _O_TEXT);
691−}
692−
693675 void
694676 guimain(void)
695677 {
gui-x11/x11.c+0−16
@@ -10,8 +10,6 @@ · 9 unmodified lines
1010 #include <cursor.h>
1111 #include "screen.h"
1212
13−#include <termios.h>
14−
1513 typedef struct Cursor Cursor;
1614
1715 #undef long
@@ -1187,20 +1185,6 @@ clipwrite(char *buf) · 1169 unmodified lines
11871185 return 0;
11881186 }
11891187
1190−void
1191−setterm(int raw)
1192−{
1193− struct termios t;
1194−
1195− if(tcgetattr(0, &t) < 0)
1196− return;
1197− if(raw)
1198− t.c_lflag &= ~(ECHO|ICANON);
1199− else
1200− t.c_lflag |= (ECHO|ICANON);
1201− tcsetattr(0, TCSAFLUSH, &t);
1202−}
1203−
12041188 void
12051189 guimain(void)
12061190 {
kern/posix.c+15−0
@@ -15,6 +15,7 @@ · 14 unmodified lines
1515 #include <signal.h>
1616 #include <pwd.h>
1717 #include <errno.h>
18+#include <termios.h>
1819
1920 #include "lib.h"
2021 #include "dat.h"
@@ -211,3 +212,17 @@ showfilewrite(char *a, int n) · 190 unmodified lines
211212 error("not implemented");
212213 return -1;
213214 }
215+
216+void
217+setterm(int raw)
218+{
219+ struct termios t;
220+
221+ if(tcgetattr(0, &t) < 0)
222+ return;
223+ if(raw)
224+ t.c_lflag &= ~(ECHO|ICANON);
225+ else
226+ t.c_lflag |= (ECHO|ICANON);
227+ tcsetattr(0, TCSAFLUSH, &t);
228+}
kern/win32.c+18−0
@@ -316,3 +316,21 @@ showfilewrite(char *a, int n) · 315 unmodified lines
316316 free(cmd);
317317 return n;
318318 }
319+
320+void
321+setterm(int raw)
322+{
323+ DWORD mode;
324+ HANDLE h;
325+
326+ h = GetStdHandle(STD_INPUT_HANDLE);
327+ if(!GetConsoleMode(h, &mode))
328+ return;
329+ if(raw)
330+ mode &= ~(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT);
331+ else
332+ mode |= (ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT);
333+ SetConsoleMode(h, mode);
334+ FlushConsoleInputBuffer(h);
335+ _setmode(0, raw? _O_BINARY: _O_TEXT);
336+}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t