Skip to content

Commit

Permalink
Few minor formatting and UI changes
Browse files Browse the repository at this point in the history
  • Loading branch information
comfortablejohn committed Jul 18, 2013
1 parent 1e0fa96 commit d97da2d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -15,3 +15,6 @@
*.exe
*.out
*.app

# Build Directory
build/
2 changes: 1 addition & 1 deletion build.sh 100755 → 100644
@@ -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 changes: 32 additions & 7 deletions main.c
Expand Up @@ -14,7 +14,7 @@ void buildScreen(char **text, int selected, int size)
{
clear();
start_color();
init_pair(1,COLOR_RED,COLOR_YELLOW);
init_pair(1,COLOR_CYAN,COLOR_MAGENTA);
int i = 0;
for(i = 0; i != size; ++i)
{
Expand All @@ -26,6 +26,24 @@ void buildScreen(char **text, int selected, int size)
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)
{
struct post threads[25];//Our array with reddit threads
Expand Down Expand Up @@ -68,17 +86,17 @@ void showSubreddit(char *subreddit)
break;//YEA FUCK YOU WHILE
switch(c)
{
case KEY_UP:
case 'k': case KEY_UP:
if(selected != 0)
selected--;
break;

case KEY_DOWN:
case 'j': case KEY_DOWN:
if(selected != 24)
selected++;
break;

case '\n':
case '\n': // Display selected thread
refresh();
int *commentCount;
commentCount = malloc(sizeof(int));
Expand All @@ -89,6 +107,11 @@ void showSubreddit(char *subreddit)
}
// Basically a copy of the code above
int u;

clear();
start_color();
init_pair(1,COLOR_MAGENTA,COLOR_CYAN);

char *ctext[cdisplayCount]; //Text buffer for each line
for(u = 0; u != cdisplayCount; ++u)
{
Expand All @@ -108,10 +131,12 @@ void showSubreddit(char *subreddit)
strcat(cbuffer,cList[u].text);
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!
printw("%s\n",cbuffer);
refresh();
printComment(cbuffer);
attroff(COLOR_PAIR(1));
}
wgetch(stdscr);
refresh();

wgetch(stdscr);
}
buildScreen(text,selected,displayCount); //Print the updates!!
}
Expand Down

0 comments on commit d97da2d

Please sign in to comment.