Module: EntryController

Included in:
CursesController
Defined in:
lib/entry_controller.rb

Instance Method Summary collapse

Instance Method Details

#parse_entry_page_commandObject



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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/entry_controller.rb', line 29

def parse_entry_page_command
  LOGGER.debug "Waiting for entry page command"
  c = @scr.getch
  LOGGER.debug("Entry Page getch: #{c}")
  c, buffer = key_buffer(c)
  multiplier = buffer.empty? ? 1 : buffer.join.to_i

  case c
  when "?"[0] # help
    @content_area.close
    show_help(CursesController::ENTRY_PAGE_COMMANDS)
    # Any key restores the menu

    @scr.clear
    @scr.refresh
    set_content_area
    @content_area.draw
    return
  when ?\q
    exit
    
  # go back to entries list
  when '-'[0], Key::LEFT, ?h
    @content_area.close
    show_entries
    return :exit

  when ?\/
    # search mode
    # TODO
  when Key::UP, ?k, ?p, control_key('B'), Key::PPAGE
    if @content_area.prev_page == :exit
      # go back to entries list
      @content_area.close
      show_entries
      return :exit
    end
  when Key::DOWN, ?j, ?\s, ?n, control_key('F'), Key::NPAGE
    if @content_area.next_page == :exit
      # go back to entries list
      @content_area.close
      show_entries
      return :exit
    end
  when '<'[0], ','[0] # Previous entry
    if @current_entry_index > 0 
      @current_entry_index -=  1
      @current_entry = @current_entries[@current_entry_index]
      @content_area.close
      set_content_area
    end
  when '>'[0], '.'[0] # Next entry
    if @current_entry_index < @current_entries.size - 1
      @current_entry_index +=  1
      @current_entry = @current_entries[@current_entry_index]
      @content_area.close
      set_content_area
    end

  when Key::RESIZE
    content = @content_area.content
    @content_area.close
    set_content_area
    @content_area.content = content

  when '*'[0], 's'[0] # Flag the entry
    @content_area.toggle_flag

  when '\\'[0]
    unless @raw_content_mode
      # Show raw HTML for entry content
      @content_area.close
      @content_area = EntryWindow.new(@scr, 
                                      @formatter.display_feed(@current_entry), 
                                      @formatter.display_title(@current_entry), 
                                      @formatter.display_raw_entry_content(@current_entry), 
                                      @current_entry, @global_search_string)
      @raw_content_mode = true
    else # go back to normal mode
      @content_area.close
      set_content_area
      @raw_content_mode = false
    end

  when ?l, Key::RIGHT, 10 # Enter key 
    # TODO 
    # open web browser
    command = (ENV['FASTREADER_WEB'] || "open") + " #{@current_entry.url.strip}" 
    `#{command}`
  when 'G'[0] # beginning or of list
    if buffer.last == 1
      @content_area.end
    else
      @content_area.beginning
    end
  else
    # don't do anything
  end
end

#set_content_areaObject



20
21
22
23
24
25
26
# File 'lib/entry_controller.rb', line 20

def set_content_area
  @content_area = EntryWindow.new(@scr, 
                                  @formatter.display_feed(@current_entry), 
                                  @formatter.display_title(@current_entry), 
                                  @formatter.display_entry(@current_entry, false), 
                                  @current_entry, @global_search_string)
end

#show_entryObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/entry_controller.rb', line 3

def show_entry
 begin
   LOGGER.debug("initializing EntryWindow")

   @command_window = CommandWindow.new( @scr ) 

   # The formatter formats a blog entry but does not paginate it


   set_content_area
   @command_window.help_prompt
   begin 
     @content_area.draw
   end while parse_entry_page_command != :exit
 end
end