💾 Archived View for gemini.rmf-dev.com › repo › Vaati › Vgmi › files › da124580ee0bfc37958712f270232… captured on 2024-02-05 at 10:01:13. Gemini links have been rewritten to link to archived content

View Raw

More Information

-=-=-=-=-=-=-

Go Back

0 /*

1 * ISC License

2 * Copyright (c) 2023 RMF <rawmonk@firemail.cc>

3 */

4 #include <stdlib.h>

5 #include <stdint.h>

6 #include "macro.h"

7 #include "wcwidth.h"

8 #include "termbox.h"

9 #define PAGE_INTERNAL

10 #include "page.h"

11 #include "request.h"

12 #define PARSER_INTERNAL

13 #include "parser.h"

14

15 int parse_plain(int in, size_t length, int width, int out) {

16

17 size_t i;

18 struct termwriter termwriter = {0};

19

20 if (width < 10) width = 10;

21

22 termwriter.width = width - OFFSETX;

23 termwriter.fd = out;

24 termwriter.pos = 0;

25

26 for (i = 0; i < length;) {

27 uint32_t ch;

28 struct page_cell cell = {0};

29

30 if (readnext(in, &ch, &i, length)) return -1;

31 if (!renderable(ch)) continue;

32 if (ch == '\n') {

33 cell.special = PAGE_NEWLINE;

34 } else {

35 cell.codepoint = ch;

36 cell.width = mk_wcwidth(ch);

37 cell.color = TB_DEFAULT;

38 }

39 writecell(&termwriter, cell, i);

40 }

41

42 {

43 struct page_cell cell = {0};

44 cell.special = PAGE_EOF;

45 writecell(&termwriter, cell, i);

46 }

47 return 0;

48 }

49