Few minor formatting and UI changes

This commit is contained in:
comfortablejohn 2013-07-18 21:47:11 +08:00
parent 1e0fa96778
commit d97da2d288
3 changed files with 36 additions and 8 deletions

3
.gitignore vendored
View File

@ -15,3 +15,6 @@
*.exe *.exe
*.out *.out
*.app *.app
# Build Directory
build/

2
build.sh Executable file → Normal file
View File

@ -1 +1 @@
gcc -g -o cReddit `curl-config --cflags` main.c reddit.c jsmn.c -lncurses `curl-config --libs` gcc -g -o ./build/cReddit `curl-config --cflags` main.c reddit.c jsmn.c -lncurses `curl-config --libs`

39
main.c
View File

@ -14,7 +14,7 @@ void buildScreen(char **text, int selected, int size)
{ {
clear(); clear();
start_color(); start_color();
init_pair(1,COLOR_RED,COLOR_YELLOW); init_pair(1,COLOR_CYAN,COLOR_MAGENTA);
int i = 0; int i = 0;
for(i = 0; i != size; ++i) for(i = 0; i != size; ++i)
{ {
@ -26,6 +26,24 @@ void buildScreen(char **text, int selected, int size)
refresh(); refresh();
} }
/*
Prints horizontal line of dashes to screen
*/
void printHLine(int width) {
int i;
for (i = 0; i < width; i++) {
printw("-");
}
}
/*
Print comments separated by hline equal to width of term
*/
void printComment(char *text) {
printHLine(COLS);
printw("%s\n",text);
}
void showSubreddit(char *subreddit) void showSubreddit(char *subreddit)
{ {
struct post threads[25];//Our array with reddit threads struct post threads[25];//Our array with reddit threads
@ -68,17 +86,17 @@ void showSubreddit(char *subreddit)
break;//YEA FUCK YOU WHILE break;//YEA FUCK YOU WHILE
switch(c) switch(c)
{ {
case KEY_UP: case 'k': case KEY_UP:
if(selected != 0) if(selected != 0)
selected--; selected--;
break; break;
case KEY_DOWN: case 'j': case KEY_DOWN:
if(selected != 24) if(selected != 24)
selected++; selected++;
break; break;
case '\n': case '\n': // Display selected thread
refresh(); refresh();
int *commentCount; int *commentCount;
commentCount = malloc(sizeof(int)); commentCount = malloc(sizeof(int));
@ -89,6 +107,11 @@ void showSubreddit(char *subreddit)
} }
// Basically a copy of the code above // Basically a copy of the code above
int u; int u;
clear();
start_color();
init_pair(1,COLOR_MAGENTA,COLOR_CYAN);
char *ctext[cdisplayCount]; //Text buffer for each line char *ctext[cdisplayCount]; //Text buffer for each line
for(u = 0; u != cdisplayCount; ++u) for(u = 0; u != cdisplayCount; ++u)
{ {
@ -108,10 +131,12 @@ void showSubreddit(char *subreddit)
strcat(cbuffer,cList[u].text); strcat(cbuffer,cList[u].text);
ctext[u] = (char*)malloc(strlen(cbuffer)); //Now lets make a small buffer that fits exacly! ctext[u] = (char*)malloc(strlen(cbuffer)); //Now lets make a small buffer that fits exacly!
strcpy(ctext[u],cbuffer); //And copy our data into it! strcpy(ctext[u],cbuffer); //And copy our data into it!
printw("%s\n",cbuffer); printComment(cbuffer);
refresh(); attroff(COLOR_PAIR(1));
} }
wgetch(stdscr); refresh();
wgetch(stdscr);
} }
buildScreen(text,selected,displayCount); //Print the updates!! buildScreen(text,selected,displayCount); //Print the updates!!
} }