AmendHub

Download:

jcs

/

subtext

/

amendments

/

210

session+chat: Remove session_bar, implement simpler bar in chat

This is only used in chat and only to print a left-aligned bar.

jcs made amendment 210 over 2 years ago
--- chat.c Fri Jul 15 21:50:23 2022 +++ chat.c Sat Jul 16 14:50:15 2022 @@ -29,6 +29,7 @@ static char chat_tbuf[256]; +void chat_output_bar(struct session *s, char *left_str, char *right_str); void chat_help(struct session *s); void chat_who(struct session *s); @@ -146,8 +147,8 @@ chat_printf_line(struct session *s, short around_bar, void chat_start(struct session *s, char *with_node) { - char *input, *bar; - short len, alen, lagged = 0; + char *input; + bool lagged = false; s->chatting = 1; if (with_node[0]) @@ -168,13 +169,11 @@ chat_start(struct session *s, char *with_node) ansi(s, ANSI_BOLD, ANSI_END), ansi(s, ANSI_RESET, ANSI_END)); session_flush(s); - snprintf(chat_tbuf, sizeof(chat_tbuf), - " [ %s ] [ Chatting with %s ]", + session_printf(s, "\r%s [ %s ] [ Chatting with %s ]%s\r\n", + ansi(s, ANSI_REVERSE, ANSI_ERASE_LINE, ANSI_END), s->user ? s->user->username : "guest", - s->chatting_with_node[0] ? "..." : "everyone"); - bar = session_bar(s, chat_tbuf, NULL); - session_output(s, bar, strlen(bar)); - session_output(s, "\r\n", 2); + s->chatting_with_node[0] ? "..." : "everyone", + ansi(s, ANSI_RESET, ANSI_END)); session_flush(s); snprintf(chat_tbuf, sizeof(chat_tbuf), @@ -240,7 +239,7 @@ chat_start(struct session *s, char *with_node) session_flush(s); if (s->abort_input && !s->chatting) - lagged = 1; + lagged = true; s->chatting = 0; memset(s->chatting_with_node, 0, sizeof(s->chatting_with_node)); --- session.c Fri Jul 15 22:15:00 2022 +++ session.c Sat Jul 16 14:32:15 2022 @@ -956,75 +956,6 @@ login_bail: return AUTH_USER_FAILED; } -char * -session_bar(struct session *s, char *left_str, char *right_str) -{ - static char sides[2][128]; - static char bar[256]; - char *str, *side; - short sstrlen, sidelen, bold, n, nside, barlen, pad; - - memset(bar, 0, sizeof(bar)); - barlen = sprintf(bar, "\r%s", ansi(s, ANSI_REVERSE, ANSI_END)); - - for (nside = 0; nside < 2; nside++) { - if (nside == 0) - str = left_str; - else - str = right_str; - - side = (char *)&sides[nside]; - side[0] = '\0'; - - if (str == NULL) - continue; - - bold = 0; - sstrlen = strlen(str); - sidelen = 0; - - for (n = 0; n < sstrlen; n++) { - if (str[n] == '\b') { - if (bold) - sidelen = strlcat(side, - ansi(s, ANSI_RESET, ANSI_REVERSE, ANSI_END), - sizeof(sides[0])); - else - sidelen = strlcat(side, ansi_bold(s), - sizeof(sides[0])); - - bold = !bold; - } else { - side[sidelen++] = str[n]; - } - - if (sidelen >= sizeof(sides[0])) - break; - } - - side[sidelen] = '\0'; - } - - pad = s->terminal_columns; - if (left_str) - pad -= ansi_strip(sides[0], NULL); - if (right_str) - pad -= ansi_strip(sides[1], NULL); - - barlen = strlcat(bar, sides[0], sizeof(bar)); - - for (; pad > 0 && barlen < sizeof(bar); pad--) - bar[barlen++] = ' '; - - barlen = strlcat(bar, sides[1], sizeof(bar)); - barlen = strlcat(bar, ansi(s, ANSI_RESET, ANSI_END), sizeof(bar)); - - if (barlen > sizeof(bar)) - panic("session_bar: bar overflow!"); - - return bar; -} - size_t session_expand_template(struct session *session, const char *tmpl, char **ret) --- session.h Fri Jul 15 22:42:37 2022 +++ session.h Sat Jul 16 14:32:32 2022 @@ -138,7 +138,6 @@ size_t session_expand_template(struct session *session char **ret); char * session_field_input(struct session *session, unsigned short size, unsigned short width, char *initial_input, bool multiline, char mask); -char * session_bar(struct session *s, char *left_str, char *right_str); void session_pause_return(struct session *s, char enforce, char *msg); void session_recents(struct session *s); void session_who(struct session *s);