diff options
author | Malfurious <m@lfurio.us> | 2023-07-02 04:22:41 -0400 |
---|---|---|
committer | Malfurious <m@lfurio.us> | 2023-07-02 04:22:41 -0400 |
commit | 7e89874f23e0423a4c9476cba8b566809685cfb9 (patch) | |
tree | 5f23041b4499640aab168a2f59b9489bf3546622 | |
parent | 2c714c2d0066eafa066b96e5e3e48fbee27c4e1a (diff) | |
download | misplays-7e89874f23e0423a4c9476cba8b566809685cfb9.tar.gz misplays-7e89874f23e0423a4c9476cba8b566809685cfb9.zip |
Add convenience ncurses functions
Signed-off-by: Malfurious <m@lfurio.us>
-rw-r--r-- | curshelpers.c | 47 | ||||
-rw-r--r-- | curshelpers.h | 12 |
2 files changed, 59 insertions, 0 deletions
diff --git a/curshelpers.c b/curshelpers.c new file mode 100644 index 0000000..7b2f1d1 --- /dev/null +++ b/curshelpers.c @@ -0,0 +1,47 @@ +#include <locale.h> +#include <stdarg.h> + +#include "curshelpers.h" + +void cursinit(void) { + setlocale(LC_ALL, ""); + initscr(); + cbreak(); + noecho(); + keypad(stdscr, TRUE); + curs_set(FALSE); + timeout(25); + refresh(); +} + +void cursupdate(void) { + update_panels(); + doupdate(); +} + +PANEL *newpan(int h, int w, int y, int x) { + WINDOW *win = newwin(h, w, y, x); + scrollok(win, TRUE); + return new_panel(win); +} + +void delpan(PANEL *pan) { + WINDOW *win = panel_window(pan); + del_panel(pan); + delwin(win); +} + +void reset_panel(PANEL *pan, int h, int w, int y, int x) { + WINDOW *win = panel_window(pan); + wresize(win, h, w); + replace_panel(pan, win); + move_panel(pan, y, x); +} + +int pprintw(PANEL *pan, const char *fmt, ...) { + va_list args; + va_start(args, fmt); + int res = vw_printw(panel_window(pan), fmt, args); + va_end(args); + return res; +} diff --git a/curshelpers.h b/curshelpers.h new file mode 100644 index 0000000..d8bda0d --- /dev/null +++ b/curshelpers.h @@ -0,0 +1,12 @@ +#pragma once + +#include <ncurses.h> +#include <panel.h> + +extern void cursinit(void); +extern void cursupdate(void); + +extern PANEL *newpan(int h, int w, int y, int x); +extern void delpan(PANEL *pan); +extern void reset_panel(PANEL *pan, int h, int w, int y, int x); +extern int pprintw(PANEL *pan, const char *fmt, ...); |