cgmnlm

Unnamed repository; edit this file 'description' to name the repository.
git clone git://code.clttr.info/cgmnlm.git
Log | Files | Refs | README | LICENSE

commit 801d9b8f13f6adef25fb14ec2e9acbc6dd4e92a9
parent 78cfe1b669fad6b7a3638d371ed9825e2ee53243
Author: René Wagner <rwagner@rw-net.de>
Date:   Thu, 25 Mar 2021 20:19:46 +0100

allow toggling between preformatted and alt text

alt text is prefixed with A
preformatted text is prefixed with P

closes #13 #10

Diffstat:
MREADME.md | 2+-
Msrc/gmnlm.c | 24++++++++++++++++++++----
2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/README.md b/README.md @@ -29,7 +29,7 @@ It includes the following modifications: - k command to remove the bookmark for the current page - e[N] command to open a link in default external program (requires `xdg-open`) - t[N] command to download the content behind a link to a temporary file -- b & f commands to navigate history can jump multiple entries at once +- a command to switch between display of preformatted blocks and alt text (if available) The actual colors used depend on your terminal palette: - heading 1: light red diff --git a/src/gmnlm.c b/src/gmnlm.c @@ -44,7 +44,7 @@ struct history { }; struct browser { - bool pagination, unicode; + bool pagination, unicode, alttext; int max_width; struct gemini_options opts; struct gemini_tofu tofu; @@ -103,6 +103,7 @@ const char *help_msg = "d <path>\tDownload page to <path>\n" "|<prog>\t\tPipe page into program\n" "[N]|<prog>\tPipe content of Nth link into program\n" + "a\t\ttoggle usage of alt text instead of preformatted text\n" "q\t\tQuit\n" "\n" ; @@ -636,6 +637,11 @@ do_prompts(const char *prompt, struct browser *browser) set_url(browser, "gemini://geminispace.info/search", &browser->history); result = PROMPT_ANSWERED; goto exit; + case 'a': + browser->alttext = !browser->alttext; + fprintf(browser->tty, "Alttext instead of preformatted block is now %s\n", browser->alttext ? "ENABLED" : "DISABLED"); + result = PROMPT_AGAIN; + goto exit; case 'b': if (in[1]) historyhops =(int)strtol(in+1, &endptr, 10); while (historyhops > 0) { @@ -939,6 +945,7 @@ display_gemini(struct browser *browser, struct gemini_response *resp) fprintf(out, "\n"); char *text = NULL; int row = 0, col = 0; + bool no_alttext; struct gemini_token tok; struct link **next = &browser->links; while (text != NULL || gemini_parser_next(&p, &tok) == 0) { @@ -962,13 +969,21 @@ repeat: } break; case GEMINI_PREFORMATTED_BEGIN: - gemini_token_finish(&tok); + if (text == NULL && browser->alttext) { + if (tok.preformatted == NULL) { + no_alttext = true; + } else { + fprintf(out, " A %s", ANSI_COLOR_GRAY); + text = tok.preformatted; + } + } + break; /* fallthrough */ case GEMINI_PREFORMATTED_END: continue; // Not used case GEMINI_PREFORMATTED_TEXT: - if (text == NULL) { - fprintf(out, " %s", ANSI_COLOR_GRAY); + if (text == NULL && (!browser->alttext || no_alttext)) { + fprintf(out, " P %s", ANSI_COLOR_GRAY); text = tok.preformatted; } break; @@ -1241,6 +1256,7 @@ main(int argc, char *argv[]) { struct browser browser = { .pagination = true, + .alttext = false, .tofu_mode = TOFU_ASK, .unicode = true, .url = curl_url(),