Class: I18nJS::CLI::UI
- Inherits:
-
Object
- Object
- I18nJS::CLI::UI
- Defined in:
- lib/i18n-js/cli/ui.rb
Instance Attribute Summary collapse
-
#colored ⇒ Object
Returns the value of attribute colored.
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
Instance Method Summary collapse
- #ansi(text, code) ⇒ Object
- #colored? ⇒ Boolean
- #exit_with(*message) ⇒ Object
- #fail_with(*message) ⇒ Object
-
#initialize(stdout:, stderr:, colored: nil) ⇒ UI
constructor
A new instance of UI.
- #no_color? ⇒ Boolean
- #red(text) ⇒ Object
- #stderr_print(*message) ⇒ Object
- #stdout_print(*message) ⇒ Object
- #yellow(text) ⇒ Object
Constructor Details
#initialize(stdout:, stderr:, colored: nil) ⇒ UI
Returns a new instance of UI.
9 10 11 12 13 |
# File 'lib/i18n-js/cli/ui.rb', line 9 def initialize(stdout:, stderr:, colored: nil) @stdout = stdout @stderr = stderr @colored = colored end |
Instance Attribute Details
#colored ⇒ Object
Returns the value of attribute colored.
7 8 9 |
# File 'lib/i18n-js/cli/ui.rb', line 7 def colored @colored end |
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
6 7 8 |
# File 'lib/i18n-js/cli/ui.rb', line 6 def stderr @stderr end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
6 7 8 |
# File 'lib/i18n-js/cli/ui.rb', line 6 def stdout @stdout end |
Instance Method Details
#ansi(text, code) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/i18n-js/cli/ui.rb', line 51 def ansi(text, code) if colored? "\e[#{code}m#{text}\e[0m" else text end end |
#colored? ⇒ Boolean
41 42 43 44 45 46 47 48 49 |
# File 'lib/i18n-js/cli/ui.rb', line 41 def colored? colored_output = if colored.nil? stdout.tty? else colored end colored_output && !no_color? end |
#exit_with(*message) ⇒ Object
28 29 30 31 |
# File 'lib/i18n-js/cli/ui.rb', line 28 def exit_with(*) stdout_print() exit(0) end |
#fail_with(*message) ⇒ Object
23 24 25 26 |
# File 'lib/i18n-js/cli/ui.rb', line 23 def fail_with(*) stderr_print() exit(1) end |
#no_color? ⇒ Boolean
59 60 61 |
# File 'lib/i18n-js/cli/ui.rb', line 59 def no_color? !ENV["NO_COLOR"].nil? && ENV["NO_COLOR"] == "1" end |
#red(text) ⇒ Object
37 38 39 |
# File 'lib/i18n-js/cli/ui.rb', line 37 def red(text) ansi(text, 31) end |
#stderr_print(*message) ⇒ Object
19 20 21 |
# File 'lib/i18n-js/cli/ui.rb', line 19 def stderr_print(*) stderr << "#{.join(' ')}\n" end |
#stdout_print(*message) ⇒ Object
15 16 17 |
# File 'lib/i18n-js/cli/ui.rb', line 15 def stdout_print(*) stdout << "#{.join(' ')}\n" end |
#yellow(text) ⇒ Object
33 34 35 |
# File 'lib/i18n-js/cli/ui.rb', line 33 def yellow(text) ansi(text, 33) end |