Class: Rutt::Screen::Content
- Inherits:
-
Base
- Object
- Base
- Rutt::Screen::Content
show all
- Defined in:
- lib/rutt/screen/content.rb
Instance Method Summary
collapse
Methods inherited from Base
#decr_page, #display_menu, #incr_page, #move_pointer
Constructor Details
#initialize(stdscr, item) ⇒ Content
Returns a new instance of Content.
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/rutt/screen/content.rb', line 4
def initialize(stdscr, item)
super(stdscr)
@item = item
= "i:back b:open in browser"
source = open(@item['url']).read
content = Nokogiri::HTML(::Readability::Document.new(source).content).text
@content = content.split("\n").map do |s|
s.gsub(/.{0,74}(?:\s|\Z)/){($& + 5.chr).gsub(/\n\005/,"\n")}.gsub(/((\n|^)[>|\s]*[>|].*?)\005/, "\\1").gsub(/\005/,"\n").split("\n") << "\n"
end.flatten
@pages = @content / @max_y
end
|
Instance Method Details
#display_content ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/rutt/screen/content.rb', line 21
def display_content
@cur_y = @min_y
@stdscr.move(@cur_y, 0)
@stdscr.addstr(" #{@item['title']}\n")
@cur_y += 1
@stdscr.move(@cur_y, 0)
@stdscr.addstr(" #{@item['url']}\n")
@cur_y += 1
@pages[@cur_page].each do |line|
@stdscr.move(@cur_y, 0)
@stdscr.addstr(" #{line}\n")
@cur_y += 1
end
@cur_y = @min_y
@stdscr.refresh
end
|
#loop ⇒ Object
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
|
# File 'lib/rutt/screen/content.rb', line 49
def loop
@cur_line = 0
window
while true do
c = @stdscr.getch
if c > 0 && c < 255
case c.chr
when /[iq]/i
DB::Item::mark_as_read(@item)
break
when /b/i
Launchy.open(@item['url'])
end
else
case c
when Ncurses::KEY_UP
decr_page
window
when Ncurses::KEY_DOWN
incr_page
window
end
end
end
end
|
#window ⇒ Object
43
44
45
46
47
|
# File 'lib/rutt/screen/content.rb', line 43
def window
@stdscr.clear
display_content
end
|