Introduction
Introduction Statistics Contact Development Disclaimer Help
youtube/gopher: add simple soft line-wrapping - frontends - front-ends for some…
Log
Files
Refs
README
LICENSE
---
commit 4dcebc72f5a00e9b94a8e2338fb0127662933fa3
parent bf8c35a7535d6791e618edc08a055822cba4e304
Author: Hiltjo Posthuma <[email protected]>
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(-)
---
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 c…
+ if (!((unsigned char)*e & 0x80))
+ i++;
}
}
}
You are viewing proxied material from codemadness.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.