Class: CursesController

Inherits:
Object
  • Object
show all
Includes:
EntriesController, EntryController, FeedsController
Defined in:
lib/curses_controller.rb

Constant Summary collapse

PREAMBLE =
<<END
FastReader Console Feed Reader Command Reference

END
<<END

                                      by Daniel Choi, June 2008
                                      Cambridge, Massachusetts, USA
                                      [email protected]

END
FEEDS_MENU_COMMANDS =
<<-END
Feed Menu Navigation

The standard Vi bindings h, j, k, l move left, down, up, and right. You can
also use the arrow keys. Right in this case drills down the hierachy
(goes from the feed list to the entry list for a feed to an entry), while
left goes back up the hierarchy.

You can prefix a up or down movement command with a number to go that many
steps in that direction.

CTRL-f, PAGE DOWN KEY     Page down
CTRL-b, PAGE UP KEY       Page up
H                         Move to top of screen
M                         Move to top middle of screen 
L                         Move to bottom of screen
G                         Move to last item
1G                        Move to first item
SPACE, l, RIGHT ARROW, RETURN    Select a feed and display its entries

You can also type the feed's number and press RETURN or RIGHT ARROW to select
it.

Actions

q       Quit the program
u       Updates the feed; won't update if last update was within the last hour
U       Forces an update of the feed
CTRL-u  Updates all feeds
      * It's better to update the feeds from the command line because the
      feedback if easier to follow. Use the command 'fastreader update'.
d       Deletes the feed. This will also delete any flagged items from this feed.
a       Adds a feed; enter the url of the webpage with a feed autodiscovery link
      or the URL of the feed itself
/       Start a global search; asks for a search string and will find all entry
      items in the database that match

END
ENTRIES_MENU_COMMANDS =
<<-END
Feed Items Navigation

The standard Vi bindings h, j, k, l move left, down, up, and right. You can
also use the arrow keys. Right in this case drills down the hierachy
(goes from the feed list to the item list for a feed to an item), while
left goes back up the hierarchy.

You can prefix a up or down movement command with a number to go that many
steps in that direction.

CTRL-f, PAGE DOWN KEY     Page down
CTRL-b, PAGE UP KEY       Page up
H                         Move to top of screen
M                         Move to top middle of screen 
L                         Move to bottom of screen
G                         Move to last item
1G                        Move to first item
SPACE, l, RIGHT ARROW, RETURN    Select an item and display its content

Actions

q     Quit the program
/     Start a local search of the item titles. This lets you jump to a
    particular item quickly. 
s, *  Flag an item. Flagged items appears in a virtual feed called
    "Flagged Entries."
A     Flag all items in the list
Z     Unflag all items in the list
D     Delete all the items from the cursor position downward. Flagged items will
    be preserved.
u     Updates the feed; won't update with last update was within the last hour
U     Forces an update of the feed
END
ENTRY_PAGE_COMMANDS =
<<-END
Feed Item Content Navigation

j, DOWN ARROW, CTRL-f, PAGE DOWN KEY   Page down (if there is more than one page)
k, UP ARROW, CTRL-b, PAGE UP KEY       Page up 
h, LEFT ARROW                          Go back to entries list
l, RIGHT ARROW, RETURN                 Go to the web page linked to this entry. 

By default, the command to open the web browser is "open {url}." This works out
of the box on Mac OS X. You can change this command by setting your shell's
FASTREADER_WEB environmental variable. Currently, in-terminal text browsers like
elinks do not work with Fastreader.  Hopefully this will change.


>, .  Go to next entry in the list
<, ,  Go to previous entry in the list

Actions

q     Quit the program
s, *  Flag an entry. Flagged entries appears in a virtual feed called
    "Flagged Entries."
\\     Show raw entry content markup

END

Instance Method Summary collapse

Methods included from EntryController

#parse_entry_page_command, #set_content_area, #show_entry

Constructor Details

#initialize(formatter) ⇒ CursesController

Returns a new instance of CursesController.



143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/curses_controller.rb', line 143

def initialize(formatter)
  # Formatter is the Display class. Should change the variable names to match the class
  # names or vice versa.
  @formatter = formatter
  @scr = init_screen
  noecho
  cbreak
  Color.init
  curs_set(0)
  @scr.keypad = true
  log "Screen width: #{@scr.maxx} | Screen height: #{@scr.maxy}."
  log "Command window initilized."
end

Instance Method Details

#control_key(character) ⇒ Object



170
171
172
# File 'lib/curses_controller.rb', line 170

def control_key(character)
  character[0] - 64
end

#key_buffer(initial_char) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/curses_controller.rb', line 157

def key_buffer(initial_char)
  c = initial_char
  buffer = []
  printable = (33..126).to_a
  while printable.include?(c) && c.chr =~ /\d/
    LOGGER.debug("detecting a multiplier: #{c.chr}")
    # TODO This code doesn't work right
    buffer << c.chr.to_i
    c = @scr.getch
  end
  return c, buffer
end

#log(statement) ⇒ Object



10
11
12
# File 'lib/curses_controller.rb', line 10

def log(statement)
  LOGGER.debug(statement)
end

#show_help(text) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/curses_controller.rb', line 14

def show_help(text)
  @command_window.escape_help_prompt
  @help_window = Curses::Window.new(@scr.maxy - 4, @scr.maxx, 0, 0) 
  @text_area = Curses::Window.new(@scr.maxy - 4, @scr.maxx - 4, 2, 5)  
  @help_window.clear
  @text_area.addstr(PREAMBLE)
  @text_area.addstr(text)
  @text_area.addstr(FOOTER)
  @help_window.refresh
  @text_area.refresh
  @scr.getch
  @text_area.close
  @help_window.close
end