summaryrefslogtreecommitdiff
path: root/userspace/xterm/terminal.c
diff options
context:
space:
mode:
Diffstat (limited to 'userspace/xterm/terminal.c')
-rw-r--r--userspace/xterm/terminal.c69
1 files changed, 62 insertions, 7 deletions
diff --git a/userspace/xterm/terminal.c b/userspace/xterm/terminal.c
index ba7986e..ed2b175 100644
--- a/userspace/xterm/terminal.c
+++ b/userspace/xterm/terminal.c
@@ -1,3 +1,4 @@
+// https://en.wikipedia.org/wiki/ANSI_escape_code
// http://en.wikipedia.org/wiki/VT52
// http://vt100.net/docs/vt520-rm/
// man 4 console_codes
@@ -96,7 +97,7 @@ typedef struct terminal_tty_struct
uint32_t height;
uint32_t x;
uint32_t y;
- uint32_t *data; // screen data
+ uint32_t *data; // screen data (need this for linefeed and rev linefeed)
uint8_t *command; // command line / also holds npar for escape sequences somewhere
int32_t command_l; // command line length
@@ -250,6 +251,60 @@ static void process_graphic_npar(terminal_tty *tty, terminal_settings s)
}
}
+// string needs to have leading zeroes!
+static uint32_t myatoi(char *str,int len)
+{
+ uint32_t res=0;
+
+ for(int i=0;i<len;i++)
+ {
+ res*=10;
+ res+=str[i]-'0';
+ }
+
+ return res;
+}
+
+static void process_cup(terminal_tty *tty)
+{
+
+ // the CSI CUP command:
+ //
+ // - starts at: tty->command[NPAR_START]
+ // - has length: tty->npar
+ // - has the form: row;col
+
+ char buf[10];
+ int b=0;
+ bool row=true;
+
+ for(int i=0;i<tty->npar+1;i++)
+ {
+ char c=tty->command[NPAR_START+i];
+
+ // hit the separating ';' or hit the end
+ if(i==tty->npar||c==';')
+ {
+ if(row) //row 1-based
+ {
+ tty->y=myatoi(buf,b)-1;
+ }
+ else //col 1-based
+ {
+ tty->x=myatoi(buf,b)-1;
+ }
+ row=false;
+ b=0;
+ }
+ else
+ {
+ buf[b++]=c;
+ }
+ }
+
+ tty->npar=0;
+}
+
static void process_graphic_npars(terminal_tty *tty)
{
@@ -508,7 +563,6 @@ void terminal_put(terminal_tty *tty, uint8_t c)
if(c=='8'){}// RESTORE STATE
if(c=='['){tty->escaping=2;tty->npar=0;return;} // CONTROL SEQ INTRODUCER
-
// TODO
// %, %@, %G, %8, #8, (, (B, (O, (U, (K
// ), >, =, ] (???)
@@ -521,19 +575,20 @@ void terminal_put(terminal_tty *tty, uint8_t c)
else if(tty->escaping==2)
{
//ECMA-48: TODO
-
-
-
//ECMA-48 GRAPHIC RENDITION: OK
- if(c!='m')
+ if(c!='m' && c!='H')
{
tty->command[NPAR_START+(tty->npar++)]=c;
}
- else
+ else if(c=='m')
{
process_graphic_npars(tty);
}
+ else if(c=='H')
+ {
+ process_cup(tty);
+ }
//ECMA-48 MODE SWITCHES: TODO
//ECMA-48 STATUS REPORT: TODO