From 299c4151d9e41db8eacd6fe0187e41c37ce2128c Mon Sep 17 00:00:00 2001 From: John Hodge Date: Wed, 21 May 2014 23:21:57 +0800 Subject: [PATCH] Usermode/irc - Fix pointer mismatch printing new messages --- Usermode/Applications/irc_src/pseudo_curses.c | 59 ++++++++++++++++--- Usermode/Applications/irc_src/window.c | 6 +- 2 files changed, 56 insertions(+), 9 deletions(-) diff --git a/Usermode/Applications/irc_src/pseudo_curses.c b/Usermode/Applications/irc_src/pseudo_curses.c index bdcb3cf9..23ee1371 100644 --- a/Usermode/Applications/irc_src/pseudo_curses.c +++ b/Usermode/Applications/irc_src/pseudo_curses.c @@ -1,26 +1,71 @@ /* */ #include "pseudo_curses.h" +#include #include #include #include +// === PROTOTYPES === +bool ACurses_GetDims_Acess(void); +bool ACurses_GetDims_SerialTermHack(void); + +// === GLOBALS === int giTerminal_Width = 80; int giTerminal_Height = 25; +// === CODE === void ACurses_Init(void) { - if( _SysIOCtl(1, DRV_IOCTL_TYPE, NULL) != DRV_TYPE_TERMINAL ) { + if( ACurses_GetDims_Acess() ) { + } + else if( ACurses_GetDims_SerialTermHack() ) { + } + else { _SysDebug("note: assuming 80x25, can't get terminal dimensions"); giTerminal_Width = 80; giTerminal_Height = 25; } - else { - struct ptydims dims; - _SysIOCtl(1, PTY_IOCTL_GETDIMS, &dims); - giTerminal_Width = dims.W; - giTerminal_Height = dims.H; - } +} + +bool ACurses_GetDims_Acess(void) +{ + if( _SysIOCtl(1, DRV_IOCTL_TYPE, NULL) != DRV_TYPE_TERMINAL ) + return false; + + struct ptydims dims; + if( _SysIOCtl(1, PTY_IOCTL_GETDIMS, &dims) == -1 ) + return false; + giTerminal_Width = dims.W; + giTerminal_Height = dims.H; + return true; +} + +bool ACurses_GetDims_SerialTermHack(void) +{ + _SysDebug("ACurses_GetDims_SerialTermHack: Trying"); + // Set cursor to 1000,1000 , request cursor position, reset cursor to 0,0 + static const char req[] = "\033[1000;1000H\033[6n\033[H"; + fflush(stdin); + _SysWrite(1, req, sizeof(req)); + int64_t timeout = 1000; + fd_set fds; + FD_ZERO(&fds); + FD_SET(0, &fds); + _SysSelect(1, &fds, NULL, NULL, &timeout, 0); + if( !FD_ISSET(0, &fds) ) + return false; + + if( fgetc(stdin) != '\x1b' ) + return false; + if( fgetc(stdin) != '[' ) + return false; + if( fscanf(stdin, "%i;%i", &giTerminal_Width, &giTerminal_Height) != 2 ) + return false; + if( fgetc(stdin) != 'R' ) + return false; + + return true; } void SetCursorPos(int Row, int Col) diff --git a/Usermode/Applications/irc_src/window.c b/Usermode/Applications/irc_src/window.c index db3e4da8..48daeb5c 100644 --- a/Usermode/Applications/irc_src/window.c +++ b/Usermode/Applications/irc_src/window.c @@ -141,7 +141,9 @@ size_t Windows_int_PaintMessagePrefix(const tMessage *Message, bool EnablePrint) size_t Windows_int_PaintMessageLine(const tMessage *Message, size_t Offset, bool EnablePrint) { - if( Message->Data[Offset] == '\0' ) { + _SysDebug("Windows_int_PaintMessageLine: Message=%p,Offset=%zi, EnablePrint=%b", + Message, Offset, EnablePrint); + if( Offset > strlen(Message->Data) ) { return 0; } @@ -308,7 +310,7 @@ void Window_AppendMessage(tWindow *Window, enum eMessageClass Class, const char do { printf("\33[T"); // Scroll down 1 (free space below) SetCursorPos(giTerminal_Height-2, 1); - len = Windows_int_PaintMessageLine(Message, offset, true); + len = Windows_int_PaintMessageLine(msg, offset, true); offset += len; } while( len > 0 ); printf("\33[u"); // Restore cursor -- 2.20.1