diff options
author | Shav Kinderlehrer <[email protected]> | 2024-07-23 17:48:28 -0400 |
---|---|---|
committer | Shav Kinderlehrer <[email protected]> | 2024-07-23 17:48:28 -0400 |
commit | dc0f2ce9ba97ebb47e05b80a511da6eb29818b63 (patch) | |
tree | dc83035069f5a015047be1ca3da6f65781eb4695 /src/main.c | |
parent | f638f4bd1e3a03bc2bdd5f9dcd57d4830fd3c553 (diff) | |
download | molehole-ncurses.tar.gz molehole-ncurses.zip |
Merge old-moleholencurses
Diffstat (limited to 'src/main.c')
-rwxr-xr-x | src/main.c | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c new file mode 100755 index 0000000..26090ff --- /dev/null +++ b/src/main.c @@ -0,0 +1,83 @@ +#include <ncurses.h> +#include <openssl/ssl.h> +#include <stdlib.h> + +#include "color.h" +#include "config.h" +#include "connect.h" +#include "net.h" +#include "request.h" +#include "response.h" +#include "status.h" +#include "url.h" +#include "util.h" + +void exit_cleanup(void) { endwin(); } + +void init_ncurses(void) { + initscr(); + cbreak(); + noecho(); + + curs_set(0); + keypad(stdscr, TRUE); + scrollok(stdscr, TRUE); + + if (!has_colors()) + die("Terminal does not support colors"); + + start_color(); + set_colors(); + + refresh(); +} + +int main(void) { + struct config conf; + init_config(&conf); + + init_ncurses(); + atexit(exit_cleanup); + + getmaxyx(stdscr, conf.i.height, conf.i.width); + + init_status(&conf); + conf.s.url = init_url(); + conf.s.conn = init_connection(); + + prompt_status_url(&conf); + update_status(&conf, conf.s.url_string); + + int rc = parse_url(conf.s.url, conf.s.url_string); + if (rc < 0) { + error_status(&conf, "Invalid URL"); + conf_cleanup(&conf); + return 1; + } + + rc = tls_connect(&conf, *conf.s.url); + if (rc < 0) { + conf_cleanup(&conf); + return 1; + } + + struct request req; + req.kind = GET; + req.url = *conf.s.url; + send_request(&conf, &req); + + struct response res; + rc = read_response(&conf, &res); + if (rc < 0) { + conf_cleanup(&conf); + return rc * -1; + } + conf.s.res = &res; + + printw("%s\n", conf.s.res->content); + + getch(); + + conf_cleanup(&conf); + return 0; +} |