production quality software(tm)
This commit is contained in:
parent
df36cc6d11
commit
355501614f
87
tls2.c
87
tls2.c
|
@ -95,39 +95,90 @@ void manager(void *newdata, ll **ptr, ll **head) {
|
||||||
(*ptr)->data = newdata;
|
(*ptr)->data = newdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int is_link(char *c) {
|
||||||
|
return c[0] == '=' && c[1] == '>';
|
||||||
|
}
|
||||||
|
|
||||||
|
ll *scroll_ll(int direction, ll *current) {
|
||||||
|
if(direction) {
|
||||||
|
if(current->next) {
|
||||||
|
return current->next;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(current->prev) {
|
||||||
|
return current->prev;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return current;
|
||||||
|
}
|
||||||
|
|
||||||
|
void render(int yinit, int ymax, ll *data) {
|
||||||
|
ll *ptr2 = data;
|
||||||
|
erase();
|
||||||
|
while(ptr2) {
|
||||||
|
mvprintw(yinit++, 0, "%s", ptr2->data);
|
||||||
|
ptr2 = ptr2->next;
|
||||||
|
if(yinit == ymax) break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ll *fetch_and_render(struct tls *ctx, int yinit, int ymax, char *url) {
|
||||||
|
tls_write(ctx, url, strlen(url));
|
||||||
|
tls_write(ctx, "\r\n", 2);
|
||||||
|
ll *doc = NULL, *dochead = NULL, *links = NULL, *linkhead = NULL;
|
||||||
|
char *c;
|
||||||
|
int to_screen = 0;
|
||||||
|
|
||||||
|
while(c = tls_incremental_line_read(ctx)) {
|
||||||
|
manager(c, &doc, &dochead);
|
||||||
|
if(is_link(c)) manager(c, &links, &linkhead);
|
||||||
|
if(!to_screen) {
|
||||||
|
mvwprintw(stdscr, yinit++, 0, "%s", c);
|
||||||
|
} else if(to_screen == 1) {
|
||||||
|
refresh();
|
||||||
|
to_screen++;
|
||||||
|
}
|
||||||
|
if(yinit == ymax) to_screen = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ll *document = malloc(sizeof *document);
|
||||||
|
ll *rlinks = malloc(sizeof *rlinks);
|
||||||
|
|
||||||
|
document->data = dochead;
|
||||||
|
document->next = rlinks;
|
||||||
|
document->prev = NULL;
|
||||||
|
|
||||||
|
rlinks->data = linkhead;
|
||||||
|
rlinks->next = NULL;
|
||||||
|
rlinks->prev = document;
|
||||||
|
|
||||||
|
return document;
|
||||||
|
}
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
struct tls *ctx = dial("tilde.club", "1965");
|
struct tls *ctx = dial("tilde.club", "1965");
|
||||||
char *c;
|
int tx, ty;
|
||||||
|
getmaxyx(stdscr, ty, tx);
|
||||||
char getchb;
|
char getchb;
|
||||||
int y = 0;
|
|
||||||
ll *ptr = NULL, *head = NULL;
|
ll *ptr = NULL, *head = NULL;
|
||||||
|
|
||||||
tls_write(ctx, &towrite, sizeof towrite);
|
tls_write(ctx, &towrite, sizeof towrite);
|
||||||
|
|
||||||
ncurses_init();
|
ncurses_init();
|
||||||
|
ll *docdata = fetch_and_render(ctx, 1, ty, "gemini://tilde.club/");
|
||||||
|
|
||||||
while(c = tls_incremental_line_read(ctx)) {
|
ptr = docdata->data;
|
||||||
manager(c, &ptr, &head);
|
|
||||||
mvprintw(y++, 0, "%s", c);
|
|
||||||
}
|
|
||||||
|
|
||||||
ptr = head;
|
|
||||||
ll *ptr2 = ptr;
|
|
||||||
|
|
||||||
while(ptr) {
|
while(ptr) {
|
||||||
getchb = getch();
|
getchb = getch();
|
||||||
erase();
|
|
||||||
ptr2 = ptr;
|
|
||||||
y = 0;
|
|
||||||
while(ptr2) {
|
|
||||||
mvprintw(y++, 0, "%s", ptr2->data);
|
|
||||||
ptr2 = ptr2->next;
|
|
||||||
}
|
|
||||||
if(getchb == 'k') {
|
if(getchb == 'k') {
|
||||||
if(ptr->prev) ptr = ptr->prev;
|
ptr = scroll_ll(TRUE, ptr);
|
||||||
|
} else if(getchb == 'q') {
|
||||||
|
ptr = NULL;
|
||||||
} else {
|
} else {
|
||||||
if(ptr->next) ptr = ptr->next;
|
ptr = scroll_ll(FALSE, ptr);
|
||||||
}
|
}
|
||||||
|
render(1, ty, ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
ncurses_cleanup();
|
ncurses_cleanup();
|
||||||
|
|
Loading…
Reference in New Issue