190f42c11cc64fedbf4dc3fd86f1515c6a982fd5
[tpg/acess2.git] / Usermode / Applications / gui_shell_src / vt100.c
1 /*
2  * Acess GUI Terminal
3  * - By John Hodge (thePowersGang)
4  *
5  * vt100.c
6  * - VT100/xterm Emulation
7  */
8 #include <string.h>
9 #include <limits.h>
10 #include "include/vt100.h"
11 #include "include/display.h"
12
13 static inline int min(int a, int b)
14 {
15         return a < b ? a : b;
16 }
17
18 int Term_HandleVT100(int Len, const char *Buf)
19 {
20         #define MAX_VT100_ESCAPE_LEN    16
21         static char     inc_buf[MAX_VT100_ESCAPE_LEN];
22         static int      inc_len = 0;
23
24         if( inc_len > 0 || *Buf == '\x1b' )
25         {
26                 memcpy(inc_buf + inc_len, Buf, min(MAX_VT100_ESCAPE_LEN - inc_len, Len));
27                 // Handle VT100 (like) escape sequence
28                 
29                 inc_len = 0;
30                 return 1;
31         }
32
33         switch( *Buf )
34         {
35         case '\b':
36                 // TODO: Backspace
37                 Display_MoveCursor(-1, 0);
38                 return 1;
39         case '\t':
40                 // TODO: tab (get current cursor pos, space until multiple of 8)
41                 return 1;
42         case '\n':
43                 Display_Newline(1);
44                 return 1;
45         case '\r':
46                 // TODO: Carriage return
47                 Display_MoveCursor(INT_MIN, 0);
48                 return 1;
49         }
50
51          int    ret = 0;
52         while( ret < Len )
53         {
54                 if( *Buf == '\n' )
55                         break;
56                 if( *Buf == '\x1b' )
57                         break;
58                 ret ++;
59                 Buf ++;
60         }
61         return -ret;
62 }

UCC git Repository :: git.ucc.asn.au