From: John Hodge (sonata) Date: Sun, 20 Jan 2013 06:29:48 +0000 (+0800) Subject: Usermode/GUITerminal - Progressing, compiles and runs but stubbed X-Git-Tag: rel0.15~598^2~20 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=55ef4dd6e0ce70e703d79129ba66bed63b296e45;p=tpg%2Facess2.git Usermode/GUITerminal - Progressing, compiles and runs but stubbed --- diff --git a/Usermode/Applications/gui_shell_src/Makefile b/Usermode/Applications/gui_shell_src/Makefile index 7ccfff46..a38f1355 100644 --- a/Usermode/Applications/gui_shell_src/Makefile +++ b/Usermode/Applications/gui_shell_src/Makefile @@ -2,9 +2,9 @@ -include ../Makefile.cfg -LDFLAGS += -laxwin3 +LDFLAGS += -laxwin3 -lunicode -OBJ = main.o +OBJ = main.o vt100.o display.o BIN = terminal DIR := Apps/AxWin/3.0 diff --git a/Usermode/Applications/gui_shell_src/display.c b/Usermode/Applications/gui_shell_src/display.c new file mode 100644 index 00000000..750f98de --- /dev/null +++ b/Usermode/Applications/gui_shell_src/display.c @@ -0,0 +1,74 @@ +/* + * Acess GUI Terminal + * - By John Hodge (thePowersGang) + * + * display.c + * - Abstract display manipulation methods + */ +#include "include/display.h" +#include // _SysDebug +#include // exit + +#define UNIMPLIMENTED() do{_SysDebug("UNIMPLIMENTED %s", __func__); exit(-1);}while(0) + +#define MAX_LINES 100 + +// === GLOBALS === + int giCurrentLine; + int giCurrentLinePos; // byte offset, not column + int giCurrentCol; + int giFirstLine; // Ring buffer start +char **gasDisplayLines; + +// === CODE === +void Display_Init(void) +{ + gasDisplayLines = malloc( sizeof(char*) * MAX_LINES ); +} + +void Display_AddText(int Length, const char *UTF8Text) +{ + _SysDebug("%i '%.*s'", Length, Length, UTF8Text); + UNIMPLIMENTED(); +} + +void Display_Newline(int bCarriageReturn) +{ + UNIMPLIMENTED(); +} + +void Display_SetCursor(int Row, int Col) +{ + UNIMPLIMENTED(); +} + +void Display_MoveCursor(int RelRow, int RelCol) +{ + UNIMPLIMENTED(); +} + +void Display_ClearLine(int Dir) // 0: All, 1: Forward, -1: Reverse +{ + UNIMPLIMENTED(); +} + +void Display_ClearLines(int Dir) // 0: All, 1: Forward, -1: Reverse +{ + UNIMPLIMENTED(); +} + +void Display_SetForeground(uint32_t RGB) +{ + UNIMPLIMENTED(); +} + +void Display_SetBackground(uint32_t RGB) +{ + UNIMPLIMENTED(); +} + +void Display_Flush(void) +{ + UNIMPLIMENTED(); +} + diff --git a/Usermode/Applications/gui_shell_src/include/display.h b/Usermode/Applications/gui_shell_src/include/display.h index 80bc69ca..648a2de7 100644 --- a/Usermode/Applications/gui_shell_src/include/display.h +++ b/Usermode/Applications/gui_shell_src/include/display.h @@ -8,6 +8,8 @@ #ifndef _DISPLAY_H_ #define _DISPLAY_H_ +#include + extern void Display_AddText(int Length, const char *UTF8Text); extern void Display_Newline(int bCarriageReturn); extern void Display_SetCursor(int Row, int Col); @@ -16,6 +18,11 @@ extern void Display_ClearLine(int Dir); // 0: All, 1: Forward, -1: Reverse extern void Display_ClearLines(int Dir); // 0: All, 1: Forward, -1: Reverse extern void Display_SetForeground(uint32_t RGB); extern void Display_SetBackground(uint32_t RGB); +/** + * \brief Ensure that recent updates are flushed to the server + * \note Called at the end of an "input" buffer + */ +extern void Display_Flush(void); #endif diff --git a/Usermode/Applications/gui_shell_src/main.c b/Usermode/Applications/gui_shell_src/main.c index c7aac852..3729d702 100644 --- a/Usermode/Applications/gui_shell_src/main.c +++ b/Usermode/Applications/gui_shell_src/main.c @@ -8,14 +8,19 @@ #include #include #include +#include #include +#include #include "include/display.h" #include "include/vt100.h" +#include +#include // === PROTOTYPES === int main(int argc, char *argv[], const char **envp); int Term_KeyHandler(tHWND Window, int bPress, uint32_t KeySym, uint32_t Translated); int Term_MouseHandler(tHWND Window, int bPress, int Button, int Row, int Col); +void Term_HandleOutput(int Len, const char *Buf); // === GLOBALS === tHWND gMainWindow; @@ -55,19 +60,26 @@ int main(int argc, char *argv[], const char **envp) AxWin3_RichText_SendLine(gMainWindow, 2, "Third line! \x01""ff0000A red"); // - AxWin3_ResizeWindow(gMainWindow, 600, 400); - AxWin3_MoveWindow(gMainWindow, 50, 50); + AxWin3_ResizeWindow(gMainWindow, 80*8, 25*16); + AxWin3_MoveWindow(gMainWindow, 20, 50); AxWin3_ShowWindow(gMainWindow, 1); AxWin3_FocusWindow(gMainWindow); // Spawn shell - giChildStdout = open("/Devices/FIFO/anon", O_RDWR); - giChildStdin = open("/Devices/FIFO/anon", O_RDWR); + giChildStdin = _SysOpen("/Devices/fifo/anon", OPENFLAG_READ|OPENFLAG_WRITE); + giChildStdout = _SysOpen("/Devices/fifo/anon", OPENFLAG_READ|OPENFLAG_WRITE); + if( giChildStdout == -1 || giChildStdin == -1 ) { + perror("Oh, fsck"); + _SysDebug("out,in = %i,%i", giChildStdout, giChildStdin); + return -1; + } { int fds[] = {giChildStdin, giChildStdout, giChildStdout}; const char *argv[] = {"CLIShell", NULL}; - _SysSpawn("/Acess/Bin/CLIShell", argv, envp, 3, fds, NULL); + int pid = _SysSpawn("/Acess/Bin/CLIShell", argv, envp, 3, fds, NULL); + if( pid < 0 ) + _SysDebug("ERROR: Shell spawn failed"); } // Main loop @@ -81,9 +93,10 @@ int main(int argc, char *argv[], const char **envp) if( FD_ISSET(giChildStdout, &fds) ) { + _SysDebug("Activity on child stdout"); // Read and update screen char buf[32]; - int len = read(giChildStdout, buf, sizeof(buf)); + int len = _SysRead(giChildStdout, buf, sizeof(buf)); if( len <= 0 ) break; Term_HandleOutput(len, buf); @@ -101,10 +114,10 @@ int Term_KeyHandler(tHWND Window, int bPress, uint32_t KeySym, uint32_t Translat #define _bitset(var,bit,set) do{if(set)var|=1<<(bit);else var&=1<<(bit);}while(0) switch(KeySym) { - case KEY_LCTRL: + case KEYSYM_LEFTCTRL: _bitset(ctrl_state, 0, bPress); return 0; - case KEY_RCTRL: + case KEYSYM_RIGHTCTRL: _bitset(ctrl_state, 0, bPress); return 0; } @@ -112,25 +125,36 @@ int Term_KeyHandler(tHWND Window, int bPress, uint32_t KeySym, uint32_t Translat // Handle shortcuts // - Ctrl-A -- Ctrl-Z - if( ctrl_state && KeySym >= KEY_a && KeySym <= KEY_z ) + if( ctrl_state && KeySym >= KEYSYM_a && KeySym <= KEYSYM_z ) { - Translated = KeySym - KEY_a + 1; + Translated = KeySym - KEYSYM_a + 1; } if( Translated ) { + char buf[6]; + int len; + // Encode and send + len = WriteUTF8(buf, Translated); + + _SysWrite(giChildStdin, buf, len); return 0; } // No translation, look for escape sequences to send + const char *str = NULL; switch(KeySym) { - case KEY_LEFTARROW: - // str = "\x1b[D"; + case KEYSYM_LEFTARROW: + str = "\x1b[D"; break; } + if( str ) + { + _SysWrite(giChildStdin, str, strlen(str)); + } return 0; } @@ -156,5 +180,7 @@ void Term_HandleOutput(int Len, const char *Buf) Len -= esc_len; ofs += esc_len; } + + Display_Flush(); } diff --git a/Usermode/Applications/gui_shell_src/vt100.c b/Usermode/Applications/gui_shell_src/vt100.c index 51c8016f..190f42c1 100644 --- a/Usermode/Applications/gui_shell_src/vt100.c +++ b/Usermode/Applications/gui_shell_src/vt100.c @@ -2,22 +2,28 @@ * Acess GUI Terminal * - By John Hodge (thePowersGang) * - * main.c - * - Core + * vt100.c + * - VT100/xterm Emulation */ #include +#include #include "include/vt100.h" #include "include/display.h" +static inline int min(int a, int b) +{ + return a < b ? a : b; +} + int Term_HandleVT100(int Len, const char *Buf) { - const int max_length = 16; - static char inc_buf[max_length] + #define MAX_VT100_ESCAPE_LEN 16 + static char inc_buf[MAX_VT100_ESCAPE_LEN]; static int inc_len = 0; if( inc_len > 0 || *Buf == '\x1b' ) { - memcpy(inc_buf + inc_len, Buf, min(max_length - inc_len, Len)); + memcpy(inc_buf + inc_len, Buf, min(MAX_VT100_ESCAPE_LEN - inc_len, Len)); // Handle VT100 (like) escape sequence inc_len = 0; @@ -28,16 +34,18 @@ int Term_HandleVT100(int Len, const char *Buf) { case '\b': // TODO: Backspace + Display_MoveCursor(-1, 0); return 1; case '\t': - // TODO: tab + // TODO: tab (get current cursor pos, space until multiple of 8) return 1; case '\n': Display_Newline(1); return 1; case '\r': // TODO: Carriage return - return ; + Display_MoveCursor(INT_MIN, 0); + return 1; } int ret = 0;