shithub: drawterm

Download patch

ref: fe1f7fac39b177bc4f3b3b8d39034c23be447f4e
parent: d06ed886c61c93037129a6693ab3db07c070f291
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Wed Oct 3 13:29:18 EDT 2018

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

--- a/gui-cocoa/screen.m	Wed Sep 12 03:29:20 2018
+++ b/gui-cocoa/screen.m	Wed Oct  3 13:29:18 2018
@@ -157,11 +157,6 @@
 	});
 }
 
-void
-setterm(int x)
-{
-}
-
 @interface AppDelegate : NSObject <NSApplicationDelegate>
 @end
 
--- a/gui-win32/screen.c	Wed Sep 12 03:29:20 2018
+++ b/gui-win32/screen.c	Wed Oct  3 13:29:18 2018
@@ -673,24 +673,6 @@
 }
 
 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);
-}
-
-void
 guimain(void)
 {
 	cpubody();
--- a/gui-x11/x11.c	Wed Sep 12 03:29:20 2018
+++ b/gui-x11/x11.c	Wed Oct  3 13:29:18 2018
@@ -10,8 +10,6 @@
 #include <cursor.h>
 #include "screen.h"
 
-#include <termios.h>
-
 typedef struct Cursor Cursor;
 
 #undef	long
@@ -1185,20 +1183,6 @@
 {
 	_xputsnarf(xsnarfcon, buf);
 	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);
 }
 
 void
--- a/kern/posix.c	Wed Sep 12 03:29:20 2018
+++ b/kern/posix.c	Wed Oct  3 13:29:18 2018
@@ -15,6 +15,7 @@
 #include <signal.h>
 #include <pwd.h>
 #include <errno.h>
+#include <termios.h>
 
 #include "lib.h"
 #include "dat.h"
@@ -210,4 +211,18 @@
 {
 	error("not implemented");
 	return -1;
+}
+
+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/win32.c	Wed Sep 12 03:29:20 2018
+++ b/kern/win32.c	Wed Oct  3 13:29:18 2018
@@ -316,3 +316,21 @@
 	free(cmd);
 	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);
+}