youtube/gopher: add simple soft line-wrapping - frontends - front-ends for some sites (experiment) (DIR) Log (DIR) Files (DIR) Refs (DIR) README (DIR) LICENSE --- (DIR) commit 4dcebc72f5a00e9b94a8e2338fb0127662933fa3 (DIR) parent bf8c35a7535d6791e618edc08a055822cba4e304 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org> Date: Tue, 28 Feb 2023 20:38:01 +0100 youtube/gopher: add simple soft line-wrapping Disable hard line-wrapping and keep it simple for now. Diffstat: M youtube/gopher.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) --- (DIR) diff --git a/youtube/gopher.c b/youtube/gopher.c @@ -157,7 +157,8 @@ render_video(struct video_response *r) { char buf[256]; const char *s, *e; - int i; + /* softwrap: try to wrap on word boundary, otherwise hardwrap */ + int i, sw = 72, hw = 9999; if (pledge("stdio", NULL) == -1) exit(1); @@ -221,7 +222,8 @@ render_video(struct video_response *r) for (s = e = r->shortdescription; ; e++) { if (!i) putchar('i'); - if (*e == '\n' || *e == '\0') { + if (*e == '\n' || *e == '\0' || + i > hw || (i > sw && (*e == ' ' || *e == '\t'))) { i = 0; gophertext(stdout, s, e - s); printf("\t%s\t%s\t%s\r\n", "", host, port); @@ -229,7 +231,9 @@ render_video(struct video_response *r) break; s = e + 1; } else { - i = 1; + /* start of rune, wrongly assume 1 rune is 1 column for now */ + if (!((unsigned char)*e & 0x80)) + i++; } } }