diff options
| author | katalx | 2026-02-02 04:12:07 -0500 |
|---|---|---|
| committer | katalx | 2026-02-02 04:12:07 -0500 |
| commit | b6d231847a0541f545c2b64d84f71c58841d60ec (patch) | |
| tree | 20879622f1484d13c0f6c21ac972b987c08dfdd2 /main.c | |
| parent | 4849ea60928f118cc4747b79c227f53c86f70ac9 (diff) | |
more junk
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 35 |
1 files changed, 29 insertions, 6 deletions
@@ -3,6 +3,7 @@ #include <fcntl.h> #include <limits.h> #include <sys/socket.h> +#include <sys/ioctl.h> #include <netinet/in.h> #include <netdb.h> @@ -350,6 +351,15 @@ fetch(Str *buf, Request req, Arena *perm, Arena *scratch) } } +void +term_size(int *rows, int *cols) +{ + struct winsize sz = { 0 }; + ioctl(STDOUT_FILENO, TIOCGWINSZ, &sz); + if (rows) *rows = sz.ws_row; + if (cols) *cols = sz.ws_col; +} + int main(void) { @@ -357,21 +367,34 @@ main(void) Request req = { 0 }; addr_init(); - printf("parse_request() -> %d\n", parse_request(S("file://main.c"), &req)); + printf("parse_request() -> %d\n", parse_request(S("gopher://tilde.town"), &req)); printf("host = %.*s\n", (int)req.host.n, req.host.s); printf("path = %.*s\n", (int)req.path.n, req.path.s); printf("prot = %d\n", req.proto); printf("port = %d\n", req.port); Str buf = { 0 }; - printf("fetch() -> %d\n", fetch(&buf, req, &scratch, &scratch)); - Doc doc = { .arena = scratch, .src = buf }; + DocType t = fetch(&buf, req, &scratch, &scratch); + printf("fetch() -> %d\n", t); + Doc doc = { .arena = scratch, .src = buf, .type = t }; printf("parse() -> %d\n", parse_doc(&doc)); - int i = 0; - for (DocLine *l = doc.head; l && i < 10; (l = l->next), i++) { - printf("%d %.*s\n", i, (int)l->s.n, l->s.s); + + DocLine *l = doc.head; + while (l) { + int ln; + term_size(&ln, NULL); + for (int i = 0; l && i < ln - 1; i++) { + printf("%.*s\n", (int)l->s.n, l->s.s); + l = l->next; + } + char buf[1024] = { 0 }; + printf("* "); + fflush(stdout); + fgets(buf, 1023, stdin); + if (buf[0] == 'q') break; } + puts("Goodbye!"); addr_fini(); return 0; } |
