AmendHub

Download:

jcs

/

subtext

/

amendments

/

24

session: Do conditional ANSI output depending on the user's terminal


jcs made amendment 24 over 2 years ago
--- console.c Fri Dec 10 15:57:51 2021 +++ console.c Fri Dec 10 16:44:42 2021 @@ -82,7 +82,9 @@ console_init(struct console **cur_console) console->session = session_create("console", &console_node_funcs); console->session->cookie = (void *)console; - + console->session->ansi = 1; + console->session->cp437 = 1; + *cur_console = console; TextFont(monaco); --- session.c Fri Dec 10 15:53:20 2021 +++ session.c Fri Dec 10 16:44:14 2021 @@ -29,6 +29,8 @@ struct session **sessions = NULL; short nsessions = 0; char session_tbuf[512]; +unsigned short sessions_today = 0; + void session_run(struct uthread *uthread, void *arg); short session_login(struct session *s); @@ -87,9 +89,13 @@ session_run(struct uthread *uthread, void *arg) session_close(&s); } - session_output(s, "Welcome, %s, you are the %s caller today.\r\n", - s->user->username, "1st"); + /* TODO: persist this per-day */ + sessions_today++; + session_output(s, "Welcome, %s%s%s, you are the %s caller today.\r\n", + session_ansi(s, ANSI_BOLD), s->user->username, + session_ansi(s, ANSI_RESET), ordinal(sessions_today)); + session_output(s, "\r\n[ menu goes here ]\r\n\r\n"); while (!done) { @@ -399,3 +405,19 @@ session_load_view(struct session *session, short id, c return retpos; } +char * +session_ansi(struct session *s, unsigned char attr) +{ + switch (attr) { + case ANSI_RESET: + if (s->ansi) + return "\33[0m"; + break; + case ANSI_BOLD: + if (s->ansi) + return "\33[1m"; + break; + } + + return ""; +} --- session.h Fri Dec 10 14:55:25 2021 +++ session.h Fri Dec 10 16:34:11 2021 @@ -51,6 +51,9 @@ struct session { unsigned short terminal_rows; char terminal_type[20]; void *cookie; + unsigned char ansi; + unsigned char color; + unsigned char cp437; struct node_funcs *node_funcs; struct uthread *uthread; struct user *user; @@ -59,6 +62,9 @@ struct session { extern struct session **sessions; extern short nsessions; +#define ANSI_RESET 0 +#define ANSI_BOLD 1 + struct session *session_create(char *node, struct node_funcs *node_funcs); void session_close(struct session **session); void session_idle(struct session *session); @@ -69,5 +75,6 @@ size_t session_output_formatted(struct session *sessio char *session_field_input(struct session *session, unsigned short len, char mask); size_t session_load_view(struct session *session, short id, char **ret); +char *session_ansi(struct session *s, unsigned char attr); #endif /* __SESSION_H__ */