Class: TwittyConsole::CUI
- Inherits:
-
Object
- Object
- TwittyConsole::CUI
- Includes:
- Term::ANSIColor
- Defined in:
- lib/twitty-console/cui.rb
Constant Summary collapse
- PROMPT =
'> '
- @@encoding =
'UTF-8'
Instance Attribute Summary collapse
-
#handler ⇒ Object
writeonly
Sets the attribute handler.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#handler=(value) ⇒ Object (writeonly)
Sets the attribute handler
26 27 28 |
# File 'lib/twitty-console/cui.rb', line 26 def handler=(value) @handler = value end |
Class Method Details
.encoding=(encoding) ⇒ Object
28 29 30 |
# File 'lib/twitty-console/cui.rb', line 28 def self.encoding= encoding @@encoding = encoding end |
Instance Method Details
#output(statuses) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/twitty-console/cui.rb', line 32 def output statuses puts statuses.each do |status| screen_name = status.user.screen_name text = Iconv.conv(@@encoding, 'UTF-8', status.text) puts "%s: %s" % [blue(screen_name), text] end prompt end |
#prompt ⇒ Object
62 63 64 65 |
# File 'lib/twitty-console/cui.rb', line 62 def prompt print PROMPT STDOUT.flush end |
#start ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/twitty-console/cui.rb', line 49 def start while text = Readline.readline(PROMPT, true) break if text.nil? unless text.strip.empty? @handler.handle(Iconv.conv('UTF-8', @@encoding, text)) end end end |
#stop ⇒ Object
59 60 |
# File 'lib/twitty-console/cui.rb', line 59 def stop end |
#warn(message) ⇒ Object
43 44 45 46 47 |
# File 'lib/twitty-console/cui.rb', line 43 def warn puts puts red() prompt end |