💾 Archived View for gemini.rmf-dev.com › repo › Vaati › VgmiTL › files › aac4be838fc42cc1538a34bc6db… captured on 2022-07-16 at 17:13:06. Gemini links have been rewritten to link to archived content
-=-=-=-=-=-=-
0 /* See LICENSE file for copyright and license details. */
1 #include <strings.h>
2 #include <termbox.h>
3 #include "gemini.h"
4
5 void tb_colorline(int x, int y, uintattr_t color) {
6 for (int i=x; i<tb_width(); i++)
7 tb_set_cell(i, y, ' ', color, color);
8 }
9
10 void display() {
11 struct gmi_tab* tab = &client.tabs[client.tab];
12 struct gmi_page* page = &tab->page;
13 tb_clear();
14
15 if (client.input.mode) {
16 if (page->code == 11 || page->code == 10)
17 tb_set_cursor(client.input.cursor+strnlen(client.input.label,
18 sizeof(client.input.label))+2, tb_height()-1);
19 else
20 tb_set_cursor(client.input.cursor, tb_height()-1);
21 }
22
23 if (page->code == 20 || page->code == 10 || page->code == 11) {
24 tb_clear();
25 if (client.tabs_count > 1) tab->scroll--;
26 page->lines = gmi_render(tab);
27 if (client.tabs_count > 1) tab->scroll++;
28 } else if (tab->error[0] != '\0') {
29 tb_printf(2, 1+(client.tabs_count>1), TB_RED, TB_DEFAULT,
30 "# %!s(MISSING)", tab->error);
31 }
32
33 // current tab
34 if (client.tabs_count > 1) {
35 tb_colorline(0, 0, TB_WHITE);
36 tb_printf(0, 0, TB_BLACK, TB_WHITE,
37 "Tabs : %!d(MISSING)/%!d(MISSING)", client.tab+1, client.tabs_count);
38 }
39
40 // current url
41 tb_colorline(0, tb_height()-2, TB_WHITE);
42 char urlbuf[MAX_URL];
43 int hide = 0;
44 int posx = 0;
45 for (int i=0; tab->url[i]; i++) {
46 if (hide && (tab->url[i] == '/')) {
47 hide = 0;
48 }
49 if (!hide) {
50 urlbuf[posx] = tab->url[i];
51 posx++;
52 }
53 if (!hide && tab->url[i] == '?') {
54 hide = 1;
55 urlbuf[posx] = '<';
56 urlbuf[posx+1] = '*';
57 urlbuf[posx+2] = '>';
58 posx+=3;
59 }
60 }
61 urlbuf[posx] = '\0';
62 tb_printf(0, tb_height()-2, TB_BLACK, TB_WHITE, "%!s(MISSING) (%!s(MISSING))", urlbuf, tab->page.meta);
63
64 // Show selected link url
65 if (tab->selected != 0) {
66 int llen = strnlen(tab->selected_url, sizeof(tab->selected_url));
67 tb_printf(tb_width()-llen-5, tb_height()-2, TB_WHITE, TB_BLUE,
68 " => %!s(MISSING) ", tab->selected_url);
69 }
70
71 int count = atoi(client.vim.counter);
72 if (count) {
73 tb_printf(tb_width() - 8, tb_height() - 1, TB_DEFAULT, TB_DEFAULT,
74 "%!d(MISSING)", count);
75 }
76
77 // input
78 if (client.input.error) {
79 tb_hide_cursor();
80 tb_colorline(0, tb_height()-1, TB_RED);
81 tb_print(0, tb_height()-1, TB_WHITE, TB_RED, tab->error);
82 client.input.field[0] = '\0';
83 } else if (client.input.info) {
84 tb_hide_cursor();
85 tb_colorline(0, tb_height()-1, TB_GREEN);
86 tb_print(0, tb_height()-1, TB_WHITE, TB_GREEN, tab->info);
87 client.input.field[0] = '\0';
88 client.input.info = 0;
89 } else if (page->code == 10) {
90 tb_printf(0, tb_height()-1, TB_DEFAULT, TB_DEFAULT,
91 "%!s(MISSING): %!s(MISSING)", client.input.label, client.input.field);
92 } else if (page->code == 11) {
93 char input_buf[1024];
94 size_t i = 0;
95 for (; client.input.field[i] && i < sizeof(client.input.field); i++)
96 input_buf[i] = '*';
97 input_buf[i] = '\0';
98 tb_printf(0, tb_height()-1, TB_DEFAULT, TB_DEFAULT,
99 "%!s(MISSING): %!s(MISSING)", client.input.label, input_buf);
100 } else {
101 tb_printf(0, tb_height()-1, TB_DEFAULT, TB_DEFAULT, "%!s(MISSING)", client.input.field);
102 }
103
104 tb_present();
105 }
106
107 void display_history() {
108 int ret = 0;
109 struct tb_event ev;
110 bzero(&ev, sizeof(ev));
111 do {
112 struct gmi_tab* tab = &client.tabs[client.tab];
113
114 tb_clear();
115 tb_print(2, 1, TB_RED, TB_DEFAULT, "# History");
116
117 if (!tab->history) {
118 tb_present();
119 continue;
120 }
121 int y = 3;
122 for (struct gmi_link* link = tab->history->next; link; link = link->next) {
123 tb_printf(4, y, TB_DEFAULT, TB_DEFAULT, "%!s(MISSING)", link->url);
124 y++;
125 }
126
127 tb_printf(4, y, TB_DEFAULT, TB_BLUE, "-> %!s(MISSING)", tab->history->url);
128 y++;
129
130 for (struct gmi_link* link = tab->history->prev; link; link = link->prev) {
131 tb_printf(4, y, TB_DEFAULT, TB_DEFAULT, "%!s(MISSING)", link->url);
132 y++;
133 }
134
135 tb_present();
136
137 } while(((ret = tb_poll_event(&ev)) == TB_OK && ev.type == TB_EVENT_RESIZE)
138 || ret == -14);
139 }
140
141 int display_download(char* info) {
142 int ret = 0;
143 struct tb_event ev;
144 bzero(&ev, sizeof(ev));
145 do {
146
147 tb_clear();
148 tb_printf(2, 1, TB_RED, TB_DEFAULT, "# Non-renderable meta-data : %!s(MISSING)", info);
149 int w = tb_width();
150 int h = tb_height();
151 const char* line1 = "Press 'y' to download";
152 const char* line2 = "Press any other key to cancel";
153 int x = w/2-strlen(line1)/2;
154 tb_printf(x, h/2-1, TB_DEFAULT, TB_DEFAULT, line1);
155 tb_printf(x+7, h/2-1, TB_GREEN, TB_DEFAULT, "y");
156 tb_printf(w/2-strlen(line2)/2, h/2, TB_DEFAULT, TB_DEFAULT, line2);
157
158 tb_present();
159
160 } while(((ret = tb_poll_event(&ev)) == TB_OK && ev.type == TB_EVENT_RESIZE)
161 || ret == -14);
162 return ev.ch == 'y' || ev.ch == 'Y';
163 }
164
165 int display_open(char* path) {
166 int ret = 0;
167 struct tb_event ev;
168 bzero(&ev, sizeof(ev));
169 do {
170
171 tb_clear();
172 tb_printf(2, 1, TB_RED, TB_DEFAULT, "# %!s(MISSING) downloaded", path);
173 int w = tb_width();
174 int h = tb_height();
175 const char* line1 = "Press 'y' to open";
176 const char* line2 = "Press any other key to cancel";
177 int x = w/2-strlen(line1)/2;
178 tb_printf(x, h/2-1, TB_DEFAULT, TB_DEFAULT, line1);
179 tb_printf(x+7, h/2-1, TB_GREEN, TB_DEFAULT, "y");
180 tb_printf(w/2-strlen(line2)/2, h/2, TB_DEFAULT, TB_DEFAULT, line2);
181
182 tb_present();
183
184 } while(((ret = tb_poll_event(&ev)) == TB_OK && ev.type == TB_EVENT_RESIZE)
185 || ret == -14);
186 return ev.ch == 'y' || ev.ch == 'Y';
187 }
188
189