AmendHub

Download:

jcs

/

subtext

/

amendments

/

467

session: Turn word wrap into paginator, use in boards+mail


jcs made amendment 467 11 months ago
--- board.c Thu Apr 6 17:48:03 2023 +++ board.c Fri Apr 7 14:11:08 2023 @@ -934,11 +934,9 @@ board_post_read(struct session *s, struct board *board session_printf(s, "{{B}}Subject:{{/B}}{{#}} %s%s\r\n", (fpost.reply[0] && strncasecmp(fpost.subject, "Re:", 3) != 0 ? "Re: " : ""), fpost.subject); - session_flush(s); session_printf(s, "\r\n"); - session_output_word_wrapped(s, fpost.body, fpost.body_size, - s->terminal_columns - 1); - session_printf(s, "\r\n"); + session_flush(s); + session_paginate(s, fpost.body, fpost.body_size, 6); } else { size = bile_read_alloc(board->bile, BOARD_POST_RTYPE, id, &data); if (size == 0) @@ -982,11 +980,9 @@ board_post_read(struct session *s, struct board *board db->config.timezone); session_printf(s, "{{B}}Subject:{{/B}}{{#}} %s%s\r\n", (post.parent_post_id ? "Re: " : ""), thread.subject); - session_flush(s); session_printf(s, "\r\n"); - session_output_word_wrapped(s, post.body, post.body_size, - s->terminal_columns - 1); - session_printf(s, "\r\n"); + session_flush(s); + session_paginate(s, post.body, post.body_size, 5); } snprintf(prompt, sizeof(prompt), "%s:%d", prompt_prefix, idx); --- mail.c Thu Mar 23 22:51:34 2023 +++ mail.c Fri Apr 7 14:11:21 2023 @@ -637,11 +637,9 @@ mail_read(struct session *s, unsigned long id, short i session_printf(s, "{{B}}Date:{{/B}} %s %s\r\n", time, db->config.timezone); session_printf(s, "{{B}}Subject:{{/B}}{{#}} %s\r\n", msg.subject); - session_flush(s); session_printf(s, "\r\n"); - session_output(s, msg.body, msg.body_size); - session_printf(s, "\r\n"); session_flush(s); + session_paginate(s, msg.body, msg.body_size, 5); if (!msg.read) { msg.read = Time; --- session.c Thu Apr 6 17:03:45 2023 +++ session.c Fri Apr 7 14:42:41 2023 @@ -576,11 +576,14 @@ session_output(struct session *session, const char *st } size_t -session_output_word_wrapped(struct session *session, const char *str, - size_t len, size_t line_len) +session_paginate(struct session *session, const char *str, size_t len, + size_t first_page_printed) { size_t olen = 0, n, adv, last_space = 0; - + size_t olines = first_page_printed; + size_t line_len = session->terminal_columns; + short last_input = 0; + while (len && !session->ending) { for (n = 0, adv = 0; n < line_len && n < len; n++) { if (str[n] == '\r') { @@ -607,9 +610,28 @@ session_output_word_wrapped(struct session *session, c olen += last_space; str += adv; len -= adv; - if (len) { - session_output(session, "\r\n", 2); - olen += 2; + + session_output(session, "\r\n", 2); + olen += 2; + olines++; + + if (len && (olines == session->terminal_lines - 1 || + last_input == '\r' || last_input == '\n')) { + olines = 0; + + session_printf(session, "-- More --"); + session_flush(session); + + last_input = session_input_char(session); + + if (session->vt100) + session_printf(session, "\r%s", + ansi(session, ANSI_ERASE_LINE, ANSI_END)); + else + session_output(session, "\r", 1); + + if (last_input == 'q' || last_input == 'Q') + break; } } --- session.h Sat Mar 25 21:55:51 2023 +++ session.h Fri Apr 7 14:10:56 2023 @@ -136,8 +136,8 @@ void session_flush(struct session *session); size_t session_logf(struct session *session, const char *format, ...); size_t session_logf_buffered(struct session *session, const char *format, ...); size_t session_output(struct session *session, const char *str, size_t len); -size_t session_output_word_wrapped(struct session *session, const char *str, - size_t len, size_t line_len); +size_t session_paginate(struct session *session, const char *str, + size_t len, size_t first_page_printed); size_t session_printf(struct session *session, const char *format, ...); size_t session_output_view_or_printf(struct session *session, short id, const char *format, ...);