jcs
/subtext
/amendments
/32
console: Implement remaining CSI commands, add cheap screen clearing
jcs made amendment 32 over 2 years ago
--- console.c Mon Dec 13 21:42:20 2021
+++ console.c Wed Dec 15 14:34:35 2021
@@ -26,6 +26,11 @@
#define FONT_WIDTH 6
#define FONT_HEIGHT 11
+#define CONSOLE_FORCE_REDRAW 1
+#define CONSOLE_CLEAR_SCREEN 2
+
+#define CONSOLE_PADDING 6
+
struct node_funcs console_node_funcs = {
NULL,
console_input,
@@ -52,8 +57,10 @@ console_init(struct console **cur_console)
console->ncolumns = 80;
console->nlines = 24;
- width = (FONT_WIDTH * console->ncolumns) + (FONT_WIDTH * 2);
- height = (FONT_HEIGHT * console->nlines) + (FONT_WIDTH * 2);
+ width = CONSOLE_PADDING + (FONT_WIDTH * console->ncolumns) +
+ CONSOLE_PADDING;
+ height = CONSOLE_PADDING + (FONT_HEIGHT * console->nlines) +
+ CONSOLE_PADDING;
bounds.left = (screenBits.bounds.right - width) / 2;
bounds.right = bounds.left + width;
@@ -71,13 +78,6 @@ console_init(struct console **cur_console)
panic("Can't create window");
SetPort(console->win);
- bounds.right = console->win->portRect.right;
- bounds.left = bounds.right - SCROLLBAR_WIDTH;
- bounds.bottom = console->win->portRect.bottom + 1;
- bounds.top = console->win->portRect.top - 1;
- console->scroller = NewControl(console->win, &bounds, "\p", true,
- 1, 1, 1, scrollBarProc, 0L);
-
ShowWindow(console->win);
console->session = session_create("console", "console",
@@ -86,6 +86,8 @@ console_init(struct console **cur_console)
console->session->ansi = 1;
console->session->cp437 = 1;
console->session->tspeed = 19200;
+ strlcpy(console->session->autologin_username, "sysop",
+ sizeof(console->session->autologin_username));
*cur_console = console;
@@ -202,10 +204,7 @@ console_update(struct console *console, EventRecord *e
switch (what) {
case -1:
case updateEvt:
- console_redraw(console, 1);
- //browser_update_menu(browser);
- UpdtControl(console->win, console->win->visRgn);
-
+ console_redraw(console, CONSOLE_FORCE_REDRAW);
break;
case activateEvt:
break;
@@ -272,8 +271,8 @@ console_bound(struct console *console)
pxout = shift_lines * FONT_HEIGHT;
rgn = NewRgn();
- r.left = console->win->portRect.left + FONT_WIDTH;
- r.top = console->win->portRect.top + FONT_WIDTH;
+ r.left = console->win->portRect.left + CONSOLE_PADDING;
+ r.top = console->win->portRect.top + CONSOLE_PADDING;
r.right = r.left + (console->ncolumns * FONT_WIDTH);
r.bottom = r.top + ((console->nlines) * FONT_HEIGHT);
#ifdef SMOOTH_SCROLLING
@@ -314,15 +313,25 @@ console_redraw(struct console *console, short force)
console->attrs[(console->cursor_line * console->ncolumns) +
console->cursor_column] |= (ATTR_CURSOR | ATTR_DIRTY);
+ if (force == CONSOLE_CLEAR_SCREEN) {
+ cursor.left = console->win->portRect.left + CONSOLE_PADDING;
+ cursor.top = console->win->portRect.top + CONSOLE_PADDING;
+ cursor.right = cursor.left + (FONT_WIDTH * console->ncolumns);
+ cursor.bottom = cursor.top + (FONT_HEIGHT * console->nlines);
+
+ FillRect(&cursor, console->cur_attr & ATTR_REVERSE ? black : white);
+ force = 0;
+ }
+
nsize = console->ncolumns * console->nlines;
SetCursor(*(GetCursor(watchCursor)));
- cursor.left = console->win->portRect.left + FONT_WIDTH;
- cursor.top = console->win->portRect.top + FONT_WIDTH;
+ cursor.left = console->win->portRect.left + CONSOLE_PADDING;
+ cursor.top = console->win->portRect.top + CONSOLE_PADDING;
for (cell = 0; cell < nsize; cell++) {
if (cell) {
if (cell % console->ncolumns == 0) {
- cursor.left = console->win->portRect.left + FONT_WIDTH;
+ cursor.left = console->win->portRect.left + CONSOLE_PADDING;
cursor.top += FONT_HEIGHT;
} else {
cursor.left += FONT_WIDTH;
@@ -349,9 +358,12 @@ console_redraw(struct console *console, short force)
DrawChar(console->chars[cell]);
- console->attrs[cell] &= ~ATTR_DIRTY;
+ if (console->attrs[cell] & ATTR_REVERSE)
+ InvertRect(&cursor);
if (console->attrs[cell] & ATTR_CURSOR)
InvertRect(&cursor);
+
+ console->attrs[cell] &= ~ATTR_DIRTY;
}
ValidRect(&console->win->portRect);
@@ -362,7 +374,8 @@ console_redraw(struct console *console, short force)
void
console_parse_csi(struct console *console)
{
- short x, y, cursor;
+ short x, y;
+ long cursor;
short serviced = 0;
short param1 = -1, param2 = -1;
short parambuflen;
@@ -508,40 +521,46 @@ console_parse_csi(struct console *console)
switch (param1) {
case 0:
/* clear from cursor to end of screen */
-#if 0
for (y = console->cursor_line; y < console->nlines; y++) {
for (x = 0; x < console->ncolumns; x++) {
if (y == console->cursor_line &&
x < console->cursor_column)
continue;
- update_char(x, y, ' ', cur_attr, cur_color);
+ cursor = (y * console->ncolumns) + x;
+ console->chars[cursor] = ' ';
+ console->attrs[cursor] = console->cur_attr | ATTR_DIRTY;
}
}
-#endif
break;
case 1:
/* clear from cursor to beginning of the screen */
-#if 0
for (y = console->cursor_line; y >= 0; y--) {
for (x = console->ncolumns; x >= 0; x--) {
if (y == console->cursor_line &&
x > console->cursor_column)
continue;
- update_char(x, y, ' ', cur_attr, cur_color);
+ cursor = (y * console->ncolumns) + x;
+ console->chars[cursor] = ' ';
+ console->attrs[cursor] = console->cur_attr | ATTR_DIRTY;
}
}
-#endif
break;
case 2:
- /* clear entire screen */
-#if 0
+ /* clear entire screen, mark everything clean */
+ cursor = 0;
for (y = 0; y < console->nlines; y++) {
- for (x = 0; x < console->ncolumns; x++)
- update_char(x, y, ' ', cur_attr, cur_color);
+ for (x = 0; x < console->ncolumns; x++) {
+ console->chars[cursor] = ' ';
+ console->attrs[cursor] = console->cur_attr;
+ cursor++;
+ }
}
-#endif
+
+ /* and then quickly clear the screen */
+ console_bound(console);
+ console_redraw(console, CONSOLE_CLEAR_SCREEN);
break;
}
break;
@@ -551,29 +570,29 @@ console_parse_csi(struct console *console)
/* clear from cursor to end of line */
if (console->cursor_column >= console->ncolumns)
break;
-#if 0
- for (x = console->cursor_column; x < console->ncolumns; x++)
- update_char(x, console->cursor_line, ' ', cur_attr,
- cur_color);
-#endif
+ for (x = console->cursor_column; x < console->ncolumns; x++) {
+ cursor = (console->cursor_line * console->ncolumns) + x;
+ console->chars[cursor] = ' ';
+ console->attrs[cursor] = console->cur_attr | ATTR_DIRTY;
+ }
break;
case 1:
/* clear from cursor to beginning of line */
if (console->cursor_column == 0)
break;
-#if 0
- for (x = console->cursor_column; x >= 0; x--)
- update_char(x, console->cursor_line, ' ', cur_attr,
- cur_color);
-#endif
+ for (x = console->cursor_column; x >= 0; x--) {
+ cursor = (console->cursor_line * console->ncolumns) + x;
+ console->chars[cursor] = ' ';
+ console->attrs[cursor] = console->cur_attr | ATTR_DIRTY;
+ }
break;
case 2:
/* clear entire line */
-#if 0
- for (x = 0; x < console->ncolumns - 1; x++)
- update_char(x, console->cursor_line, ' ', cur_attr,
- cur_color);
-#endif
+ for (x = 0; x < console->ncolumns - 1; x++) {
+ cursor = (console->cursor_line * console->ncolumns) + x;
+ console->chars[cursor] = ' ';
+ console->attrs[cursor] = console->cur_attr | ATTR_DIRTY;
+ }
break;
}
break;
@@ -685,17 +704,13 @@ console_parse_csi(struct console *console)
break;
case '7': /* DECSC - save cursor */
case 's': /* from ANSI.SYS */
-#if 0
- saved_cursorx = cursorx;
- saved_cursory = cursory;
-#endif
+ console->saved_cursor_column = console->cursor_column;
+ console->saved_cursor_line = console->cursor_line;
break;
case '8': /* DECRC - restore cursor */
case 'u': /* from ANSI.SYS */
-#if 0
- cursorx = saved_cursorx;
- cursory = saved_cursory;
-#endif
+ console->cursor_column = console->saved_cursor_column;
+ console->cursor_line = console->saved_cursor_line;
break;
default:
/*
--- console.h Mon Dec 13 13:43:42 2021
+++ console.h Wed Dec 15 09:24:45 2021
@@ -36,6 +36,8 @@ struct console {
#define ATTR_DIRTY (1 << 7)
short cursor_line;
short cursor_column;
+ short saved_cursor_line;
+ short saved_cursor_column;
short in_csi;
short csilen;
char csi[32];