Class: Podnix::Text
- Inherits:
-
Object
- Object
- Podnix::Text
- Defined in:
- lib/podnix/core/text.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
-
#stdin ⇒ Object
readonly
Returns the value of attribute stdin.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
Instance Method Summary collapse
- #color(string, *colors) ⇒ Object
-
#color? ⇒ Boolean
Should colored output be used ?.
-
#err(message) ⇒ Object
Prints a msg to stderr.
-
#error(message) ⇒ Object
Print an error message.
-
#fatal(message) ⇒ Object
Print a message describing a fatal error.
- #highline ⇒ Object
-
#info(message) ⇒ Object
Prints a message to stdout.
-
#initialize(stdout, stderr, stdin, config) ⇒ Text
constructor
A new instance of Text.
- #list(*args) ⇒ Object
- #msg(message) ⇒ Object
- #pretty_print(data) ⇒ Object
-
#warn(message) ⇒ Object
Print a warning message.
Constructor Details
#initialize(stdout, stderr, stdin, config) ⇒ Text
Returns a new instance of Text.
23 24 25 |
# File 'lib/podnix/core/text.rb', line 23 def initialize(stdout, stderr, stdin, config) @stdout, @stderr, @stdin, @config = stdout, stderr, stdin, config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
22 23 24 |
# File 'lib/podnix/core/text.rb', line 22 def config @config end |
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
20 21 22 |
# File 'lib/podnix/core/text.rb', line 20 def stderr @stderr end |
#stdin ⇒ Object (readonly)
Returns the value of attribute stdin.
21 22 23 |
# File 'lib/podnix/core/text.rb', line 21 def stdin @stdin end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
19 20 21 |
# File 'lib/podnix/core/text.rb', line 19 def stdout @stdout end |
Instance Method Details
#color(string, *colors) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/podnix/core/text.rb', line 65 def color(string, *colors) if color? highline.color(string, *colors) else string end end |
#color? ⇒ Boolean
Should colored output be used ?. When output is not to a terminal, colored output is never used
75 76 77 |
# File 'lib/podnix/core/text.rb', line 75 def color? stdout.tty? end |
#err(message) ⇒ Object
Prints a msg to stderr. Used for warn, error, and fatal.
46 47 48 |
# File 'lib/podnix/core/text.rb', line 46 def err() stderr.puts end |
#error(message) ⇒ Object
Print an error message
56 57 58 |
# File 'lib/podnix/core/text.rb', line 56 def error() err("#{color('ERROR:', :red, :bold)} #{}") end |
#fatal(message) ⇒ Object
Print a message describing a fatal error.
61 62 63 |
# File 'lib/podnix/core/text.rb', line 61 def fatal() err("#{color('FATAL:', :red, :bold)} #{}") end |
#highline ⇒ Object
27 28 29 30 31 32 |
# File 'lib/podnix/core/text.rb', line 27 def highline @highline ||= begin require 'highline' HighLine.new end end |
#info(message) ⇒ Object
Prints a message to stdout. Aliased as info
for compatibility with the logger API.
41 42 43 |
# File 'lib/podnix/core/text.rb', line 41 def info() stdout.puts("#{color('INFO:', :green, :bold)} #{}") end |
#list(*args) ⇒ Object
79 80 81 |
# File 'lib/podnix/core/text.rb', line 79 def list(*args) highline.list(*args) end |
#msg(message) ⇒ Object
34 35 36 |
# File 'lib/podnix/core/text.rb', line 34 def msg() stdout.puts end |
#pretty_print(data) ⇒ Object
83 84 85 |
# File 'lib/podnix/core/text.rb', line 83 def pretty_print(data) stdout.puts data end |
#warn(message) ⇒ Object
Print a warning message
51 52 53 |
# File 'lib/podnix/core/text.rb', line 51 def warn() err("#{color('WARNING:', :yellow, :bold)} #{}") end |