class Meshchat::Ui::Display::ReadlineDisplay
Public Instance Methods
add_line(line)
click to toggle source
TODO: find a more elegant way to handle color
# File lib/meshchat/ui/display/readline_display.rb, line 32 def add_line(line) print_non_destructively(line) end
alert(msg)
click to toggle source
# File lib/meshchat/ui/display/readline_display.rb, line 54 def alert(msg) print_non_destructively(msg.colorize(:red)) end
chat(msg)
click to toggle source
# File lib/meshchat/ui/display/readline_display.rb, line 72 def chat(msg) message_parts_for(msg) do |time, name, message, _| colored_time = (time.to_s + ' ').colorize(:light_magenta) colored_name = (name + ' ').colorize(:cyan) print_non_destructively(colored_time + colored_name + message) end end
emote(msg)
click to toggle source
# File lib/meshchat/ui/display/readline_display.rb, line 62 def emote(msg) message_parts_for(msg) do |time, name, message, _| colored_time = (time.to_s + ' ').colorize(:magenta) colored_name = (name + ' ').colorize(:light_black) colored_message = message.colorize(:light_black) print_non_destructively(colored_time + colored_name + colored_message) end end
info(msg)
click to toggle source
# File lib/meshchat/ui/display/readline_display.rb, line 36 def info(msg) if msg.is_a?(Hash) message_parts_for(msg) do |time, name, message, _| colored_time = (time.to_s + ' ').colorize(:magenta) colored_name = (name + ' ').colorize(:light_black) colored_message = message.colorize(:light_black) print_non_destructively(colored_time + colored_name + colored_message) end else print_non_destructively(msg.colorize(:light_black)) end end
message_parts_for(msg) { |nil, nil, msg| ... }
click to toggle source
# File lib/meshchat/ui/display/readline_display.rb, line 93 def message_parts_for(msg) return yield(nil, nil, msg) if msg.is_a?(String) time = msg[:time].strftime('%H:%M:%S') name = msg[:from].to_s message = msg[:message] to = msg[:to] yield(time, name, message, to) end
print_non_destructively(text)
click to toggle source
# 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()
click to toggle source
# 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)
click to toggle source
# File lib/meshchat/ui/display/readline_display.rb, line 58 def success(msg) print_non_destructively(msg.colorize(:green)) end
warning(msg)
click to toggle source
# File lib/meshchat/ui/display/readline_display.rb, line 50 def warning(msg) print_non_destructively(msg.colorize(:yellow)) end
whisper(msg)
click to toggle source
# File lib/meshchat/ui/display/readline_display.rb, line 81 def whisper(msg) message_parts_for(msg) do |time, name, message, to| colored_time = (time.to_s + ' ').colorize(:magenta).bold colored_name = name.colorize(:light_black).bold colored_message = message.colorize(:blue).bold colored_to = to.colorize(:blue).bold names = "#{colored_name}->#{to} " print_non_destructively(colored_time + names + colored_message) end end