Skip to content

Commit

Permalink
node.c: Default terminal size to 80x24.
Browse files Browse the repository at this point in the history
The default terminal size is 80 x 24, but this
is left zero-initialized, which means that dial-in
clients were only shown a single column in menus,
even though their terminal is probably 80 x 24.
Previously, this was left as 0 x 0 to distinguish
an explicit size from the default; for ease of use,
this is changed to 80 x 24 by default, and we use
a separate flag (node->dimensions) to keep track of
having received explicit dimensions.
  • Loading branch information
InterLinked1 committed Feb 4, 2024
1 parent af76ae0 commit ad51c01
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
5 changes: 3 additions & 2 deletions bbs/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,9 @@ static int bbs_menu_run(struct bbs_node *node, const char *menuname, const char
RWLIST_UNLOCK(&menus);
return -1;
}
/* Pause momentarily, or the user won't really see the ANSI art */
if (bbs_node_wait_key(node, MIN_MS(2)) < 0) {
/* Pause momentarily, or the user won't really see the ANSI art.
* ANSI art can take a long time at slow speeds, so be tolerant of that. */
if (bbs_node_wait_key(node, MIN_MS(7)) < 0) {
RWLIST_UNLOCK(&menus);
return -1;
}
Expand Down
13 changes: 10 additions & 3 deletions bbs/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,11 @@ struct bbs_node *__bbs_node_request(int fd, const char *protname, void *mod)
node->protname = protname;
node->ansi = 1; /* Assume nodes support ANSI escape sequences by default. */

/* Assume 80x24 terminal by default, for interactive nodes,
* to support dumb terminals over modems that won't tell us their size. */
node->cols = 80;
node->rows = 24;

/* This prevents this module from being unloaded as long as there are nodes using it.
* For example, since node->protname is constant in this module, if we unload it,
* even though no code is being executed in the module actively, if we list nodes,
Expand Down Expand Up @@ -780,7 +785,8 @@ static int cli_nodes(struct bbs_cli_args *a)
lwp = bbs_pthread_tid(n->thread);

if (NODE_INTERACTIVE(n)) {
snprintf(termsize, sizeof(termsize), "%dx%d", n->cols, n->rows);
/* If the size is speculative, put a '?' afterwards */
snprintf(termsize, sizeof(termsize), "%dx%d%s", n->cols, n->rows, n->dimensions ? "" : "?");
bbs_node_format_speed(n, speed, sizeof(speed));
} else {
termsize[0] = speed[0] = '\0';
Expand Down Expand Up @@ -914,7 +920,7 @@ static int node_info(int fd, unsigned int nodenum)

#define BBS_FMT_S "%-20s : %s\n"
#define BBS_FMT_D "%-20s : %d\n"
#define BBS_FMT_DSD "%-20s : %d%s%d\n"
#define BBS_FMT_DSDS "%-20s : %d%s%d%s\n"

/* This addresses the desire to be able to do something like this:
* bbs_dprintf(fd, n->childpid ? BBS_FMT_D : BBS_FMT_S, "CHILD PID", n->childpid ? n->childpid : "None");
Expand All @@ -939,7 +945,7 @@ static int node_info(int fd, unsigned int nodenum)
if (NODE_INTERACTIVE(n)) {
char speed[NODE_SPEED_BUFSIZ_LARGE];
bbs_node_format_speed(n, speed, sizeof(speed));
bbs_dprintf(fd, BBS_FMT_DSD, "Term Size", n->cols, "x", n->rows);
bbs_dprintf(fd, BBS_FMT_DSDS, "Term Size", n->cols, "x", n->rows, n->dimensions ? "" : "?");
bbs_dprintf(fd, BBS_FMT_S, "Term ANSI", BBS_YN(n->ansi));
bbs_dprintf(fd, BBS_FMT_S, "Term Speed", speed);
bbs_dprintf(fd, BBS_FMT_S, "Term Echo", BBS_YN(n->echo));
Expand Down Expand Up @@ -1035,6 +1041,7 @@ int bbs_node_update_winsize(struct bbs_node *node, int cols, int rows)
*/
node->cols = (unsigned int) cols;
node->rows = (unsigned int) rows;
node->dimensions = 1;
}

/*
Expand Down
1 change: 1 addition & 0 deletions include/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ struct bbs_node {
unsigned int inmenu:1; /*!< Whether actively displaying a menu */
unsigned int ansi:1; /*!< Terminal supports ANSI escape sequences */
unsigned int slow:1; /*!< Terminal is using slow connection */
unsigned int dimensions:1; /*!< Aware of actual terminal dimensions */
/* TDD stuff */
char ioreplace[10][2]; /*!< Character replacement for TDDs and other keyboard input-limited endpoints. 2D list with 10 slots. */
unsigned int ioreplaces; /*!< Number of characters currently being replaced. Purely for speed of access in pty.c */
Expand Down

0 comments on commit ad51c01

Please sign in to comment.