commit bac8f5e5647476c3be27d07ae722c30f174337df Author: nova Date: Thu Feb 20 23:05:23 2025 +0100 initial commit diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..656b621 --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +all: + gcc ./main.c -std=c99 -o th -lncurses -ltinfo -Wall + +d: + gcc -g -std=c99 ./main.c -o th -lncurses -ltinfo -Wall diff --git a/main.c b/main.c new file mode 100644 index 0000000..8512d6b --- /dev/null +++ b/main.c @@ -0,0 +1,25 @@ +#include +#include "window.h" + +unsigned int terminal_height; +unsigned int terminal_width; + +int main() { + initscr(); //start ncurses + + unsigned int ch; + getmaxyx(stdscr, terminal_height, terminal_width); + WINDOW *win_m = newwin(terminal_height, terminal_width/3, 0, 0); + WINDOW *win_l = newwin(terminal_height, terminal_width/3, terminal_height, (terminal_width/3)); + WINDOW *win_r = newwin(terminal_height, terminal_width/3, terminal_height, ((terminal_width/3)*2)); + while((ch = wgetch(win_m)) != 'q'){ + getmaxyx(stdscr, terminal_height, terminal_width); + window_left(win_l,0,0); + window_main(win_m,0,(terminal_width/3)); + window_right(win_r,0,((terminal_width/3)*2)); + } + + + endwin(); + return 0; +} diff --git a/window.c b/window.c new file mode 100644 index 0000000..8f86345 --- /dev/null +++ b/window.c @@ -0,0 +1,89 @@ +#include "curses.h" +#include + +extern unsigned int terminal_height; +extern unsigned int terminal_width; + +void window_main(WINDOW *win, unsigned int start_y, unsigned int start_x){ + + unsigned int local_width; + unsigned int local_height; + DIR *path = opendir("."); + + //{{{ size & positioning + wresize(win, terminal_height, terminal_width/3); + getmaxyx(win, local_height, local_width); + mvwin(win, start_y, start_x); + wclear(win); + //}}} + + wmove(win, 0, 0); + if (path == NULL) { + wprintw(win, "Unable to read directory"); + } else { + int index = 0; + struct dirent *entry; + while ( entry=readdir(path) ) { + if (entry->d_name[0] != '.') { + wprintw(win, "%s", entry->d_name); + wmove(win, index, 1); + index++; + } + } + } + closedir(path); + + box(win,0,0); + wrefresh(win); +} +void window_left(WINDOW *win, unsigned int start_y, unsigned int start_x){ + + unsigned int local_width; + unsigned int local_height; + DIR *path = opendir(".."); + + //{{{ size & positioning + wresize(win, terminal_height, terminal_width/3); + getmaxyx(win, local_height, local_width); + mvwin(win, start_y, start_x); + wclear(win); + //}}} + + wmove(win, 0, 0); + if (path == NULL) { + wprintw(win, "Unable to read directory"); + } else { + int index = 0; + struct dirent *entry; + while ( entry=readdir(path) ) { + if (entry->d_name[0] != '.') { + wprintw(win, "%s", entry->d_name); + wmove(win, index, 1); + index++; + } + } + } + closedir(path); + + + box(win,0,0); + wrefresh(win); +} +void window_right(WINDOW *win, unsigned int start_y, unsigned int start_x){ + + unsigned int local_width; + unsigned int local_height; + + //{{{ size & positioning + wresize(win, terminal_height, terminal_width/3); + getmaxyx(win, local_height, local_width); + mvwin(win, start_y, start_x); + wclear(win); + //}}} + + wmove(win, local_height/2, local_width/2); + wprintw(win, "%d,%d", local_height, local_width); + + box(win,0,0); + wrefresh(win); +} diff --git a/window.h b/window.h new file mode 100644 index 0000000..adc865d --- /dev/null +++ b/window.h @@ -0,0 +1,6 @@ +#include "curses.h" +#include "window.c" + +void window_left(WINDOW *win, unsigned int start_y, unsigned int start_x); +void window_main(WINDOW *win, unsigned int start_y, unsigned int start_x); +void window_right(WINDOW *win, unsigned int start_y, unsigned int start_x);