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 ae43b9190e1a18796222b94ec1e78b35f5826964
parent c0c891f87b101db98c589da9a60e4a39bf048f0d
Author: René Wagner <rwagner@rw-net.de>
Date:   Wed, 23 Dec 2020 18:06:50 +0100

add coloring of headings and links

modify indenting of gemtext lines to always
indent 4 chars

Diffstat:
Msrc/gmnlm.c | 35++++++++++++++++++++++-------------
1 file changed, 22 insertions(+), 13 deletions(-)

diff --git a/src/gmnlm.c b/src/gmnlm.c @@ -19,6 +19,14 @@ #include <gmni/url.h> #include "util.h" +#define ANSI_COLOR_RED "\x1b[31m" +#define ANSI_COLOR_GREEN "\x1b[32m" +#define ANSI_COLOR_YELLOW "\x1b[33m" +#define ANSI_COLOR_BLUE "\x1b[34m" +#define ANSI_COLOR_MAGENTA "\x1b[35m" +#define ANSI_COLOR_CYAN "\x1b[36m" +#define ANSI_COLOR_RESET "\x1b[0m" + struct link { char *url; struct link *next; @@ -767,7 +775,7 @@ display_gemini(struct browser *browser, struct gemini_response *resp) out = fopen("/dev/null", "w+"); } - fprintf(out, "\n\n"); + fprintf(out, "\n"); char *text = NULL; int row = 0, col = 0; struct gemini_token tok; @@ -776,20 +784,20 @@ display_gemini(struct browser *browser, struct gemini_response *resp) repeat: switch (tok.token) { case GEMINI_TEXT: - col += fprintf(out, " "); + col += fprintf(out, " "); if (text == NULL) { text = tok.text; } break; case GEMINI_LINK: if (text == NULL) { - col += fprintf(out, "%d) ", nlinks++); + col += fprintf(out, "%2d> %s", nlinks++, ANSI_COLOR_CYAN); text = trim_ws(tok.link.text ? tok.link.text : tok.link.url); *next = calloc(1, sizeof(struct link)); (*next)->url = strdup(trim_ws(tok.link.url)); next = &(*next)->next; } else { - col += fprintf(out, " "); + col += fprintf(out, " "); } break; case GEMINI_PREFORMATTED_BEGIN: @@ -799,6 +807,7 @@ repeat: continue; // Not used case GEMINI_PREFORMATTED_TEXT: if (text == NULL) { + fprintf(out, " "); text = tok.preformatted; } break; @@ -807,34 +816,33 @@ repeat: browser->page_title = strdup(tok.heading.title); } if (text == NULL) { - for (int n = tok.heading.level; n; --n) { - col += fprintf(out, "#"); - } switch (tok.heading.level) { case 1: - col += fprintf(out, " "); + col += fprintf(out, "%s%s", " # ", ANSI_COLOR_RED); break; case 2: + col += fprintf(out, "%s%s", " ## ", ANSI_COLOR_YELLOW); + break; case 3: - col += fprintf(out, " "); + col += fprintf(out, "%s%s", "### ", ANSI_COLOR_GREEN); break; } text = trim_ws(tok.heading.title); } else { - col += fprintf(out, " "); + col += fprintf(out, " "); } break; case GEMINI_LIST_ITEM: if (text == NULL) { - col += fprintf(out, " %s ", + col += fprintf(out, " %s ", browser->unicode ? "•" : "*"); text = trim_ws(tok.list_item); } else { - col += fprintf(out, " "); + col += fprintf(out, " "); } break; case GEMINI_QUOTE: - col += fprintf(out, " %s ", + col += fprintf(out, " %s ", browser->unicode ? "┃" : ">"); if (text == NULL) { text = trim_ws(tok.quote_text); @@ -878,6 +886,7 @@ repeat: } ++row; col = 0; + fprintf(out, ANSI_COLOR_RESET); if (browser->pagination && row >= ws.ws_row - 4) { char prompt[4096]; char *end = NULL;