aboutsummaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorShav Kinderlehrer <[email protected]>2024-07-23 17:48:28 -0400
committerShav Kinderlehrer <[email protected]>2024-07-23 17:48:28 -0400
commitdc0f2ce9ba97ebb47e05b80a511da6eb29818b63 (patch)
treedc83035069f5a015047be1ca3da6f65781eb4695 /src/ui
parentf638f4bd1e3a03bc2bdd5f9dcd57d4830fd3c553 (diff)
downloadmolehole-ncurses.tar.gz
molehole-ncurses.zip
Merge old-moleholencurses
Diffstat (limited to 'src/ui')
-rwxr-xr-xsrc/ui/color.c10
-rwxr-xr-xsrc/ui/status.c54
2 files changed, 64 insertions, 0 deletions
diff --git a/src/ui/color.c b/src/ui/color.c
new file mode 100755
index 0000000..e834193
--- /dev/null
+++ b/src/ui/color.c
@@ -0,0 +1,10 @@
+#include <ncurses.h>
+
+#include "color.h"
+
+void set_colors(void) {
+ /* fg color, bg color */
+ init_pair(STATUS_MAIN, COLOR_DIM_WHITE, COLOR_GREY);
+ init_pair(STATUS_ERROR, COLOR_DIM_WHITE, COLOR_DIM_RED);
+ init_pair(STATUS_PROMPT, COLOR_GREY, COLOR_DIM_WHITE);
+}
diff --git a/src/ui/status.c b/src/ui/status.c
new file mode 100755
index 0000000..703575d
--- /dev/null
+++ b/src/ui/status.c
@@ -0,0 +1,54 @@
+#include <ncurses.h>
+#include <string.h>
+
+#include "color.h"
+#include "config.h"
+#include "connect.h"
+#include "status.h"
+#include "url.h"
+
+void init_status(struct config *conf) {
+ WINDOW *status = newwin(1, conf->i.width, conf->i.height - 1, 0);
+
+ conf->i.status_win = status;
+ update_status(conf, "");
+}
+
+void update_status(struct config *conf, char *s) {
+ werase(conf->i.status_win);
+ wbkgd(conf->i.status_win, COLOR_PAIR(STATUS_MAIN));
+ wprintw(conf->i.status_win, "%s", s);
+ wrefresh(conf->i.status_win);
+}
+
+void prompt_status_url(struct config *conf) {
+ echo();
+ curs_set(1);
+
+ werase(conf->i.status_win);
+
+ char prompt[] = "Enter a molerat URL: molerat://";
+ werase(conf->i.status_win);
+ wbkgd(conf->i.status_win, COLOR_PAIR(STATUS_PROMPT));
+ wprintw(conf->i.status_win, "%s", prompt);
+ wrefresh(conf->i.status_win);
+
+ char url_string[MAX_URL_LENGTH];
+ wgetstr(conf->i.status_win, url_string);
+
+ char url_string_with_scheme[MAX_URL_LENGTH] = "molerat://";
+ strlcat(url_string_with_scheme, url_string, MAX_URL_LENGTH);
+
+ conf->s.url_string = url_string_with_scheme;
+
+ curs_set(0);
+ noecho();
+}
+
+void error_status(struct config *conf, char *s) {
+ werase(conf->i.status_win);
+ wbkgd(conf->i.status_win, COLOR_PAIR(STATUS_ERROR));
+ wprintw(conf->i.status_win, "Error: %s [Press RETURN]", s);
+ wrefresh(conf->i.status_win);
+ getch();
+}