jcs
/subtext
/amendments
/22
console: Fix attribute storing, do output from thread
This doesn't seem to break things and makes it more responsive
jcs made amendment 22 over 2 years ago
--- console.c Wed Dec 8 14:39:08 2021
+++ console.c Fri Dec 10 15:57:51 2021
@@ -84,6 +84,9 @@ console_init(struct console **cur_console)
console->session->cookie = (void *)console;
*cur_console = console;
+
+ TextFont(monaco);
+ TextSize(9);
return console;
}
@@ -93,8 +96,8 @@ console_close(struct session *session)
{
struct console *console = (struct console *)session->cookie;
- DisposeWindow(console->win);
*(console->cur_console) = NULL;
+ DisposeWindow(console->win);
free(console);
}
@@ -145,11 +148,11 @@ console_idle(struct console *console)
case '\n':
console->cursor_line++;
break;
- case '\e':
+ case '\33': /* \e */
if (session->obuflen <= n + 1) {
/* lone \e at end of buffer, keep it until we see next */
session->obuflen = 1;
- session->obuf[0] = '\e';
+ session->obuf[0] = '\33';
goto output_done;
}
if (session->obuf[n + 1] == '[') {
@@ -162,7 +165,7 @@ console_idle(struct console *console)
cursor = (console->cursor_line * console->ncolumns) +
console->cursor_column;
console->chars[cursor] = session->obuf[n];
- console->attrs[cursor] |= ATTR_DIRTY;
+ console->attrs[cursor] = console->cur_attr | ATTR_DIRTY;
console->cursor_column++;
if (nhints != -1 && nhints < nitems(hints) - 1)
hints[nhints++] = cursor;
@@ -240,8 +243,8 @@ console_key_down(struct console *console, EventRecord
short
console_output(struct session *session)
{
- /* nothing to do here, output is printed from console_idle */
- uthread_yield();
+ struct console *console = (struct console *)session->cookie;
+ console_idle(console);
return 0;
}
@@ -258,9 +261,6 @@ console_redraw(struct console *console, short nhints,
{
Rect cursor;
short n, nsize, cell, line = 0, column = 0;
-
- TextFont(monaco);
- TextSize(9);
if (nhints > 0)
nsize = nhints;
@@ -300,6 +300,11 @@ console_redraw(struct console *console, short nhints,
FillRect(&cursor, white);
MoveTo(cursor.left, cursor.top + FONT_HEIGHT - 2);
+
+ if (console->attrs[cell] & ATTR_BOLD)
+ TextFace(thePort->txFace | bold);
+ else
+ TextFace(thePort->txFace & ~bold);
DrawChar(console->chars[cell]);
console->attrs[n] &= ~ATTR_DIRTY;
@@ -321,7 +326,7 @@ console_parse_csi(struct console *console)
short param1 = -1, param2 = -1;
short parambuflen;
char parambuf[4];
- char c;
+ unsigned char c;
if (console->csilen == 0)
return;
@@ -629,10 +634,10 @@ console_parse_csi(struct console *console)
case 'n': /* DSR - device status report */
switch (param1) {
case 5: /* terminal is ready */
- session_output(console->session, "\e[0n");
+ session_output(console->session, "\33[0n");
break;
case 6: /* CPR - report cursor position */
- session_output(console->session, "\e[%d;%dR",
+ session_output(console->session, "\33[%d;%dR",
console->cursor_line + 1, console->cursor_column + 1);
break;
}
--- main.c Tue Dec 7 15:08:48 2021
+++ main.c Fri Dec 10 15:58:05 2021
@@ -105,8 +105,6 @@ main(void)
switch (event.what) {
case nullEvent:
- if (cur_console)
- console_idle(cur_console);
break;
case keyDown:
case autoKey:
--- session.c Thu Dec 9 16:40:57 2021
+++ session.c Fri Dec 10 15:53:20 2021
@@ -60,7 +60,8 @@ session_run(struct uthread *uthread, void *arg)
{
struct session *s = (struct session *)arg;
Handle h;
- char *view;
+ char *view, done = 0;
+ unsigned char c;
size_t len;
/* until we negotiate otherwise */
@@ -70,7 +71,7 @@ session_run(struct uthread *uthread, void *arg)
if (s->node_funcs->setup)
s->node_funcs->setup(s);
-
+
len = session_load_view(s, DB_TEXT_ISSUE_ID, &view);
if (len) {
session_output_formatted(s, view, len);
@@ -81,11 +82,35 @@ session_run(struct uthread *uthread, void *arg)
"\r\n", db->config.name, s->node);
}
- if (session_login(s) == AUTH_USER_OK)
- session_output(s, "Welcome, %s\r\n", s->user->username);
- else
+ if (session_login(s) != AUTH_USER_OK) {
session_output(s, "Thanks for playing\r\n");
+ session_close(&s);
+ }
+ session_output(s, "Welcome, %s, you are the %s caller today.\r\n",
+ s->user->username, "1st");
+
+ session_output(s, "\r\n[ menu goes here ]\r\n\r\n");
+
+ while (!done) {
+ session_output(s, "Main Menu> ");
+
+ c = session_input_char(s);
+ session_output_formatted(s, "\r\n", 2);
+
+ switch (c) {
+ case 'g':
+ case 'G':
+ /* goodbye */
+ session_output(s, "Goodbye!\r\n");
+ done = 1;
+ break;
+ default:
+ session_output(s, "Invalid option\r\n");
+ break;
+ }
+ }
+
session_close(&s);
}
@@ -96,7 +121,7 @@ session_close(struct session **session)
unsigned long now;
short onsessions, n;
- /* try to flush output */
+ /* give 1 second to flush output */
now = Ticks;
while ((*session)->obuflen && (Ticks - now) < 60) {
(*session)->node_funcs->output(*session);
@@ -203,13 +228,13 @@ session_field_input(struct session *session, unsigned
{
short ilen = 0, ipos = 0, lastlen = 0;
char *field;
- char c, redraw = 0;
+ unsigned char c, redraw = 0;
field = xmalloczero(len);
for (;;) {
c = session_input_char(session);
- switch ((unsigned char)c) {
+ switch (c) {
case 8: /* backspace / ^H */
case 127: /* delete, backspace through telnet */
if (ipos == 0)
@@ -249,7 +274,7 @@ session_field_input(struct session *session, unsigned
ipos++;
ilen++;
field[ipos] = '\0';
- session_output_formatted(session, mask ? &mask : &c, 1);
+ session_output_formatted(session, mask ? &mask : (char *)&c, 1);
}
}
@@ -262,15 +287,19 @@ session_login(struct session *s)
{
struct user *user;
char junk[SHA256_DIGEST_STRING_LENGTH];
- char *username;
- char *password;
- short n;
+ char *username, *password;
size_t len;
+ short n;
for (n = 1; n <= 3; n++) {
session_output(s, "login: ");
username = session_field_input(s, 32, 0);
session_output(s, "\r\n");
+
+ if (username[0] == '\0') {
+ n--;
+ continue;
+ }
if (strcmp(username, "guest") == 0) {
/* TODO */
@@ -369,3 +398,4 @@ session_load_view(struct session *session, short id, c
return retpos;
}
+
--- session.h Thu Dec 9 16:41:34 2021
+++ session.h Fri Dec 10 14:55:25 2021
@@ -66,8 +66,8 @@ char session_input_char(struct session *session);
size_t session_output(struct session *session, const char *format, ...);
size_t session_output_formatted(struct session *session, const char *str,
size_t len);
-char *session_field_input(struct session *session, unsigned short len,
- char mask);
+char *session_field_input(struct session *session,
+ unsigned short len, char mask);
size_t session_load_view(struct session *session, short id, char **ret);
#endif /* __SESSION_H__ */
--- telnet.c Thu Dec 9 20:58:41 2021
+++ telnet.c Fri Dec 10 13:53:54 2021
@@ -228,18 +228,17 @@ telnet_idle(void)
break;
}
}
-
}
void
telnet_setup(struct session *session)
{
char iacs[] = {
- IAC, DO, IAC_TTYPE, /* send your TTYPE */
- IAC, DO, IAC_TSPEED, /* send your TSPEED */
- IAC, DO, IAC_NAWS, /* send your NAWS */
IAC, WILL, IAC_SGA, /* we will supress go-ahead */
IAC, WILL, IAC_ECHO, /* and we will echo for you */
+ IAC, DO, IAC_TSPEED, /* send your TSPEED */
+ IAC, DO, IAC_NAWS, /* send your NAWS */
+ IAC, DO, IAC_TTYPE, /* send your TTYPE */
/* IAC, DO, IAC_LINEMODE, */
};