From 8ca18a718af411a8391be8629e1201983044a88f Mon Sep 17 00:00:00 2001 From: "John Hodge (sonata)" Date: Sun, 20 Jan 2013 17:24:16 +0800 Subject: [PATCH] Usermode/GUITerminal - Now can show shell --- Usermode/Applications/gui_shell_src/display.c | 164 +++++++++++++++++- .../gui_shell_src/include/display.h | 9 +- Usermode/Applications/gui_shell_src/main.c | 5 +- 3 files changed, 168 insertions(+), 10 deletions(-) diff --git a/Usermode/Applications/gui_shell_src/display.c b/Usermode/Applications/gui_shell_src/display.c index 750f98de..4972ed13 100644 --- a/Usermode/Applications/gui_shell_src/display.c +++ b/Usermode/Applications/gui_shell_src/display.c @@ -8,33 +8,131 @@ #include "include/display.h" #include // _SysDebug #include // exit +#include +#include +#include +#include +#include #define UNIMPLIMENTED() do{_SysDebug("UNIMPLIMENTED %s", __func__); exit(-1);}while(0) -#define MAX_LINES 100 +// === EXTERN == +extern tHWND gMainWindow; // === GLOBALS === + int giDisplayCols; + int giDisplayLines; + int giDisplayTotalLines; + int giDisplayBufSize; int giCurrentLine; int giCurrentLinePos; // byte offset, not column int giCurrentCol; + int giFirstDispLine; // First displayed line int giFirstLine; // Ring buffer start char **gasDisplayLines; + int *gaiDisplayLineSizes; +char *gabDisplayLinesDirty; // === CODE === -void Display_Init(void) +void Display_Init(int Cols, int Lines, int ExtraScrollbackLines) { - gasDisplayLines = malloc( sizeof(char*) * MAX_LINES ); + giDisplayCols = Cols; + giDisplayLines = Lines; + giDisplayTotalLines = Lines + ExtraScrollbackLines; + gasDisplayLines = calloc( sizeof(char*), (Lines + ExtraScrollbackLines) ); + gaiDisplayLineSizes = calloc( sizeof(int), (Lines + ExtraScrollbackLines) ); + gabDisplayLinesDirty = calloc( sizeof(char), (Lines + ExtraScrollbackLines) ); +} + +void Display_int_PushString(int Length, const char *Text) +{ + _SysDebug("Line %i += %i '%*C'", giCurrentLine, Length, Length, Text); + if( !gasDisplayLines[giCurrentLine] || giCurrentLinePos + Length >= gaiDisplayLineSizes[giCurrentLine] ) + { + int reqsize = giCurrentLinePos + Length; + gaiDisplayLineSizes[giCurrentLine] = (reqsize + 32-1) & ~(32-1); + void *tmp = realloc(gasDisplayLines[giCurrentLine], gaiDisplayLineSizes[giCurrentLine]); + if( !tmp ) perror("Display_AddText - realloc"); + gasDisplayLines[giCurrentLine] = tmp; + } + + memcpy(gasDisplayLines[giCurrentLine]+giCurrentLinePos, Text, Length); + gabDisplayLinesDirty[giCurrentLine] = 1; + gasDisplayLines[giCurrentLine][giCurrentLinePos+Length] = 0; + } void Display_AddText(int Length, const char *UTF8Text) { _SysDebug("%i '%.*s'", Length, Length, UTF8Text); - UNIMPLIMENTED(); + // Copy as many characters (not bytes, have to trim off the last char) as we can to the current line + // - then roll over to the next line + while( Length > 0 ) + { + int space = giDisplayCols - giCurrentCol; + int bytes = 0; + while( space && bytes < Length ) + { + uint32_t cp; + bytes += ReadUTF8(UTF8Text+bytes, &cp); + if( Unicode_IsPrinting(cp) ) + space --; + } + + Display_int_PushString(bytes, UTF8Text); + + UTF8Text += bytes; + _SysDebug("Length(%i) -= bytes(%i)", Length, bytes); + Length -= bytes; + if( Length != 0 ) + { + // Next line + giCurrentLinePos = 0; + giCurrentCol = 0; + giCurrentLine ++; + } + } } void Display_Newline(int bCarriageReturn) { - UNIMPLIMENTED(); + Display_Flush(); + + // Going down! + giCurrentLine ++; + if( giCurrentLine == giDisplayLines ) + giCurrentLine = 0; + if( giCurrentLine == giFirstLine ) + { + giFirstLine ++; + if(giFirstLine == giDisplayLines) + giFirstLine = 0; + } + + if( bCarriageReturn ) { + giCurrentLinePos = 0; + giCurrentCol = 0; + } + else { + giCurrentLinePos = 0; + int i = giCurrentCol; + if( !gasDisplayLines[giCurrentLine] ) + { + giCurrentCol = 0; + while(i--) + Display_AddText(1, " "); + } + else + { + while( i -- ) + { + uint32_t cp; + giCurrentLinePos += ReadUTF8(gasDisplayLines[giCurrentLine]+giCurrentLinePos, &cp); + if( !Unicode_IsPrinting(cp) ) + i ++; + } + } + } } void Display_SetCursor(int Row, int Col) @@ -49,12 +147,47 @@ void Display_MoveCursor(int RelRow, int RelCol) void Display_ClearLine(int Dir) // 0: All, 1: Forward, -1: Reverse { - UNIMPLIMENTED(); + if( Dir == 0 ) + { + // Completely clear line + if( gasDisplayLines[giCurrentLine] ) + free(gasDisplayLines[giCurrentLine]); + gasDisplayLines[giCurrentLine] = NULL; + gabDisplayLinesDirty[giCurrentLine] = 1; + } + else if( Dir == 1 ) + { + // Forward clear (truncate) + } + else if( Dir == -1 ) + { + // Reverse clear (replace with spaces) + } + else + { + // BUGCHECK + } } void Display_ClearLines(int Dir) // 0: All, 1: Forward, -1: Reverse { - UNIMPLIMENTED(); + if( Dir == 0 ) + { + // Push giDisplayLines worth of empty lines + // Move cursor back up by giDisplayLines + } + else if( Dir == 1 ) + { + // Push (giDisplayLines - (giCurrentLine-giFirstDispLine)) and reverse + } + else if( Dir == -1 ) + { + // Reverse clear (replace with spaces) + } + else + { + // BUGCHECK + } } void Display_SetForeground(uint32_t RGB) @@ -68,6 +201,23 @@ void Display_SetBackground(uint32_t RGB) } void Display_Flush(void) +{ + int i; + for( i = 0; i < giDisplayCols; i ++ ) + { + int line = (giFirstLine + i) % giDisplayTotalLines; + if( !gabDisplayLinesDirty[line] ) + continue; + _SysDebug("Line %i+%i '%s'", giFirstLine, i, gasDisplayLines[line]); + AxWin3_RichText_SendLine(gMainWindow, giFirstLine + i, gasDisplayLines[line] ); + gabDisplayLinesDirty[line] = 0; + } + + // force redraw? + AxWin3_FocusWindow(gMainWindow); +} + +void Display_ShowAltBuffer(int AltBufEnabled) { UNIMPLIMENTED(); } diff --git a/Usermode/Applications/gui_shell_src/include/display.h b/Usermode/Applications/gui_shell_src/include/display.h index 648a2de7..4feaf352 100644 --- a/Usermode/Applications/gui_shell_src/include/display.h +++ b/Usermode/Applications/gui_shell_src/include/display.h @@ -3,13 +3,15 @@ * - By John Hodge (thePowersGang) * * display.h - * - RichText Termianl Translation + * - RichText terminal translation */ #ifndef _DISPLAY_H_ #define _DISPLAY_H_ #include +extern void Display_Init(int Cols, int Lines, int ExtraScrollbackLines); + extern void Display_AddText(int Length, const char *UTF8Text); extern void Display_Newline(int bCarriageReturn); extern void Display_SetCursor(int Row, int Col); @@ -24,5 +26,10 @@ extern void Display_SetBackground(uint32_t RGB); */ extern void Display_Flush(void); +/** + * \brief Switch the display to the alternate buffer (no scrollback) + */ +extern void Display_ShowAltBuffer(int AltBufEnabled); + #endif diff --git a/Usermode/Applications/gui_shell_src/main.c b/Usermode/Applications/gui_shell_src/main.c index 3729d702..1c748b32 100644 --- a/Usermode/Applications/gui_shell_src/main.c +++ b/Usermode/Applications/gui_shell_src/main.c @@ -57,9 +57,10 @@ int main(int argc, char *argv[], const char **envp) // AxWin3_RichText_SetLineCount(gMainWindow, 3); AxWin3_RichText_SendLine(gMainWindow, 0, "First line!"); - AxWin3_RichText_SendLine(gMainWindow, 2, "Third line! \x01""ff0000A red"); + AxWin3_RichText_SendLine(gMainWindow, 2, "Third line! \1ff0000A red"); // + Display_Init(80, 25, 100); AxWin3_ResizeWindow(gMainWindow, 80*8, 25*16); AxWin3_MoveWindow(gMainWindow, 20, 50); AxWin3_ShowWindow(gMainWindow, 1); @@ -177,8 +178,8 @@ void Term_HandleOutput(int Len, const char *Buf) Display_AddText(-esc_len, Buf + ofs); esc_len = -esc_len; } - Len -= esc_len; ofs += esc_len; + _SysDebug("Len = %i, ofs = %i", Len, ofs); } Display_Flush(); -- 2.20.1