Class: Meshchat::Ui::Display::ReadlineDisplay
- Defined in:
- lib/meshchat/ui/display/readline_display.rb
Instance Method Summary collapse
-
#add_line(line) ⇒ Object
TODO: find a more elegant way to handle color.
- #alert(msg) ⇒ Object
- #chat(msg) ⇒ Object
- #emote(msg) ⇒ Object
- #info(msg) ⇒ Object
- #message_parts_for(msg) {|time, name, message, to| ... } ⇒ Object
- #print_non_destructively(text) ⇒ Object
- #start ⇒ Object
- #success(msg) ⇒ Object
- #warning(msg) ⇒ Object
- #whisper(msg) ⇒ Object
Methods inherited from Base
Instance Method Details
#add_line(line) ⇒ Object
TODO: find a more elegant way to handle color
32 33 34 |
# File 'lib/meshchat/ui/display/readline_display.rb', line 32 def add_line(line) print_non_destructively(line) end |
#alert(msg) ⇒ Object
54 55 56 |
# File 'lib/meshchat/ui/display/readline_display.rb', line 54 def alert(msg) print_non_destructively(msg.colorize(:red)) end |
#chat(msg) ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/meshchat/ui/display/readline_display.rb', line 72 def chat(msg) (msg) do |time, name, , _| colored_time = (time.to_s + ' ').colorize(:light_magenta) colored_name = (name + ' ').colorize(:cyan) print_non_destructively(colored_time + colored_name + ) end end |
#emote(msg) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/meshchat/ui/display/readline_display.rb', line 62 def emote(msg) (msg) do |time, name, , _| colored_time = (time.to_s + ' ').colorize(:magenta) colored_name = (name + ' ').colorize(:light_black) = .colorize(:light_black) print_non_destructively(colored_time + colored_name + ) end end |
#info(msg) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/meshchat/ui/display/readline_display.rb', line 36 def info(msg) if msg.is_a?(Hash) (msg) do |time, name, , _| colored_time = (time.to_s + ' ').colorize(:magenta) colored_name = (name + ' ').colorize(:light_black) = .colorize(:light_black) print_non_destructively(colored_time + colored_name + ) end else print_non_destructively(msg.colorize(:light_black)) end end |
#message_parts_for(msg) {|time, name, message, to| ... } ⇒ Object
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/meshchat/ui/display/readline_display.rb', line 93 def (msg) return yield(nil, nil, msg) if msg.is_a?(String) time = msg[:time].strftime('%H:%M:%S') name = msg[:from].to_s = msg[:message] to = msg[:to] yield(time, name, , to) end |
#print_non_destructively(text) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/meshchat/ui/display/readline_display.rb', line 15 def print_non_destructively(text) # Example of writing output while line is being edited. # # See also http://stackoverflow.com/questions/1512028/gnu-readline-how-do-clear-the-input-line if buffer = Readline.line_buffer print "\b \b" * buffer.size print "\r" end begin puts text + "\n" ensure Readline.forced_update_display end end |
#start ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/meshchat/ui/display/readline_display.rb', line 6 def start puts "\n" alert 'Welcome to Spiced Rumby!' puts "\n" puts "\n" # Start up Ripl, but it will not receive any user input # Ripl.start end |
#success(msg) ⇒ Object
58 59 60 |
# File 'lib/meshchat/ui/display/readline_display.rb', line 58 def success(msg) print_non_destructively(msg.colorize(:green)) end |
#warning(msg) ⇒ Object
50 51 52 |
# File 'lib/meshchat/ui/display/readline_display.rb', line 50 def warning(msg) print_non_destructively(msg.colorize(:yellow)) end |
#whisper(msg) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/meshchat/ui/display/readline_display.rb', line 81 def whisper(msg) (msg) do |time, name, , to| colored_time = (time.to_s + ' ').colorize(:magenta).bold colored_name = name.colorize(:light_black).bold = .colorize(:blue).bold colored_to = to.colorize(:blue).bold names = "#{colored_name}->#{to} " print_non_destructively(colored_time + names + ) end end |