make: taskasaur
taskasaur:
- $(CC) -lncurses taskasaur.c -o taskasaur
+ $(CC) -lncurses -lmenu taskasaur.c -o taskasaur
+
+menutest:
+ $(CC) -lncurses -lmenu menutest.c -o menutest
clean:
- rm taskasaur
+ rm taskasaur menutest
--- /dev/null
+#include <stdio.h>
+#include <stdlib.h>
+#include <ncurses.h>
+#include <menu.h>
+
+WINDOW* create_list_win(int height, int width, int y, int x);
+
+int
+main(int argc, char** argv)
+{
+ int height, width;
+ int ch;
+
+ WINDOW* todo_win;
+ char* todos[] = {"eat bread", "eat milk", "eat cheese"};
+ int todo_length;
+ ITEM** todo_items;
+ MENU* todo_menu;
+ ITEM* cur_item;
+
+ // start ncurses
+ initscr();
+ cbreak();
+ noecho();
+ curs_set(0);
+ start_color();
+
+ getmaxyx(stdscr, height, width);
+ refresh();
+
+ /* init todo menu stuff */
+
+ todo_win = create_list_win(20, 40, 5, 5);
+ todo_length = sizeof(todos)/sizeof(todos[0]);
+
+ todo_items = malloc((todo_length+1)*sizeof(ITEM*));
+ for (int i = 0; i < todo_length; i++) {
+ todo_items[i] = new_item(todos[i], "");
+ }
+ todo_items[todo_length] = NULL; // last item needs to be a null pointer for some reason?
+
+ todo_menu = new_menu(todo_items);
+ post_menu(todo_menu);
+
+ /* todo_menu = new_menu(); */
+
+ /* for (int i = 0; i < todo_length; i++) { */
+ /* mvwprintw(todo_win, i, 0, todos[i]); */
+ /* } */
+ wrefresh(todo_win);
+
+ while ((ch = getch()) != 113) { // while not q
+
+ // ofc the first thing we need is vim keys
+ switch (ch) {
+ case 106: // j
+ menu_driver(todo_menu, REQ_DOWN_ITEM);
+ break;
+ case 107: // k
+ menu_driver(todo_menu, REQ_UP_ITEM);
+ break;
+ }
+
+ refresh();
+ /* clear(); */
+ }
+
+ endwin();
+
+ return 0;
+}
+
+WINDOW*
+create_list_win(int height, int width, int y, int x)
+{
+ WINDOW* new_win = newwin(height, width, y, x);
+ wrefresh(new_win);
+ return new_win;
+}
#include <stdio.h>
-#include <ncurses.h>
-#include <signal.h>
#include <stdlib.h>
+#include <signal.h>
#include <unistd.h>
+#include <ncurses.h>
+#include <menu.h>
void winch_handler(int sig);
WINDOW* create_list_win(int height, int width, int y, int x);
+void draw_todo(WINDOW* todo_win, char** todo_list, int todo_length);
+
#include "config.h"
int
refresh();
todo_win = create_list_win(20, 40, 5, 5);
- for (int i = 0; i < todo_length; i++) {
- mvwprintw(todo_win, i+1, 2, todos[i]);
- }
- wrefresh(todo_win);
+ draw_todo(todo_win, todos, todo_length);
move(y,x);
while ((ch = getch()) != 113) { // while not q
while ((nread = getline(&lineptr, &len, file)) != -1) {
out_len++;
out_arr = realloc(out_arr, (sizeof(char*))*out_len); // bad to keep resizing?
- // remove new line character (maybe just write own new line func later)
- /* lineptr = realloc(*lineptr, len-2); */
- /* *(lineptr+len-1) = '\0'; */
- /* printf(lineptr); */
- /* lineptr = realloc(lineptr, len-1); //maybe watch out for empty lines */
- /* *(lineptr+len-3) = '\0'; */
-
out_arr[out_len-1] = lineptr;
lineptr = NULL;
create_list_win(int height, int width, int y, int x)
{
WINDOW* new_win = newwin(height, width, y, x);
- box(new_win, 0, 0);
wrefresh(new_win);
return new_win;
}
+
+void
+draw_todo(WINDOW* todo_win, char** todo_list, int todo_length) {
+ for (int i = 0; i < todo_length; i++) {
+ mvwprintw(todo_win, i+1, 2, todo_list[i]);
+ }
+ box(todo_win, 0, 0);
+ wrefresh(todo_win);
+}