AmendHub

Download:

jcs

/

subtext

/

amendments

/

443

board: Allow < and > to iterate through posts, even through pages

Add prompt help for each screen

jcs made amendment 443 about 1 year ago
--- board.c Thu Mar 23 11:04:34 2023 +++ board.c Sat Mar 25 21:29:51 2023 @@ -31,8 +31,8 @@ #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 +#define POST_READ_RETURN_NEWER -4 +#define POST_READ_RETURN_OLDER -5 const struct struct_field board_fields[] = { { "Board ID", CONFIG_TYPE_LONG, @@ -170,6 +170,8 @@ board_list_ftn_areas(struct session *s) { 'q', "QqXx", "Return to main menu" }, { '?', "?", "List menu options" }, }; + static const char prompt_help[] = + "#:View Area L:List Areas Q:Return ?:Help"; struct board *fboards = NULL, tboard; struct fidopkt_address our_address; size_t nfboards; @@ -245,8 +247,9 @@ board_list_ftn_areas(struct session *s) show_list = false; } - c = session_menu(s, title, db->config.ftn_network, opts, - nitems(opts), show_help, "Area #", &an); + c = session_menu(s, title, db->config.ftn_network, + (char *)prompt_help, opts, nitems(opts), show_help, "Area #", + &an); show_help = false; switch (c) { @@ -279,19 +282,21 @@ board_show(struct session *s, short id, char *prompt_p { static const struct session_menu_option opts[] = { { '#', "#", "Enter post to read" }, - { '<', "<", "Previous page of posts" }, + { '<', "<", "View newer posts" }, { 'l', "Ll", "List posts" }, - { '>', ">", "Next page of posts" }, + { '>', ">", "View older posts" }, { 'p', "Pp", "Post new thread" }, { 'q', "QqXx", "Return to main menu" }, { '?', "?", "List menu options" }, }; + static const char prompt_help[] = + "#:Read <:Newer >:Older L:List P:New Q:Return ?:Help"; char prompt[7 + member_size(struct board, name)]; struct board *board = NULL; size_t n, nall_post_ids, page, pages, npost_ids; unsigned long *post_ids = NULL; short ppp, ret, pn; - char c; + char c, next_c; bool done, find_post_ids, show_list, show_help; for (n = 0; n < db->nboards; n++) { @@ -312,6 +317,7 @@ board_show(struct session *s, short id, char *prompt_p show_list = true; show_help = false; done = false; + next_c = 0; if (prompt_prefix == NULL) prompt_prefix = "Boards"; @@ -344,9 +350,15 @@ board_show(struct session *s, short id, char *prompt_p show_list = false; } - c = session_menu(s, board->description, prompt, opts, - nitems(opts), show_help, "Post #", &pn); - show_help = false; + if (next_c) { + c = next_c; + next_c = 0; + } else { + c = session_menu(s, board->description, prompt, + (char *)prompt_help, opts, nitems(opts), show_help, "Post #", + &pn); + show_help = false; + } handle_opt: switch (c) { @@ -396,12 +408,40 @@ check_pn: 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; + case POST_READ_RETURN_NEWER: + if (pn == 1) { + if (page == 0) { + session_printf(s, "No newer posts.\r\n"); + session_flush(s); + break; + } else { + page--; + find_post_ids = true; + pn = npost_ids; + next_c = '#'; + } + } else { + pn--; + goto check_pn; + } + break; + case POST_READ_RETURN_OLDER: + if (pn == npost_ids) { + if (page == pages - 1) { + session_printf(s, "No more posts.\r\n"); + session_flush(s); + break; + } else { + page++; + find_post_ids = true; + pn = 1; + next_c = '#'; + } + } else { + pn++; + goto check_pn; + } + break; default: c = ret; goto handle_opt; @@ -437,7 +477,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); @@ -741,13 +781,15 @@ board_post_read(struct session *s, struct board *board unsigned long id, short idx) { static const struct session_menu_option opts[] = { - { 'd', "Dd", "Delete this post" }, - { 'n', "Nn", "Read next post" }, - { 'p', "Pp", "Read previous post" }, + { '<', "<Nn", "Read newer post" }, + { '>', ">Pp", "Read older post" }, { 'r', "Rr", "Reply to this post" }, + { 'd', "Dd", "Delete this post" }, { 'q', "QqXx", "Return to threads" }, { '?', "?", "List these options" }, }; + static const char prompt_help[] = + "<:Newer >:Older R:Reply D:Delete Q:Return ?:Help"; char time[32], prompt[7 + member_size(struct board, name) + 8]; struct board_thread thread; struct board_post post; @@ -857,8 +899,8 @@ board_post_read(struct session *s, struct board *board subject = thread.subject; while (!done && !s->ending) { - c = session_menu(s, subject, prompt, dopts, nitems(opts), - show_help, NULL, NULL); + c = session_menu(s, subject, prompt, (char *)prompt_help, dopts, + nitems(opts), show_help, NULL, NULL); show_help = false; switch (c) { @@ -911,12 +953,12 @@ board_post_read(struct session *s, struct board *board done = true; } break; - case 'n': - ret = POST_READ_RETURN_NEXT; + case '<': + ret = POST_READ_RETURN_NEWER; done = true; break; - case 'p': - ret = POST_READ_RETURN_PREVIOUS; + case '>': + ret = POST_READ_RETURN_OLDER; done = true; break; case 'q':