commit 31d59fd0fcaa2a697742ae82f6e7e02e303b6a8c Author: jazz (gitea) Date: Wed Feb 4 19:59:37 2026 -0600 initial diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7068452 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.ccls-cache/ +*.o +nctest diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d5793dc --- /dev/null +++ b/Makefile @@ -0,0 +1,14 @@ +include config.mk + +OBJS = main.o window.o + +all: $(TARGET) + +$(TARGET): $(OBJS) + $(CC) $(CFLAGS) -o $(TARGET) $(OBJS) + +%.o: %.c + $(CC) $(CFLAGS) -c $< + +clean: + rm -f *.o $(TARGET) diff --git a/config.mk b/config.mk new file mode 100644 index 0000000..4b6230c --- /dev/null +++ b/config.mk @@ -0,0 +1,3 @@ +CC = gcc +CFLAGS = -Wall -Wextra -std=c11 -lncurses +TARGET = nctest diff --git a/hacks.h b/hacks.h new file mode 100644 index 0000000..ded4168 --- /dev/null +++ b/hacks.h @@ -0,0 +1,22 @@ +#ifndef HACKS_H +#define HACKS_H + +/* + * Ugly hack to print a message in the center column by taking half its length + * and subtracting that from the desired X position. + */ +#define midprint(y, x, len, message) mvwprintw(stdscr, y, x - (len * 0.5), message) + +/* + * @brief string pointer with manual length stuck to it + */ +typedef struct { + char *s; + int l; +} lstring_t; + +struct xy { + int x, y; +}; + +#endif diff --git a/main.c b/main.c new file mode 100644 index 0000000..c3b237b --- /dev/null +++ b/main.c @@ -0,0 +1,12 @@ +#include +#include + +#include "hacks.h" +#include "window.h" + +int +main(void) +{ + return homewin(); +} + diff --git a/window.c b/window.c new file mode 100644 index 0000000..877041d --- /dev/null +++ b/window.c @@ -0,0 +1,108 @@ +#include +#include + +#include "hacks.h" + +/* + * Execute actual code and draw on the window. + * Should be called by a function that creates a window. + * Returns 0 if successful. + */ +int +dostuff(void) +{ + /* + * Using unsafe strings right now, but should change this later to use + * malloc(), strcpy, the like. + */ + lstring_t msg; + + struct xy max; + struct xy center; + + getmaxyx(stdscr, max.y, max.x); + + center.y = max.y * 0.5; + center.x = max.x * 0.5; + + msg.s = "Hello, World!"; + msg.l = 14; + //mvwprintw(stdscr, center.y, center.x - (msg.l * 0.5), msg.s); // gross + midprint(center.y, center.x, msg.l, msg.s); + refresh(); + + sleep(3); + + msg.s = "You can leave in 3..."; + msg.l = 21; + midprint(center.y, center.x, msg.l, msg.s); + refresh(); + + sleep(1); + + msg.s = "You can leave in 2..."; + msg.l = 21; + midprint(center.y, center.x, msg.l, msg.s); + refresh(); + + sleep(1); + + msg.s = "You can leave in 1..."; + msg.l = 21; + midprint(center.y, center.x, msg.l, msg.s); + refresh(); + + sleep(1); + + msg.s = "Press Any Key to Leave"; + msg.l = 22; + midprint(center.y, center.x, msg.l, msg.s); + refresh(); + + getch(); + + return 0; +} + +/* + * Full lifetime of main window happens here. + * Returns 0 if successful after window closes. + */ +int +homewin(void) +{ + int err, ret; + err = ret = 0; + + initscr(); + noecho(); + cbreak(); + keypad(stdscr, TRUE); + curs_set(0); + + if (!has_colors()) { + endwin(); + puts("err: no color"); + return 1; + } + + start_color(); + init_pair(1, COLOR_BLACK, COLOR_MAGENTA); + + attron(COLOR_PAIR(1)); + + /* Window Title */ + mvwprintw(stdscr, 2, 2, "Test Program"); + + err = dostuff(); + + attroff(COLOR_PAIR(1)); + endwin(); + + if (err) { + puts("err in dostuff()"); + ret = 1; + } + + return ret; +} diff --git a/window.h b/window.h new file mode 100644 index 0000000..e75a1b0 --- /dev/null +++ b/window.h @@ -0,0 +1,7 @@ +#ifndef WINDOW_H +#define WINDOW_H + +int dostuff(void); +int homewin(void); + +#endif