[PATCH 2/7] [WineConsole]: in line mode, save (resp restore) terminal settings upon startup (resp exit)
Eric Pouech
eric.pouech at orange.fr
Sat Dec 29 09:21:23 CST 2012
A+
---
programs/wineconsole/line.c | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/programs/wineconsole/line.c b/programs/wineconsole/line.c
index 630acaf..f755b7b 100644
--- a/programs/wineconsole/line.c
+++ b/programs/wineconsole/line.c
@@ -31,6 +31,9 @@
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
+#ifdef HAVE_TERMIOS_H
+# include <termios.h>
+#endif
#include <windef.h>
#include <winbase.h>
#include <winnls.h>
@@ -48,6 +51,7 @@ struct inner_data_line
int sync_pipe[2];
HANDLE input_thread;
CRITICAL_SECTION lock;
+ struct termios termios;
};
/******************************************************************
@@ -249,6 +253,8 @@ static void WCLINE_DeleteBackend(struct inner_data* data)
{
if (!PRIVATE(data)) return;
+ /* restore initial termios settings */
+ tcsetattr(0, TCSANOW, &PRIVATE(data)->termios);
if (PRIVATE(data)->input_thread)
{
close(PRIVATE(data)->sync_pipe[1]);
@@ -269,11 +275,23 @@ static void WCLINE_DeleteBackend(struct inner_data* data)
*/
static int WCLINE_MainLoop(struct inner_data* data)
{
- DWORD id;
+ DWORD id;
+ struct termios term;
WCLINE_Resize(data);
if (pipe(PRIVATE(data)->sync_pipe) == -1) return 0;
+
+ /* put console into raw mode */
+ term = PRIVATE(data)->termios;
+ term.c_lflag &= ~(ECHO | ECHONL | ICANON | IEXTEN);
+ term.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
+ term.c_cflag &= ~(CSIZE | PARENB);
+ term.c_cflag |= CS8;
+ term.c_cc[VMIN] = 1;
+ term.c_cc[VTIME] = 0;
+ if (tcsetattr(0, TCSANOW, &term) == -1) return 0;
+
PRIVATE(data)->input_thread = CreateThread(NULL, 0, input_thread, data, 0, &id);
while (!data->dying && WaitForSingleObject(data->hSynchro, INFINITE) == WAIT_OBJECT_0)
@@ -315,6 +333,8 @@ enum init_return WCLINE_InitBackend(struct inner_data* data)
InitializeCriticalSection(&PRIVATE(data)->lock);
PRIVATE(data)->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": line");
+ /* save initial termios settings */
+ if (tcgetattr(0, &PRIVATE(data)->termios) == -1) return 0;
return init_success;
}
More information about the wine-patches
mailing list