Class: Rutt::Screen::Item
- Inherits:
-
Base
- Object
- Base
- Rutt::Screen::Item
show all
- Defined in:
- lib/rutt/screen/item.rb
Instance Method Summary
collapse
Methods inherited from Base
#decr_page, #display_menu, #incr_page, #move_pointer
Constructor Details
#initialize(stdscr, feed) ⇒ Item
Returns a new instance of Item.
4
5
6
7
8
9
10
11
|
# File 'lib/rutt/screen/item.rb', line 4
def initialize(stdscr, feed)
super(stdscr)
@feed = feed
@menu = " i:quit r:refresh m:mark as read u:mark as unread a:mark all as read b:open in browser"
get_items
end
|
Instance Method Details
#display_items ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/rutt/screen/item.rb', line 18
def display_items
@cur_y = @min_y
@pages[@cur_page].each do |item|
item_status = case item['read'].to_i
when 0 then 'N'
when 1 then ' '
when 2 then 'I'
else ' '
end
@stdscr.addstr(" #{item_status}\t#{Time.at(item['published_at']).strftime("%b %d, %Y %R:%M")}\t#{item['title']}\n")
@cur_y += 1
end
@cur_y = @min_y
@stdscr.refresh
end
|
#get_items ⇒ Object
13
14
15
16
|
# File 'lib/rutt/screen/item.rb', line 13
def get_items
@items = DB::Item::all(@feed)
@pages = @items / @max_y
end
|
#loop ⇒ Object
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
# File 'lib/rutt/screen/item.rb', line 44
def loop
window
while true do
c = @stdscr.getch
if c > 0 && c < 255
case c.chr
when /[iq]/i
break
when /s/i
cur_y = @cur_y - 1
$instapaper.request('/api/1/bookmarks/add', {
'url' => @pages[@cur_page][cur_y]['url'],
'title' => @pages[@cur_page][cur_y]['title'],
})
DB::Item::sent_to_instapaper(@pages[@cur_page][cur_y])
get_items
window
move_pointer(cur_y + 1, move_to=true)
when /a/i
DB::Feed::mark_as_read(@feed)
get_items
window
move_pointer(@cur_y, move_to=true)
when /p/i
decr_page
window
when /n/i
incr_page
window
when /b/i
cur_y = @cur_y - 1
DB::Item::mark_as_read(@items[cur_y])
Launchy.open(@pages[@cur_page][cur_y]['url'])
window
move_pointer(@cur_y, move_to=true)
when /m/i
cur_y = @cur_y - 1
DB::Item::mark_as_read(@pages[@cur_page][cur_y])
get_items
window
move_pointer(cur_y + 1, move_to=true)
when /u/i
cur_y = @cur_y - 1
DB::Item::mark_as_unread(@pages[@cur_page][cur_y])
get_items
window
move_pointer(cur_y + 1, move_to=true)
when /r/i
DB::Feed::refresh_for(@feed)
window
when / /
cur_y = @cur_y - 1
content_screen = Content.new(@stdscr, @pages[@cur_page][cur_y])
content_screen.loop
get_items
window
move_pointer(cur_y + 1, move_to=true)
end
else
case c
when Ncurses::KEY_UP
move_pointer(-1)
when Ncurses::KEY_DOWN
move_pointer(1)
end
end
end
end
|
#window ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/rutt/screen/item.rb', line 36
def window
@stdscr.clear
display_items
move_pointer(0)
end
|