module Belajar::Terminal::Output
Private Instance Methods
empty_line()
click to toggle source
# File lib/belajar/terminal/output.rb, line 14 def empty_line $stdout.puts '' end
get(string)
click to toggle source
# File lib/belajar/terminal/output.rb, line 18 def get(string) $stdout.print "\n\t#{string} " $stdin.gets.strip end
get_command(command, description)
click to toggle source
# File lib/belajar/terminal/output.rb, line 48 def get_command(command, description) say description loop do cmd = get '>' unless cmd == command say "This was something else. Try \"#{command}\"." next end system cmd break end end
get_confirm(description) { || ... }
click to toggle source
# File lib/belajar/terminal/output.rb, line 64 def get_confirm(description) say_warning description confirm = get '(yes|no)' yield if confirm == 'yes' && block_given? end
line(symbol = '-')
click to toggle source
# File lib/belajar/terminal/output.rb, line 44 def line(symbol = '-') symbol * 70 end
say(text)
click to toggle source
# File lib/belajar/terminal/output.rb, line 9 def say(text) output = text.split("\n").map { |line| "\t#{line}" }.join("\n") $stdout.puts output end
say_box(text, symbol, color)
click to toggle source
# File lib/belajar/terminal/output.rb, line 31 def say_box(text, symbol, color) empty_line say line.send(color) empty_line indented_text = text.split("\n").join("\n#{' ' * (symbol.length + 1)}") say indented_text.prepend("#{symbol} ").send(color) empty_line say line.send(color) empty_line end
say_info(text)
click to toggle source
# File lib/belajar/terminal/output.rb, line 23 def say_info(text) say_box(text, ' ℹ', :light_blue) end
say_warning(text)
click to toggle source
# File lib/belajar/terminal/output.rb, line 27 def say_warning(text) say_box(text, '⚠ ', :light_red) end