Object
The IO class is used to cleanly separate out the basic input/output “dialog” between user and script.
Convenient method to get simple console reply.
# File lib/syckle/io.rb, line 54 def ask(question, answers=nil) stdout.print "#{question}" stdout.print " [#{answers}] " if answers stdout.flush until inp = stdin.gets ; sleep 1 ; end inp.strip end
# File lib/syckle/io.rb, line 133 def display_action(action_item) phase, service, action, parameters = *action_item puts " %-10s %-10s %-10s" % [phase.to_s.capitalize, service.service_title, action] #status_line(service.service_title, phase.to_s.capitalize) end
TODO: Until we have better support for getting input acorss platforms we are using ask only.
# File lib/syckle/io.rb, line 82 def password(prompt=nil) prompt ||= "Enter Password: " ask(prompt) end
# File lib/syckle/io.rb, line 88 def print(str=nil) stdout.print(str.to_s) unless quiet? end
# File lib/syckle/io.rb, line 168 def print_header(left, right) if ANSI::SUPPORTED printline('', '', :pad=>1, :sep=>' ', :style=>[:negative, :bold], :left=>[:bold], :right=>[:bold]) printline(left, right, :pad=>2, :sep=>' ', :style=>[:negative, :bold], :left=>[:bold], :right=>[:bold]) printline('', '', :pad=>1, :sep=>' ', :style=>[:negative, :bold], :left=>[:bold], :right=>[:bold]) else printline(left, right, :pad=>2, :sep=>'=') end end
# File lib/syckle/io.rb, line 179 def print_phase(left, right) if ANSI::SUPPORTED printline(left, right, :pad=>2, :sep=>' ', :style=>[:on_white, :black, :bold], :left=>[:bold], :right=>[:bold]) else printline(left, right, :pad=>2, :sep=>'-') end end
# File lib/syckle/io.rb, line 98 def printline(left, right='', options={}) return if quiet? separator = options[:seperator] || options[:sep] || ' ' padding = options[:padding] || options[:pad] || 0 left, right = left.to_s, right.to_s left_size = left.size right_size = right.size #left = colorize(left) #right = colorize(right) l = padding r = -(right_size + padding) style = options[:style] || [] lstyle = options[:left] || [] rstyle = options[:right] || [] left = lstyle.inject(left) { |s, c| ansize(s, c) } right = rstyle.inject(right){ |s, c| ansize(s, c) } line = separator * screen_width line[l, left_size] = left if left_size != 0 line[r, right_size] = right if right_size != 0 line = style.inject(line){ |s, c| ansize(s, c) } puts line + ansize('', :clear) end
# File lib/syckle/io.rb, line 93 def puts(str=nil) stdout.puts(str.to_s) unless quiet? end
TODO: just rename to puts ?
# File lib/syckle/io.rb, line 37 def report(message) stdout.puts message unless quiet? end
# File lib/syckle/io.rb, line 141 def status_header(left, right='') left, right = left.to_s, right.to_s #left.color = 'blue' #right.color = 'magenta' unless quiet? puts print_header(left, right) #puts "=" * io.screen_width end end
# File lib/syckle/io.rb, line 154 def status_line(left, right='') left, right = left.to_s, right.to_s #left.color = 'blue' #right.color = 'magenta' unless quiet? puts #puts "-" * io.screen_width print_phase(left, right) #puts "-" * io.screen_width #puts end end
Generated with the Darkfish Rdoc Generator 2.