3 * - By John Hodge (thePowersGang)
8 #include <axwin3/axwin.h>
9 #include <axwin3/menu.h>
10 #include <axwin3/richtext.h>
12 #include "include/display.h"
15 int main(int argc, char *argv[]);
16 int Term_KeyHandler(tHWND Window, int bPress, uint32_t KeySym, uint32_t Translated);
17 int Term_MouseHandler(tHWND Window, int bPress, uint32_t KeySym, uint32_t Translated);
26 int main(int argc, char *argv[])
30 // --- Build up window
31 gMainWindow = AxWin3_RichText_CreateWindow(NULL, 0);
32 AxWin3_SetWindowTitle(gMainWindow, "Terminal"); // TODO: Update title with other info
34 gMenuWindow = AxWin3_Menu_Create(gMainWindow);
35 AxWin3_Menu_AddItem(gMenuWindow, "Copy\tWin+C", NULL, NULL, NULL, 0);
36 AxWin3_Menu_AddItem(gMenuWindow, "Paste\tWin+V", NULL, NULL, NULL, 0);
37 // TODO: Populate menu
42 AxWin3_RichText_SetKeyHandler (gMainWindow, Term_KeyHandler);
43 AxWin3_RichText_SetMouseHandler (gMainWindow, Term_MouseHandler);
44 AxWin3_RichText_SetDefaultColour(gMainWindow, 0xFFFFFF);
45 AxWin3_RichText_SetBackground (gMainWindow, 0x000000);
46 AxWin3_RichText_SetFont (gMainWindow, "#monospace", 10);
47 AxWin3_RichText_SetCursorPos (gMainWindow, 0, 0);
48 AxWin3_RichText_SetCursorType (gMainWindow, AXWIN3_RICHTEXT_CURSOR_INV);
49 AxWin3_RichText_SetCursorBlink (gMainWindow, 1);
52 AxWin3_RichText_SetLineCount(gMainWindow, 3);
53 AxWin3_RichText_SendLine(gMainWindow, 0, "First line!");
54 AxWin3_RichText_SendLine(gMainWindow, 2, "Third line! \x01""ff0000A red");
57 AxWin3_ResizeWindow(gMainWindow, 600, 400);
58 AxWin3_MoveWindow(gMainWindow, 50, 50);
59 AxWin3_ShowWindow(gMainWindow, 1);
60 AxWin3_FocusWindow(gMainWindow);
63 giChildStdout = open("/Devices/FIFO/anon", O_RDWR);
64 giChildStdin = open("/Devices/FIFO/anon", O_RDWR);
67 int fds[] = {giChildStdin, giChildStdout, giChildStdout};
68 const char *argv[] = {"CLIShell", NULL};
69 _SysSpawn("/Acess/Bin/CLIShell", argv, envp, 3, fds, NULL);
78 FD_SET(&fds, giChildStdout);
79 AxWin3_MessageSelect(giChildStdout + 1, &fds);
81 if( FD_ISSET(&fds, giChildStdout) )
83 // Read and update screen
85 len = read(giChildStdout, sizeof(buf), buf);
88 //Term_HandleOutput(len, buf);
95 int Term_KeyHandler(tHWND Window, int bPress, uint32_t KeySym, uint32_t Translated)
97 static int ctrl_state = 0;
100 #define _bitset(var,bit,set) do{if(set)var|=1<<(bit);else var&=1<<(bit);}while(0)
104 _bitset(ctrl_state, 0, bPress);
107 _bitset(ctrl_state, 0, bPress);
113 // - Ctrl-A -- Ctrl-Z
114 if( ctrl_state && KeySym >= KEY_a && KeySym <= KEY_z )
116 Translated = KeySym - KEY_a + 1;
126 // No translation, look for escape sequences to send
136 int Term_MouseHandler(tHWND Window, int bPress, int Button, int Row, int Col)
141 void Term_HandleOutput(int Len, const char *Buf)
143 // TODO: Handle graphical / accelerated modes
150 esc_len = Term_HandleVT100(Len - ofs, Buf + ofs);
152 Display_AddText(-esc_len, Buf + ofs);