* vt100.c
* - VT100/xterm Emulation
*/
-#include <string.h>
#include <limits.h>
#include "include/vt100.h"
#include "include/display.h"
#include <ctype.h> // isalpha
-#include <acess/sys.h> // _SysDebug
-#include <assert.h>
+#ifdef KERNEL_VERSION
+# define _SysDebug(v...) Debug("VT100 "v)
+#else
+# include <acess/sys.h> // _SysDebug
+# include <string.h>
+# include <assert.h>
+#endif
const uint32_t caVT100Colours[] = {
- // Black, Red, Green, Yellow, Blue, Purple, Cyan, Gray
+ // Black, Red, Green, Yellow, Blue, Magenta, Cyan, Gray
// Same again, but bright
- 0x000000, 0x770000, 0x007700, 0x777700, 0x000077, 0x770077, 0x007777, 0xAAAAAAA,
- 0xCCCCCC, 0xFF0000, 0x00FF00, 0xFFFF00, 0x0000FF, 0xFF00FF, 0x00FFFF, 0xFFFFFFF
+ 0x000000, 0x770000, 0x007700, 0x777700, 0x000077, 0x770077, 0x007777, 0xAAAAAA,
+ 0xCCCCCC, 0xFF0000, 0x00FF00, 0xFFFF00, 0x0000FF, 0xFF00FF, 0x00FFFF, 0xFFFFFF,
};
int Term_HandleVT100_Long(tTerminal *Term, int Len, const char *Buf);
memcpy(inc_buf + inc_len, Buf, new_bytes);
if( new_bytes == 0 ) {
+ _SysDebug("Term_HandleVT100: Hit max? (Len=%i)", Len);
inc_len = 0;
return 0;
}
switch( *Buf )
{
+ // TODO: Need to handle \t and ^A-Z
case '\b':
Display_MoveCursor(Term, 0, -1);
Display_AddText(Term, 1, " ");
Display_MoveCursor(Term, 0, -1);
- // TODO: Need to handle \t and ^A-Z
return 1;
case '\t':
// TODO: tab (get current cursor pos, space until multiple of 8)
return 1;
case '\n':
+ // TODO: Support disabling CR after NL
Display_Newline(Term, 1);
return 1;
case '\r':
- Display_MoveCursor(Term, 0, INT_MIN);
- return 1;
+ if( Len >= 2 && Buf[1] == '\n' ) {
+ Display_Newline(Term, 1);
+ return 2;
+ }
+ else {
+ Display_MoveCursor(Term, 0, INT_MIN);
+ return 1;
+ }
}
int ret = 0;
case 'l': // unset
switch(args[0])
{
+ case 1: // Aplication cursor keys
+ _SysDebug("TODO: \\e[?1%c Application cursor keys", c);
+ break;
case 25: // Hide cursor
_SysDebug("TODO: \\e[?25%c Show/Hide cursor", c);
break;
// Standard commands
switch( c )
{
+ case 'A':
+ Display_MoveCursor(Term, -(argc >= 1 ? args[0] : 1), 0);
+ break;
+ case 'B':
+ Display_MoveCursor(Term, (argc >= 1 ? args[0] : 1), 0);
+ break;
+ case 'C':
+ Display_MoveCursor(Term, 0, (argc >= 1 ? args[0] : 1));
+ break;
+ case 'D':
+ Display_MoveCursor(Term, 0, -(argc >= 1 ? args[0] : 1));
+ break;
case 'H':
if( argc != 2 ) {
}
Display_SetCursor(Term, args[0], args[1]);
}
break;
- case 'J':
+ case 'J': // Clear lines
switch( args[0] )
{
case 0:
+ Display_ClearLines(Term, 1); // Down
+ break;
case 1:
- _SysDebug("TODO: VT100 %i J", args[0]);
+ Display_ClearLines(Term, -1); // Up
break;
- case 2: // Everything
- Display_ClearLines(Term, 0);
+ case 2:
+ Display_ClearLines(Term, 0); // All
break;
default:
_SysDebug("Unknown VT100 %i J", args[0]);
switch( args[0] )
{
case 0: // To EOL
+ Display_ClearLine(Term, -1);
+ break;
case 1: // To SOL
- _SysDebug("TODO: VT100 %i K", args[0]);
+ Display_ClearLine(Term, 1);
break;
case 2:
Display_ClearLine(Term, 0);
_SysDebug("Unknown VT100 %i K", args[0]);
break;
}
+ case 'S': // Scroll down n=1
+ Display_ScrollDown(Term, -(argc >= 1 ? args[0] : 1));
+ break;
case 'T': // Scroll down n=1
- Display_ScrollDown(Term, 1);
+ Display_ScrollDown(Term, (argc >= 1 ? args[0] : 1));
break;
case 'm':
if( argc == 0 )
{
// Reset
+ Display_ResetAttributes(Term);
}
else
{
- int i;
- for( i = 0; i < argc; i ++ )
+ for( int i = 0; i < argc; i ++ )
{
- if( args[i] < 8 )
- {
- // TODO: Flags?
- }
- else if( 30 <= args[i] && args[i] <= 37 )
+ switch(args[i])
{
+ case 0:
+ Display_ResetAttributes(Term);
+ break;
+ case 1:
+ _SysDebug("TODO: VT100 \\e[1m - Bold");
+ break;
+ case 2:
+ _SysDebug("TODO: VT100 \\e[1m - Reverse");
+ break;
+ case 30 ... 37:
// TODO: Bold/bright
Display_SetForeground( Term, caVT100Colours[ args[i]-30 ] );
- }
- else if( 40 <= args[i] && args[i] <= 47 )
- {
+ break;
+ case 40 ... 47:
// TODO: Bold/bright
- Display_SetBackground( Term, caVT100Colours[ args[i]-30 ] );
+ Display_SetBackground( Term, caVT100Colours[ args[i]-40 ] );
+ break;
+ default:
+ _SysDebug("TODO: VT100 \\e[%im", args[i]);
+ break;
}
}
}
break;
// Set scrolling region
case 'r':
- Display_SetScrollArea(Term, args[0], args[1]);
+ Display_SetScrollArea(Term, args[0], (args[1] - args[0]));
break;
case 's':