#include <ctype.h> // isalpha
#include <acess/sys.h> // _SysDebug
+const uint32_t caVT100Colours[] = {
+ // Black, Red, Green, Yellow, Blue, Purple, Cyan, Gray
+ // Same again, but bright
+ 0x000000, 0x770000, 0x007700, 0x777700, 0x000077, 0x770077, 0x007777, 0xAAAAAAA,
+ 0xCCCCCC, 0xFF0000, 0x00FF00, 0xFFFF00, 0x0000FF, 0xFF00FF, 0x00FFFF, 0xFFFFFFF
+};
+
int Term_HandleVT100_Long(int Len, const char *Buf);
static inline int min(int a, int b)
if( inc_len > 0 || *Buf == '\x1b' )
{
+ // Handle VT100 (like) escape sequence
int new_bytes = min(MAX_VT100_ESCAPE_LEN - inc_len, Len);
- int ret = 0;
+ int ret = 0, old_inc_len = inc_len;
memcpy(inc_buf + inc_len, Buf, new_bytes);
- inc_len += new_bytes;
- // Handle VT100 (like) escape sequence
- _SysDebug("inc_len = %i, new_bytes = %i", inc_len, new_bytes);
+ inc_len += new_bytes;
if( inc_len <= 1 )
return 1; // Skip 1 character (the '\x1b')
{
case '[': // Multibyte, funtime starts
ret = Term_HandleVT100_Long(inc_len-2, inc_buf+2);
- if( ret > 0 )
+ if( ret > 0 ) {
ret += 2;
+ }
break;
default:
ret = 2;
break;
}
- if( ret != 0 )
+ if( ret != 0 ) {
inc_len = 0;
+ ret -= old_inc_len; // counter cached bytes
+ }
return ret;
}
switch( *Buf )
{
case '\b':
- // TODO: Backspace
Display_MoveCursor(-1, 0);
+ Display_AddText(1, " ");
+ Display_MoveCursor(-1, 0);
+ // TODO: Need to handle \t and ^A-Z
return 1;
case '\t':
// TODO: tab (get current cursor pos, space until multiple of 8)
Display_Newline(1);
return 1;
case '\r':
- // TODO: Carriage return
Display_MoveCursor(INT_MIN, 0);
return 1;
}
if( !isalpha(c) ) {
// Bother.
_SysDebug("Unexpected char 0x%x in VT100 escape code", c);
- return -1;
+ return 1;
}
if( bQuestionMark )
else
_SysDebug("TODO: VT100 %i J", args[0]);
break;
+ case 'm':
+ if( argc == 0 )
+ {
+ // Reset
+ }
+ else
+ {
+ int i;
+ for( i = 0; i < argc; i ++ )
+ {
+ if( args[i] < 8 )
+ {
+ // TODO: Flags?
+ }
+ else if( 30 <= args[i] && args[i] <= 37 )
+ {
+ // TODO: Bold/bright
+ Display_SetForeground( caVT100Colours[ args[i]-30 ] );
+ }
+ else if( 40 <= args[i] && args[i] <= 47 )
+ {
+ // TODO: Bold/bright
+ Display_SetBackground( caVT100Colours[ args[i]-30 ] );
+ }
+ }
+ }
+ break;
default:
_SysDebug("Unknown VT100 escape char 0x%x", c);
break;