Class: Pocolog::CLI::TTYReporter
- Inherits:
-
Object
- Object
- Pocolog::CLI::TTYReporter
- Defined in:
- lib/pocolog/cli/tty_reporter.rb
Instance Attribute Summary collapse
-
#base ⇒ Object
Base value for #current.
-
#c_error ⇒ Object
readonly
Returns the value of attribute c_error.
-
#c_info ⇒ Object
readonly
Returns the value of attribute c_info.
-
#c_title ⇒ Object
readonly
Returns the value of attribute c_title.
-
#c_warn ⇒ Object
readonly
Returns the value of attribute c_warn.
-
#progress_bar ⇒ Object
readonly
Returns the value of attribute progress_bar.
Instance Method Summary collapse
- #advance(step = 1) ⇒ Object
- #current ⇒ Object
- #current=(value) ⇒ Object
- #error(msg) ⇒ Object
- #finish ⇒ Object
- #info(msg) ⇒ Object
-
#initialize(format, colors: true, progress: true, **options) ⇒ TTYReporter
constructor
A new instance of TTYReporter.
- #log(msg) ⇒ Object
- #reset_progressbar(format, **options) ⇒ Object
- #title(msg) ⇒ Object
- #warn(msg) ⇒ Object
Constructor Details
#initialize(format, colors: true, progress: true, **options) ⇒ TTYReporter
Returns a new instance of TTYReporter
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/pocolog/cli/tty_reporter.rb', line 21 def initialize(format, colors: true, progress: true, **) @base = 0 @progress_enabled = progress (format, **) pastel = Pastel.new(enabled: colors) @c_warn = pastel.yellow.detach @c_info = pastel.yellow.detach @c_error = pastel.bright_red.detach @c_title = pastel.bold.detach end |
Instance Attribute Details
#base ⇒ Object
Base value for #current
It works as an offset between the reporter's current value and the underlying progress handler
19 20 21 |
# File 'lib/pocolog/cli/tty_reporter.rb', line 19 def base @base end |
#c_error ⇒ Object (readonly)
Returns the value of attribute c_error
11 12 13 |
# File 'lib/pocolog/cli/tty_reporter.rb', line 11 def c_error @c_error end |
#c_info ⇒ Object (readonly)
Returns the value of attribute c_info
13 14 15 |
# File 'lib/pocolog/cli/tty_reporter.rb', line 13 def c_info @c_info end |
#c_title ⇒ Object (readonly)
Returns the value of attribute c_title
12 13 14 |
# File 'lib/pocolog/cli/tty_reporter.rb', line 12 def c_title @c_title end |
#c_warn ⇒ Object (readonly)
Returns the value of attribute c_warn
10 11 12 |
# File 'lib/pocolog/cli/tty_reporter.rb', line 10 def c_warn @c_warn end |
#progress_bar ⇒ Object (readonly)
Returns the value of attribute progress_bar
9 10 11 |
# File 'lib/pocolog/cli/tty_reporter.rb', line 9 def @progress_bar end |
Instance Method Details
#advance(step = 1) ⇒ Object
60 61 62 63 64 |
# File 'lib/pocolog/cli/tty_reporter.rb', line 60 def advance(step = 1) return unless @progress_enabled .advance(step) end |
#current ⇒ Object
48 49 50 51 52 |
# File 'lib/pocolog/cli/tty_reporter.rb', line 48 def current return unless @progress_enabled .current - base end |
#current=(value) ⇒ Object
54 55 56 57 58 |
# File 'lib/pocolog/cli/tty_reporter.rb', line 54 def current=(value) return unless @progress_enabled .current = value + base end |
#error(msg) ⇒ Object
78 79 80 |
# File 'lib/pocolog/cli/tty_reporter.rb', line 78 def error(msg) log(c_error.call(msg)) end |
#finish ⇒ Object
82 83 84 85 86 |
# File 'lib/pocolog/cli/tty_reporter.rb', line 82 def finish return unless @progress_enabled .finish end |
#info(msg) ⇒ Object
70 71 72 |
# File 'lib/pocolog/cli/tty_reporter.rb', line 70 def info(msg) log(c_info.call(msg)) end |
#log(msg) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/pocolog/cli/tty_reporter.rb', line 40 def log(msg) if &.send(:tty?) .log(msg) else $stdout.puts(msg) end end |
#reset_progressbar(format, **options) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/pocolog/cli/tty_reporter.rb', line 32 def (format, **) return unless @progress_enabled .reset if @progress_bar @progress_bar = TTY::ProgressBar.new(format, **) .resize(60) end |
#title(msg) ⇒ Object
66 67 68 |
# File 'lib/pocolog/cli/tty_reporter.rb', line 66 def title(msg) log(c_title.call(msg)) end |
#warn(msg) ⇒ Object
74 75 76 |
# File 'lib/pocolog/cli/tty_reporter.rb', line 74 def warn(msg) log(c_warn.call(msg)) end |