pinosaur
/
taskasaur.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
menu test
[taskasaur.git]
/
taskasaur.c
diff --git
a/taskasaur.c
b/taskasaur.c
index
a4c0f4e
..
39eaca6
100644
(file)
--- a/
taskasaur.c
+++ b/
taskasaur.c
@@
-1,15
+1,18
@@
#include <stdio.h>
#include <stdio.h>
-#include <ncurses.h>
-#include <signal.h>
#include <stdlib.h>
#include <stdlib.h>
+#include <signal.h>
#include <unistd.h>
#include <unistd.h>
+#include <ncurses.h>
+#include <menu.h>
void winch_handler(int sig);
void winch_handler(int sig);
-char** read_todo(FILE* file);
+char** read_todo(FILE* file
, int* length
);
WINDOW* create_list_win(int height, int width, int y, int x);
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
#include "config.h"
int
@@
-17,6
+20,8
@@
main(int argc, char** argv)
{
int flag;
FILE* board_file;
{
int flag;
FILE* board_file;
+ char** todos;
+ int todo_length;
int height, width;
int x, y;
int ch;
int height, width;
int x, y;
int ch;
@@
-36,8
+41,7
@@
main(int argc, char** argv)
return 1;
}
return 1;
}
- char** todos = read_todo(board_file);
- printf(todos[0]);
+ todos = read_todo(board_file, &todo_length);
fclose(board_file);
break;
fclose(board_file);
break;
@@
-51,7
+55,14
@@
main(int argc, char** argv)
return 1;
}
// create a file here
return 1;
}
// create a file here
+ board_file = fopen(optarg, "w");
+ // write init stuff here
+ fclose(board_file);
printf("Successfully created %s\n", optarg);
printf("Successfully created %s\n", optarg);
+
+ todos = malloc(0);
+ todo_length = 0;
+
break;
case -1:
break;
case -1:
@@
-61,14
+72,12
@@
main(int argc, char** argv)
}
}
-
- return 0;
-
// start ncurses
initscr();
cbreak();
/* raw(); */
noecho();
// start ncurses
initscr();
cbreak();
/* raw(); */
noecho();
+ curs_set(0);
start_color();
init_pair(1, COLOR_CYAN, COLOR_BLACK);
start_color();
init_pair(1, COLOR_CYAN, COLOR_BLACK);
@@
-78,7
+87,8
@@
main(int argc, char** argv)
x = y = 0;
refresh();
x = y = 0;
refresh();
- todo_win = create_list_win(20, 20, 5, 5);
+ todo_win = create_list_win(20, 40, 5, 5);
+ draw_todo(todo_win, todos, todo_length);
move(y,x);
while ((ch = getch()) != 113) { // while not q
move(y,x);
while ((ch = getch()) != 113) { // while not q
@@
-105,6
+115,10
@@
main(int argc, char** argv)
}
endwin();
}
endwin();
+
+ /* Free mem */
+ free(todos); // prob need to free each string in list too
+
return 0;
}
return 0;
}
@@
-115,9
+129,8
@@
winch_handler(int sig)
refresh();
}
refresh();
}
-
char**
char**
-read_todo(FILE* file)
+read_todo(FILE* file
, int* length
)
{ // apparently getline isn't rly that portable, so consider other options
char** out_arr;
int out_len;
{ // apparently getline isn't rly that portable, so consider other options
char** out_arr;
int out_len;
@@
-133,13
+146,13
@@
read_todo(FILE* file)
while ((nread = getline(&lineptr, &len, file)) != -1) {
out_len++;
out_arr = realloc(out_arr, (sizeof(char*))*out_len); // bad to keep resizing?
while ((nread = getline(&lineptr, &len, file)) != -1) {
out_len++;
out_arr = realloc(out_arr, (sizeof(char*))*out_len); // bad to keep resizing?
- printf("Pointer set to: %p\n", lineptr);
out_arr[out_len-1] = lineptr;
lineptr = NULL;
len = 0;
}
out_arr[out_len-1] = lineptr;
lineptr = NULL;
len = 0;
}
-
+
+ *length = out_len;
return out_arr;
}
return out_arr;
}
@@
-147,7
+160,15
@@
WINDOW*
create_list_win(int height, int width, int y, int x)
{
WINDOW* new_win = newwin(height, width, y, x);
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;
}
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);
+}