Class: Rutt::Screen::Content

Inherits:
Base
  • Object
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
  @menu = "i:back b:open in browser"

  # Get the content
  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_contentObject



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
#        @content = `elinks -dump -dump-charset ascii -force-html #{@item['url']}`

  @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

#loopObject



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

#windowObject



43
44
45
46
47
# File 'lib/rutt/screen/content.rb', line 43

def window
  @stdscr.clear
  display_menu
  display_content
end