void showSubreddit(const char *subreddit) { char *line; LinkScreen *screen; RedditListType listType = REDDIT_HOT; // Default RedditListType for screen is 'hot' DEBUG_PRINT(L"Loading Subreddit %s\n", subreddit); screen = linkScreenNew(); linkScreenSetup(screen, subreddit, listType); drawScreen(screen); //And print the screen! int c; while((c = wgetch(stdscr))) { switch(c) { case 'k': case KEY_UP: linkScreenUp(screen); drawScreen(screen); break; case 'j': case KEY_DOWN: linkScreenDown(screen); drawScreen(screen); break; case 'K': linkScreenTextScrollUp(screen); drawScreen(screen); break; case 'J': linkScreenTextScrollDown(screen); drawScreen(screen); break; case 'q': if (screen->linkOpen) { linkScreenCloseLink(screen); drawScreen(screen); } else { goto cleanup; } break; case 'u': redditLinkListFreeLinks(screen->list); redditGetListing(screen->list); screen->offset = 0; screen->selected = 0; drawScreen(screen); break; case 'l': case '\n': case KEY_ENTER: if (screen->helpOpen) linkScreenCloseHelp(screen); else linkScreenToggleLink(screen); drawScreen(screen); break; case 'o': line = alloc_sprintf("xdg-open %s", screen->list->links[screen->selected]->url); system(line); free(line); redditLinkListFree(screen->list); linkScreenFree(screen); screen = linkScreenNew(); linkScreenSetup(screen, subreddit, listType); drawScreen(screen); break; case 'L': redditGetListing(screen->list); drawScreen(screen); break; case 'c': showThread(screen->list->links[screen->selected]); drawScreen(screen); break; case '?': linkScreenToggleHelp(screen); if (screen->helpOpen) linkScreenOpenLink(screen); drawScreen(screen); break; case '1': if (screen->list->type != REDDIT_HOT) { listType = REDDIT_HOT; redditLinkListFree(screen->list); linkScreenFree(screen); screen = linkScreenNew(); linkScreenSetup(screen, subreddit, listType); drawScreen(screen); } break; case '2': if (screen->list->type != REDDIT_NEW) { listType = REDDIT_NEW; redditLinkListFree(screen->list); linkScreenFree(screen); screen = linkScreenNew(); linkScreenSetup(screen, subreddit, listType); drawScreen(screen); } break; case '3': if (screen->list->type != REDDIT_RISING) { listType = REDDIT_RISING; redditLinkListFree(screen->list); linkScreenFree(screen); screen = linkScreenNew(); linkScreenSetup(screen, subreddit, listType); drawScreen(screen); } break; case '4': if (screen->list->type != REDDIT_CONTR) { listType = REDDIT_CONTR; redditLinkListFree(screen->list); linkScreenFree(screen); screen = linkScreenNew(); linkScreenSetup(screen, subreddit, listType); drawScreen(screen); } break; case '5': if (screen->list->type != REDDIT_TOP) { listType = REDDIT_TOP; redditLinkListFree(screen->list); linkScreenFree(screen); screen = linkScreenNew(); linkScreenSetup(screen, subreddit, listType); drawScreen(screen); } break; } } cleanup:; redditLinkListFree(screen->list); linkScreenFree(screen); }
void showSubreddit(const char *subreddit) { LinkScreen *screen; DEBUG_PRINT(L"Loading Subreddit %s\n", subreddit); screen = linkScreenNew(); screen->list = redditLinkListNew(); screen->list->subreddit = redditCopyString(subreddit); screen->list->type = REDDIT_HOT; redditGetListing(screen->list); screen->displayed = LINES - 1; screen->linkOpenSize = (screen->displayed / 5) * 4; screen->offset = 0; screen->selected = 0; /* Assign help-screen text */ screen->helpText = linkScreenHelp; screen->helpLineCount = 19; drawScreen(screen); //And print the screen! int c; while((c = wgetch(stdscr))) { switch(c) { case 'k': case KEY_UP: linkScreenUp(screen); drawScreen(screen); break; case 'j': case KEY_DOWN: linkScreenDown(screen); drawScreen(screen); break; case 'q': if (screen->linkOpen) { linkScreenCloseLink(screen); drawScreen(screen); } else { goto cleanup; } break; case 'u': redditLinkListFreeLinks(screen->list); redditGetListing(screen->list); screen->offset = 0; screen->selected = 0; drawScreen(screen); break; case 'l': case '\n': case KEY_ENTER: if (screen->helpOpen) linkScreenCloseHelp(screen); else linkScreenToggleLink(screen); drawScreen(screen); break; case 'L': redditGetListing(screen->list); drawScreen(screen); break; case 'c': showThread(screen->list->links[screen->selected]); drawScreen(screen); break; case '?': linkScreenToggleHelp(screen); if (screen->helpOpen) linkScreenOpenLink(screen); drawScreen(screen); break; } } cleanup:; redditLinkListFree(screen->list); linkScreenFree(screen); }