Class: CommandWindow
- Inherits:
-
Object
- Object
- CommandWindow
- Defined in:
- lib/command_window.rb
Instance Attribute Summary collapse
-
#command_line ⇒ Object
Returns the value of attribute command_line.
Instance Method Summary collapse
- #add_feed ⇒ Object
- #clear ⇒ Object
- #close ⇒ Object
- #confirm_delete_feed(feed) ⇒ Object
- #draw ⇒ Object
- #escape_help_prompt ⇒ Object
- #feed_update_progress(feed, force = false) ⇒ Object
- #get_search_string ⇒ Object
- #help_prompt ⇒ Object
-
#initialize(scr) ⇒ CommandWindow
constructor
A new instance of CommandWindow.
- #message(string) ⇒ Object
Constructor Details
#initialize(scr) ⇒ CommandWindow
Returns a new instance of CommandWindow.
4 5 6 7 |
# File 'lib/command_window.rb', line 4 def initialize(scr) @scr = scr @window = Curses::Window.new(1, @scr.maxx, @scr.maxy - 1, 0) end |
Instance Attribute Details
#command_line ⇒ Object
Returns the value of attribute command_line.
2 3 4 |
# File 'lib/command_window.rb', line 2 def command_line @command_line end |
Instance Method Details
#add_feed ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/command_window.rb', line 58 def add_feed @command_line = "Add feed (enter a URL or RETURN to cancel: " draw Curses::echo response = @window.getstr LOGGER.debug("Feed to add: #{response}") Curses::noecho response = response.strip if response == '' @command_line = "Canceled." draw return false else textfeeds = FASTREADER_CONTROLLER # Uses a block to update the command line for every output line feed = textfeeds.subscribe(response) do |line_output| @command_line = line_output draw end return feed end end |
#clear ⇒ Object
99 100 101 102 103 104 105 |
# File 'lib/command_window.rb', line 99 def clear if @command_line.nil? || @command_line == '' return help_prompt end @window.clear @window.refresh end |
#close ⇒ Object
107 108 109 |
# File 'lib/command_window.rb', line 107 def close @window.close end |
#confirm_delete_feed(feed) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/command_window.rb', line 49 def confirm_delete_feed(feed) @command_line = "Delete feed: #{feed.title}? (y/n) " draw Curses::echo response = @window.getch Curses::noecho response end |
#draw ⇒ Object
82 83 84 85 86 |
# File 'lib/command_window.rb', line 82 def draw @window.clear @window << @command_line @window.refresh end |
#escape_help_prompt ⇒ Object
93 94 95 96 |
# File 'lib/command_window.rb', line 93 def escape_help_prompt @command_line = "Press any key to exit help" draw end |
#feed_update_progress(feed, force = false) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/command_window.rb', line 19 def feed_update_progress(feed, force = false) # Don't do anything if it's a virtual feed if ! feed.respond_to?(:feed_url) return end if force @command_line = "Force updating feed \"%s\"" % feed.feed_url else @command_line = "Updating feed \"%s\"" % feed.feed_url end draw textfeeds = FASTREADER_CONTROLLER # Uses a block to update the command line for every output line result = textfeeds.update(:feed_id => feed.id, :force => force) do |line_output| @command_line = line_output unless @command_line.strip == '' draw end end result.to_i # nil will be turned to 0 end |
#get_search_string ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/command_window.rb', line 9 def get_search_string @command_line = "Search string: " draw Curses::echo search_string = @window.getstr Curses::noecho search_string end |
#help_prompt ⇒ Object
88 89 90 91 |
# File 'lib/command_window.rb', line 88 def help_prompt @command_line = "Type ? for help" draw end |
#message(string) ⇒ Object
44 45 46 47 |
# File 'lib/command_window.rb', line 44 def (string) @command_line = string draw end |