AmendHub

Download:

jcs

/

subtext

/

amendments

/

302

board: Go back to double-digit post numbers in list view

This lets us show 20 at a time (or less if the user's terminal is
short), and avoids the goofy starting-at-zero thing.
 
Also add 'n' and 'p' shortcuts from the post view menu to view the
next and previous posts in the list.

jcs made amendment 302 about 1 year ago
--- board.c Thu Feb 16 14:30:26 2023 +++ board.c Thu Feb 16 17:23:36 2023 @@ -24,11 +24,13 @@ #include "board.h" #include "user.h" -#define POSTS_PER_PAGE 10 +#define POSTS_PER_PAGE 20 #define POST_READ_RETURN_DONE -1 #define POST_READ_RETURN_LIST -2 #define POST_READ_RETURN_FIND -3 +#define POST_READ_RETURN_NEXT -4 +#define POST_READ_RETURN_PREVIOUS -5 const struct struct_field board_fields[] = { { "Board ID", CONFIG_TYPE_LONG, @@ -128,7 +130,7 @@ void board_show(struct session *s, short id) { static const struct session_menu_option opts[] = { - { '#', "#0123456789", "Read post [#]" }, + { '#', "#12", "Enter post to read", true }, { '<', "<", "Previous page of posts" }, { 'l', "Ll", "List posts" }, { '>', ">", "Next page of posts" }, @@ -140,8 +142,8 @@ board_show(struct session *s, short id) struct board *board = NULL; size_t n, nall_post_ids, page, pages, npost_ids; unsigned long *post_ids = NULL; - short ret; - char c; + short ppp, ret, pn; + char c, cn[2], *pn_field = NULL; bool done, find_post_ids, show_list, show_help; for (n = 0; n < db->nboards; n++) { @@ -171,10 +173,13 @@ board_show(struct session *s, short id) xfree(&post_ids); post_ids = NULL; } + ppp = POSTS_PER_PAGE; + if (s->terminal_lines < ppp + 3) + ppp = BOUND(ppp, 5, s->terminal_lines - 3); nall_post_ids = board_find_post_ids(board, &npost_ids, - &post_ids, page * POSTS_PER_PAGE, POSTS_PER_PAGE); - /* ceil(nall_post_ids / POSTS_PER_PAGE) */ - pages = (nall_post_ids + POSTS_PER_PAGE - 1) / POSTS_PER_PAGE; + &post_ids, page * ppp, ppp); + /* ceil(nall_post_ids / ppp) */ + pages = (nall_post_ids + ppp - 1) / ppp; if (page >= pages) page = pages - 1; @@ -222,22 +227,30 @@ handle_opt: find_post_ids = true; show_list = true; break; - case 0: case 1: case 2: - case 3: - case 4: - case 5: - case 6: - case 7: - case 8: - case 9: - if (c >= npost_ids) { + session_printf(s, "\r\n%sPost to View:%s ", + ansi(s, ANSI_BOLD, ANSI_END), ansi(s, ANSI_RESET, ANSI_END)); + session_flush(s); + + cn[0] = c + '0'; + cn[1] = '\0'; + pn_field = session_field_input(s, 3, 2, (char *)&cn, false, 0); + session_printf(s, "\r\n"); + session_flush(s); + if (pn_field == NULL) + break; + + pn = atoi(pn_field); + xfree(&pn_field); + +check_pn: + if (pn < 1 || pn > npost_ids) { session_printf(s, "Invalid post\r\n"); session_flush(s); break; } - ret = board_post_read(s, board, post_ids[c], c); + ret = board_post_read(s, board, post_ids[pn - 1], pn); switch (ret) { case POST_READ_RETURN_DONE: break; @@ -248,6 +261,12 @@ handle_opt: find_post_ids = true; show_list = true; break; + case POST_READ_RETURN_NEXT: + pn++; + goto check_pn; + case POST_READ_RETURN_PREVIOUS: + pn--; + goto check_pn; default: c = ret; goto handle_opt; @@ -282,7 +301,7 @@ board_list_posts(struct session *s, struct board *boar session_printf(s, "{{B}}%s: %s (Page %ld of %ld){{/B}}\r\n", board->name, board->description, page, pages); - session_printf(s, "%s# N Date From Subject%s\r\n", + session_printf(s, "%s# N Date From Subject%s\r\n", ansi(s, ANSI_BOLD, ANSI_END), ansi(s, ANSI_RESET, ANSI_END)); session_flush(s); @@ -351,9 +370,9 @@ board_list_posts(struct session *s, struct board *boar indent_s[j + 2] = '>'; indent_s[j + 3] = '\0'; } - session_printf(s, "%s%ld %c %s %- 10s %s{{#}}%- 40s%s\r\n", + session_printf(s, "%s%2ld %c %s %- 10s %s{{#}}%- 40s%s\r\n", true ? "" : ansi(s, ANSI_BOLD, ANSI_END), - n, + n + 1, true ? ' ' : 'N', time, user ? user->username : "(unknown)", @@ -537,8 +556,9 @@ board_post_read(struct session *s, struct board *board short idx) { static const struct session_menu_option opts[] = { - { '#', "#0123456789", "Read post [#]" }, { 'd', "Dd", "Delete this post" }, + { 'n', "Nn", "Read next post" }, + { 'p', "Pp", "Read previous post" }, { 'r', "Rr", "Reply to this post" }, { 'q', "QqXx", "Return to threads" }, { '?', "?", "List these options" }, @@ -647,17 +667,12 @@ board_post_read(struct session *s, struct board *board done = true; } break; - case 0: - case 1: - case 2: - case 3: - case 4: - case 5: - case 6: - case 7: - case 8: - case 9: - ret = c; + case 'n': + ret = POST_READ_RETURN_NEXT; + done = true; + break; + case 'p': + ret = POST_READ_RETURN_PREVIOUS; done = true; break; case 'q': --- session.c Sun Feb 5 10:42:38 2023 +++ session.c Thu Feb 16 17:23:19 2023 @@ -89,7 +89,7 @@ session_create(char *node, char *via, struct node_func strlcpy(session->log.node, node, sizeof(session->log.node)); strlcpy(session->via, via, sizeof(session->via)); session->last_input_at = session->established_at = Time; - + for (n = 0; n < MAX_SESSIONS; n++) { if (sessions[n] == NULL) { sessions[n] = session; @@ -538,7 +538,7 @@ session_output(struct session *session, const char *st stroff += chunk; len -= chunk; } - + return olen; } @@ -1551,13 +1551,17 @@ get_menu_option: break; if (opts[n].ret == '#') { if (opts[n].key[j] == c && c != '#') { - session_printf(s, "%c\r\n", c); - session_flush(s); + if (!opts[n].supress_output) { + session_printf(s, "%c\r\n", c); + session_flush(s); + } return c - '0'; /* return actual number */ } } else if (opts[n].key[j] == c) { - session_printf(s, "%c\r\n", c); - session_flush(s); + if (!opts[n].supress_output) { + session_printf(s, "%c\r\n", c); + session_flush(s); + } return opts[n].ret; } } @@ -1608,9 +1612,11 @@ session_purge_logs(short days) if (count) { logger_printf("[db] Deleting %ld of %ld log entries", count, n); - for (n = 0; n < count; n++) { - bile_delete(db->sessions_bile, SL_LOG_RTYPE, ids[n]); + for (n = 0; n < count - 1; n++) { + bile_delete(db->sessions_bile, SL_LOG_RTYPE, ids[n], 0); } + bile_delete(db->sessions_bile, SL_LOG_RTYPE, ids[count - 1], + BILE_DELETE_FLAG_PURGE); } if (ids) --- session.h Sat Nov 19 23:19:14 2022 +++ session.h Thu Feb 16 17:22:58 2023 @@ -117,6 +117,7 @@ struct session_menu_option { char ret; char key[15]; char title[50]; + bool supress_output; }; struct session * session_create(char *node, char *via,