/*
* $Log$
+ * Revision 1.6 2008/02/06 17:53:28 james
+ * *** empty log message ***
+ *
* Revision 1.5 2008/02/06 15:53:22 james
* *** empty log message ***
*
}
else
{
+ ansi_write (a, "\033[21m", 5);
ansi_write (a, "\033[22m", 5);
}
}
{
CRT_Pos p;
int o;
+ int hidden_cursor=0;
+
+
- ansi_showhide_cursor (a, 1);
for (p.y = 0; p.y < CRT_ROWS; ++p.y)
{
continue;
if (crt_ca_cmp (a->crt.screen[o], c->screen[o]))
{
+ ansi_showhide_cursor (a, 1);
a->crt.screen[o] = c->screen[o];
ansi_move (a, p);
}
}
+
+ if ((CRT_COLS>a->size.x) || (CRT_ROWS>a->size.y)) {
+ char msg[]="Window is too small";
+ p.x=0;
+ p.y=0;
+
+ ansi_showhide_cursor (a, 1);
+ ansi_set_attr (a, CRT_ATTR_REVERSE);
+ ansi_move(a,p);
+
+ ansi_write (a, msg, sizeof(msg));
+ a->pos.x = ANSI_INVAL;
+ }
+
+
+ if ((c->pos.x>=a->size.x)
+ || (c->pos.y>=a->size.y)) {
+ ansi_showhide_cursor (a, 1);
+ return;
+ }
+
a->crt.pos = c->pos;
ansi_move (a, a->crt.pos);
/*
* $Log$
+ * Revision 1.5 2008/02/06 17:53:28 james
+ * *** empty log message ***
+ *
* Revision 1.4 2008/02/04 20:23:55 james
* *** empty log message ***
*
#include "project.h"
struct termios old = { 0 };
+static int had_winch=0;
-static void
-foo (int not)
+static void quit (int not)
{
tcsetattr (0, TCSANOW, &old);
exit (1);
}
+static void winch (int not)
+{
+ had_winch++;
+}
+
void
testy (void)
char c;
- signal (SIGINT, foo);
+ signal (SIGINT, quit);
+{
+struct sigaction sa={0};
+
+sa.sa_handler=winch;
+sa.sa_flags=SA_RESTART;
+sigaction(SIGWINCH,&sa,NULL);
+}
+
tcgetattr (0, &old);
tcgetattr (0, &raw);
for (;;)
{
+ struct timeval tv={0,100000};
+
FD_SET (fd, &rfd);
FD_SET (0, &rfd);
- if (select (fd + 1, &rfd, NULL, NULL, NULL) <= 0)
- continue;
+ if (select (fd + 1, &rfd, NULL, NULL, &tv)<0) continue;
+
if (FD_ISSET (0, &rfd))
{
if ((read (0, &c, 1) <= 0) || (c == 3))
vt102_parse_char (&v, c);
ansi_draw (&a, &v.crt);
}
+ if (had_winch) {
+ had_winch=0;
+ ansi_getsize(&a);
+ ansi_reset(&a);
+ ansi_draw (&a, &v.crt);
+ }
}
tcsetattr (0, TCSANOW, &old);
printf ("QUAT\n");
/*
* $Log$
+ * Revision 1.3 2008/02/06 17:53:28 james
+ * *** empty log message ***
+ *
* Revision 1.2 2008/02/04 02:05:06 james
* *** empty log message ***
*
default_termios (&termios);
- winsize.ws_row = CRT_ROWS;
- winsize.ws_col = CRT_COLS;
+ winsize.ws_row = VT102_ROWS;
+ winsize.ws_col = VT102_COLS;
child = forkpty (&fd, NULL, &termios, &winsize);
/*
* $Log$
+ * Revision 1.10 2008/02/06 17:53:28 james
+ * *** empty log message ***
+ *
* Revision 1.9 2008/02/06 15:53:22 james
* *** empty log message ***
*
void
vt102_log_line (VT102 * v, int line)
{
+ static FILE *log;
CRT_Pos e = { VT102_COLS - 1, line };
CRT_Pos p = { 0, line };
+ if (!log)
+ log=fopen("log","a+");
+
+ if (!log) return;
+
+
for (; e.x > 0; --e.x)
{
if (v->crt.screen[CRT_ADDR_POS (&e)].chr != ' ')
c = ' ';
if (c > 126)
c = ' ';
- fputc (c, stderr);
+ fputc (c, log);
}
- fputc ('\n', stderr);
+ fputc ('\n', log);
}
void
v->pos = v->top_margin;
vt102_cursor_normalize (v);
v->pending_wrap = 0;
+
}
vt102_cursor_absolute (VT102 * v, int x, int y)
case 1:
v->attr |= CRT_ATTR_BOLD;
break;
+ case 21:
case 22:
v->attr &= ~CRT_ATTR_BOLD;
break;
v->attr &= ~CRT_ATTR_REVERSE;
break;
default:
+ ;
+#if 0
fprintf (stderr, "unhandled SGR %d\n", a);
+#endif
}
}
vt102_change_attr (v, &num[o]);
}
+void vt102_save_state(VT102 *v)
+{
+v->saved.pos=v->pos;
+v->saved.attr=v->attr;
+v->saved.origin_mode=v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE];
+}
+
+void vt102_restore_state(VT102 *v)
+{
+v->pos=v->saved.pos;
+v->attr=v->saved.attr;
+v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE]=v->saved.origin_mode;
+vt102_cursor_normalize(v);
+v->pending_wrap = 0;
+}
+
void
vt102_parse_esc (VT102 * v, int c)
{
-
switch (c)
{
+case 'E':
+ if(v->pos.y==v->bottom_margin.y) {
+ vt102_log_line (v, v->pos.y);
+ crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1);
+ } else {
+ vt102_cursor_relative(v,0,1);
+ }
+ break;
+case 'H':
+ v->tabs[v->pos.x]++;
+ break;
+case 'M':
+ if(v->pos.y==v->top_margin.y) {
+ crt_scroll_down (&v->crt, v->top_margin, v->bottom_margin, 1);
+ } else {
+ vt102_cursor_relative(v,0,-1);
+ }
+ break;
+case '7':
+ vt102_save_state(v);
+ break;
+case '8':
+ vt102_restore_state(v);
+ break;
#if 0
case '=':
case '>':
break;
#endif
default:
+#if 0
fprintf (stderr, "unhandled ESC \\033 \\%03o (ESC %c)\n", c,
(c < 32) ? '?' : c);
+#endif
+ ;
}
}
void
case 'D':
vt102_cursor_relative (v, -narg, 0);
break;
+ case 'E':
+ vt102_cursor_relative (v, 0, narg);
+ vt102_cursor_carriage_return (v);
+ break;
+ case 'F':
+ vt102_cursor_relative (v, 0, -narg);
+ vt102_cursor_carriage_return (v);
+ break;
+ case 'G':
+ vt102_cursor_absolute (v, narg-1, v->pos.y);
+ break;
case 'H':
+ case 'f':
{
int x, y;
vt102_cursor_home (v);
break;
+ case 's':
+ v->saved.pos=v->pos;
+ break;
+ case 'u':
+ v->pos=v->saved.pos;
+ vt102_cursor_normalize(v);
+ v->pending_wrap = 0;
+ break;
default:
+#if 0
fprintf (stderr, "unhandled CSI \\033%s\n", buf, buf[0]);
+#endif
+ ;
}
break;
default:
+#if 0
fprintf (stderr, "unhandled CSI \\033%s\n", buf, buf[0]);
+#endif
+ ;
}
VT102_parser *p = &v->parser;
#if 0
- fprintf (stderr, "%c pc %d %d %d %d %d\n", (c < 32) ? 32 : c, c,
+ fprintf (stderr, "char %c pc %d %d %d %d %d\n", (c < 32) ? 32 : c, c,
p->in_csi, p->in_escape, v->pos.x, v->pos.y);
#endif
if (p->in_csi)
/*STX*/ case 2:
/*ETX*/ case 3:
/*EOT*/ case 4:
+ break;
/*ENQ*/ case 5:
+ /*FIXME: Should send ack*/
+ break;
/*ACK*/ case 6:
/*BEL*/ case 7:
break;
}
v->crt.pos = v->pos;
+ v->crt.hide_cursor=v->private_modes[VT102_PRIVATE_MODE_SHOW_CURSOR] ? 0:1;
if (v->current_line.y != v->pos.y)
{
v->private_modes[VT102_PRIVATE_MODE_AUTO_WRAP] = 1;
v->private_modes[VT102_PRIVATE_MODE_AUTO_REPEAT] = 1;
+ v->private_modes[VT102_PRIVATE_MODE_SHOW_CURSOR] = 1;
vt102_cursor_home (v);
vt102_reset_tabs (v);
v->current_line = v->pos;
+ vt102_save_state(v);
+
+#if 0
+{
+char buf[3];
+int i;
+ for (i=0;i<200;++i) {
+ sprintf(buf,"%3d",i);
+ vt102_parse_char (v,buf[0]);
+ vt102_parse_char (v,buf[1]);
+ vt102_parse_char (v,buf[2]);
+ vt102_parse_char (v,13);
+ vt102_parse_char (v,27);
+ vt102_parse_char (v,'M');
+ }
+ vt102_parse_char(v,'f');
+ vt102_parse_char (v,13);
+ for (i=0;i<23;++i) {
+ vt102_parse_char (v,27);
+ vt102_parse_char (v,'M');
+ }
+ vt102_parse_char(v,'b');
+ vt102_parse_char (v,13);
+}
+#endif
+
+
+ vt102_status_line (v, "VT102 foo bar baz I'm the urban spaceman baby");
+
}
/*
* $Log$
+ * Revision 1.6 2008/02/06 17:53:28 james
+ * *** empty log message ***
+ *
* Revision 1.5 2008/02/06 15:53:22 james
* *** empty log message ***
*
char csi_buf[VT102_CSI_LEN];
} VT102_parser;
+typedef struct {
+ CRT_Pos pos;
+ int attr;
+ int origin_mode;
+} VT102_State;
+
+
typedef struct
{
CRT_Pos top_margin, bottom_margin;
int pending_wrap;
CRT_Pos pos,current_line;
-
-
+ VT102_State saved;
uint8_t modes[VT102_NMODES];
uint8_t private_modes[VT102_NMODES];
#define VT102_PRIVATE_MODE_ORIGIN_MODE 6
#define VT102_PRIVATE_MODE_AUTO_WRAP 7
#define VT102_PRIVATE_MODE_AUTO_REPEAT 8
+#define VT102_PRIVATE_MODE_SHOW_CURSOR 25
#define VT102_MODE_KEYBOARD_DISABLE 2
#define VT102_MODE_INSERT 4
--- /dev/null
+#include <stdio.h>
+#include <termios.h>
+
+void
+putat (int i)
+{
+ while (i--)
+ putchar ('@');
+}
+
+int
+main (int argc, char *argv[])
+{
+ struct termios raw, old;
+
+ tcgetattr (0, &old);
+ tcgetattr (0, &raw);
+ cfmakeraw (&raw);
+ tcsetattr (0, TCSANOW, &raw);
+
+
+ fputs ("\033[H\033[2J", stdout);
+ putat (80);
+ fputs ("\r\n", stdout);
+ fputs ("*", stdout);
+ fputs ("\r\n\n", stdout);
+
+ putat (80);
+ fputs ("a", stdout);
+ fputs ("\r\n", stdout);
+ fputs ("*", stdout);
+ fputs ("\r\n\n", stdout);
+
+ putat (80);
+ fputs ("\rb\n", stdout);
+ fputs ("*", stdout);
+ fputs ("\r\n\n", stdout);
+
+ putat (80);
+ fputs ("\nc\n", stdout);
+ fputs ("*", stdout);
+ fputs ("\r\n\n", stdout);
+
+ putat (80);
+ fputs ("\033[Cd", stdout);
+ fputs ("\r\n", stdout);
+ fputs ("*", stdout);
+ fputs ("\r\n\n", stdout);
+
+
+ putat (80);
+ fputs ("\033[De", stdout);
+ fputs ("\r\n", stdout);
+ fputs ("*", stdout);
+ fputs ("\r\n\n", stdout);
+
+
+ tcsetattr (0, TCSANOW, &old);
+
+ return 0;
+}