3 * - By John Hodge (thePowersGang)
8 #include <axwin3/axwin.h>
9 #include <axwin3/menu.h>
10 #include <axwin3/richtext.h>
11 #include <axwin3/keysyms.h>
13 #include <acess/sys.h>
14 #include "include/display.h"
15 #include "include/vt100.h"
20 int main(int argc, char *argv[], const char **envp);
21 int Term_KeyHandler(tHWND Window, int bPress, uint32_t KeySym, uint32_t Translated);
22 int Term_MouseHandler(tHWND Window, int bPress, int Button, int Row, int Col);
23 void Term_HandleOutput(int Len, const char *Buf);
32 int main(int argc, char *argv[], const char **envp)
36 // --- Build up window
37 gMainWindow = AxWin3_RichText_CreateWindow(NULL, 0);
38 AxWin3_SetWindowTitle(gMainWindow, "Terminal"); // TODO: Update title with other info
40 gMenuWindow = AxWin3_Menu_Create(gMainWindow);
41 AxWin3_Menu_AddItem(gMenuWindow, "Copy\tWin+C", NULL, NULL, 0, NULL);
42 AxWin3_Menu_AddItem(gMenuWindow, "Paste\tWin+V", NULL, NULL, 0, NULL);
43 // TODO: Populate menu
48 AxWin3_RichText_SetKeyHandler (gMainWindow, Term_KeyHandler);
49 AxWin3_RichText_SetMouseHandler (gMainWindow, Term_MouseHandler);
50 AxWin3_RichText_SetDefaultColour(gMainWindow, 0xFFFFFF);
51 AxWin3_RichText_SetBackground (gMainWindow, 0x000000);
52 AxWin3_RichText_SetFont (gMainWindow, "#monospace", 10);
53 AxWin3_RichText_SetCursorPos (gMainWindow, 0, 0);
54 AxWin3_RichText_SetCursorType (gMainWindow, AXWIN3_RICHTEXT_CURSOR_INV);
55 AxWin3_RichText_SetCursorBlink (gMainWindow, 1);
58 AxWin3_RichText_SetLineCount(gMainWindow, 3);
59 AxWin3_RichText_SendLine(gMainWindow, 0, "First line!");
60 AxWin3_RichText_SendLine(gMainWindow, 2, "Third line! \x01""ff0000A red");
63 AxWin3_ResizeWindow(gMainWindow, 80*8, 25*16);
64 AxWin3_MoveWindow(gMainWindow, 20, 50);
65 AxWin3_ShowWindow(gMainWindow, 1);
66 AxWin3_FocusWindow(gMainWindow);
69 giChildStdin = _SysOpen("/Devices/fifo/anon", OPENFLAG_READ|OPENFLAG_WRITE);
70 giChildStdout = _SysOpen("/Devices/fifo/anon", OPENFLAG_READ|OPENFLAG_WRITE);
71 if( giChildStdout == -1 || giChildStdin == -1 ) {
73 _SysDebug("out,in = %i,%i", giChildStdout, giChildStdin);
78 int fds[] = {giChildStdin, giChildStdout, giChildStdout};
79 const char *argv[] = {"CLIShell", NULL};
80 int pid = _SysSpawn("/Acess/Bin/CLIShell", argv, envp, 3, fds, NULL);
82 _SysDebug("ERROR: Shell spawn failed");
91 FD_SET(giChildStdout, &fds);
92 AxWin3_MessageSelect(giChildStdout + 1, &fds);
94 if( FD_ISSET(giChildStdout, &fds) )
96 _SysDebug("Activity on child stdout");
97 // Read and update screen
99 int len = _SysRead(giChildStdout, buf, sizeof(buf));
100 if( len <= 0 ) break;
102 Term_HandleOutput(len, buf);
109 int Term_KeyHandler(tHWND Window, int bPress, uint32_t KeySym, uint32_t Translated)
111 static int ctrl_state = 0;
114 #define _bitset(var,bit,set) do{if(set)var|=1<<(bit);else var&=1<<(bit);}while(0)
117 case KEYSYM_LEFTCTRL:
118 _bitset(ctrl_state, 0, bPress);
120 case KEYSYM_RIGHTCTRL:
121 _bitset(ctrl_state, 0, bPress);
127 // - Ctrl-A -- Ctrl-Z
128 if( ctrl_state && KeySym >= KEYSYM_a && KeySym <= KEYSYM_z )
130 Translated = KeySym - KEYSYM_a + 1;
139 len = WriteUTF8(buf, Translated);
141 _SysWrite(giChildStdin, buf, len);
146 // No translation, look for escape sequences to send
147 const char *str = NULL;
150 case KEYSYM_LEFTARROW:
156 _SysWrite(giChildStdin, str, strlen(str));
161 int Term_MouseHandler(tHWND Window, int bPress, int Button, int Row, int Col)
166 void Term_HandleOutput(int Len, const char *Buf)
168 // TODO: Handle graphical / accelerated modes
175 esc_len = Term_HandleVT100(Len - ofs, Buf + ofs);
177 Display_AddText(-esc_len, Buf + ofs);