class Megam::Text
Attributes
config[R]
stderr[R]
stdin[R]
stdout[R]
Public Class Methods
new(stdout, stderr, stdin, config)
click to toggle source
# File lib/megam/core/text.rb 25 def initialize(stdout, stderr, stdin, config) 26 @stdout, @stderr, @stdin, @config = stdout, stderr, stdin, config 27 end
Public Instance Methods
agree(*args, &block)
click to toggle source
# File lib/megam/core/text.rb 81 def agree(*args, &block) 82 highline.agree(*args, &block) 83 end
ask(*args, &block)
click to toggle source
# File lib/megam/core/text.rb 85 def ask(*args, &block) 86 highline.ask(*args, &block) 87 end
ask_question(question, opts={})
click to toggle source
# File lib/megam/core/text.rb 100 def ask_question(question, opts={}) 101 question = question + "[#{opts[:default]}] " if opts[:default] 102 103 if opts[:default] and config[:defaults] 104 opts[:default] 105 else 106 stdout.print question 107 a = stdin.readline.strip 108 109 if opts[:default] 110 a.empty? ? opts[:default] : a 111 else 112 a 113 end 114 end 115 end
color(string, *colors)
click to toggle source
# File lib/megam/core/text.rb 65 def color(string, *colors) 66 if color? 67 highline.color(string, *colors) 68 else 69 string 70 end 71 end
color?()
click to toggle source
Should colored output be used? For output to a terminal, this is determined by the value of ‘config`. When output is not to a terminal, colored output is never used
# File lib/megam/core/text.rb 76 def color? 77 ##Chef::Config[:color] && stdout.tty? && !Chef::Platform.windows? 78 :red 79 end
err(message)
click to toggle source
Prints a msg to stderr. Used for warn, error, and fatal.
# File lib/megam/core/text.rb 46 def err(message) 47 stderr.puts message 48 end
error(message)
click to toggle source
Print an error message
# File lib/megam/core/text.rb 56 def error(message) 57 err("#{color('ERROR:', :red, :bold)} #{message}") 58 end
fatal(message)
click to toggle source
Print a message describing a fatal error.
# File lib/megam/core/text.rb 61 def fatal(message) 62 err("#{color('FATAL:', :red, :bold)} #{message}") 63 end
highline()
click to toggle source
# File lib/megam/core/text.rb 29 def highline 30 @highline ||= begin 31 require 'highline' 32 HighLine.new 33 end 34 end
list(*args)
click to toggle source
# File lib/megam/core/text.rb 89 def list(*args) 90 highline.list(*args) 91 end
msg(message)
click to toggle source
Prints a message to stdout. Aliased as info
for compatibility with the logger API.
# File lib/megam/core/text.rb 39 def msg(message) 40 stdout.puts message 41 end
Also aliased as: info
output(data)
click to toggle source
Formats data
using the configured presenter and outputs the result via msg
. Formatting can be customized by configuring a different presenter. See use_presenter
# File lib/megam/core/text.rb 96 def output(data) 97 msg @presenter.format(data) 98 end
pretty_print(data)
click to toggle source
# File lib/megam/core/text.rb 117 def pretty_print(data) 118 stdout.puts data 119 end
warn(message)
click to toggle source
Print a warning message
# File lib/megam/core/text.rb 51 def warn(message) 52 err("#{color('WARNING:', :yellow, :bold)} #{message}") 53 end