/
curse.py
68 lines (62 loc) · 1.5 KB
/
curse.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import curses
import praw
#Global Vars probably bad design
first = 2
between = 2
limit = 10
width = 80
pad = 4
r = praw.Reddit(user_agent='redditty')
submissions_gen = r.get_subreddit('games').get_top(limit=limit)
begin_y=0;begin_x=0
height=24;width=88
stdscr = curses.initscr()
mainscr = curses.newwin(height,width,begin_y,begin_x)
begin_y=24;begin_x=0
height=2;width=88
smallscr = curses.newwin(height,width,begin_y,begin_x)
subs = []
def main():
setup()
populate_screen()
loc = first
change_highlight(loc)
while(True):
c = stdscr.getch()
if c == ord('j') and loc <= limit*between -2:
prev = loc
loc=loc+between
change_highlight(loc, prev)
if c == ord('k') and loc > first:
prev = loc
loc=loc-between
change_highlight(loc, prev)
#curses.endwin()
def setup():
curses.cbreak()
curses.start_color()
curses.noecho()
curses.curs_set(0)
stdscr.keypad(1)
#Pass submissions in?
def populate_screen():
i=first
for submission in submissions_gen:
title = submission.title
subs.append(submission)
title = title[:width]
mainscr.addstr(i,pad,title)
i= i+between
stdscr.refresh()
smallscr.addstr(0,0,'hello')
smallscr.refresh()
#Pass subs?
def change_highlight(location, prev=-1):
if prev != -1:
title = subs[prev/2-1].title[:width]
stdscr.addstr(prev, pad, title)
title = subs[location/2 -1].title[:width]
mainscr.addstr(location, pad, title, curses.A_UNDERLINE)
mainscr.refresh()
curses.flash()
main()