In Files

Parent

Syckle::IO

Syckle IO

The IO class is used to cleanly separate out the basic input/output “dialog” between user and script.

Attributes

cli[R]
stderr[R]
stdin[R]
stdout[R]

Public Class Methods

new(cli, stdout=nil, stderr=nil, stdin=nil) click to toggle source
# File lib/syckle/io.rb, line 21
def initialize(cli, stdout=nil, stderr=nil, stdin=nil)
  @cli = cli
  @stdout = stdout || $stdout
  @stderr = stderr || $stderr
  @stdin  = stdin  || $stdin
end

Public Instance Methods

ask(question, answers=nil) click to toggle source

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
debug?() click to toggle source
# File lib/syckle/io.rb, line 34
def debug?   ; cli.debug?   ; end
display_action(action_item) click to toggle source
# 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
force?() click to toggle source
# File lib/syckle/io.rb, line 28
def force?   ; cli.force?   ; end
password(prompt=nil) click to toggle source

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
printline(left, right='', options={}) click to toggle source
# 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
puts(str=nil) click to toggle source
# File lib/syckle/io.rb, line 93
def puts(str=nil)
  stdout.puts(str.to_s) unless quiet?
end
quiet?() click to toggle source
# File lib/syckle/io.rb, line 29
def quiet?   ; cli.quiet?   ; end
report(message) click to toggle source

TODO: just rename to puts ?

# File lib/syckle/io.rb, line 37
def report(message)
  stdout.puts message unless quiet?
end
status(message) click to toggle source

TODO: deprecate in favor of report (or puts ?)

# File lib/syckle/io.rb, line 42
def status(message)
  stderr.puts message unless quiet?
end
status_header(left, right='') click to toggle source
# 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
status_line(left, right='') click to toggle source
# 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
trace(message) click to toggle source

Internal status report. Only output if in TRACE mode.

# File lib/syckle/io.rb, line 49
def trace(message)
  stderr.puts message if verbose?
end
trace?() click to toggle source
# File lib/syckle/io.rb, line 32
def trace?   ; cli.trace?   ; end
trial?() click to toggle source
# File lib/syckle/io.rb, line 33
def trial?   ; cli.trial?   ; end
verbose?() click to toggle source
# File lib/syckle/io.rb, line 30
def verbose? ; cli.verbose? ; end

[Validate]

Generated with the Darkfish Rdoc Generator 2.