Class: CommandWindow

Inherits:
Object
  • Object
show all
Defined in:
lib/command_window.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_lineObject

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_feedObject



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

#clearObject



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

#closeObject



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

#drawObject



82
83
84
85
86
# File 'lib/command_window.rb', line 82

def draw
  @window.clear
  @window << @command_line
  @window.refresh
end

#escape_help_promptObject



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_stringObject



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_promptObject



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 message(string)
  @command_line = string
  draw
end