Class: Clack::TaskLog
- Inherits:
-
Object
- Object
- Clack::TaskLog
- Defined in:
- lib/clack/task_log.rb
Overview
A streaming log that clears on success and remains on failure Useful for build output, npm install style streaming, etc.
Instance Method Summary collapse
-
#add_group_message(_group, msg) ⇒ Object
Add a message from a group to the log buffer.
-
#error(msg, show_log: true) ⇒ Object
Complete with error - keeps the log visible.
-
#group(name) ⇒ TaskLogGroup
Create a named group for messages.
-
#initialize(title:, limit: nil, retain_log: false, output: $stdout) ⇒ TaskLog
constructor
A new instance of TaskLog.
-
#message(msg) ⇒ Object
Add a message to the log.
-
#success(msg, show_log: false) ⇒ Object
Complete with success - clears the log.
Constructor Details
#initialize(title:, limit: nil, retain_log: false, output: $stdout) ⇒ TaskLog
Returns a new instance of TaskLog.
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/clack/task_log.rb', line 19 def initialize(title:, limit: nil, retain_log: false, output: $stdout) @title = title @limit = limit @retain_log = retain_log @output = output @buffer = [] @full_buffer = [] @groups = [] @lines_written = 0 @tty = tty_output?(output) render_title end |
Instance Method Details
#add_group_message(_group, msg) ⇒ Object
Add a message from a group to the log buffer.
73 74 75 76 77 78 |
# File 'lib/clack/task_log.rb', line 73 def (_group, msg) clear_buffer @buffer << msg.to_s apply_limit render_buffer if @tty end |
#error(msg, show_log: true) ⇒ Object
Complete with error - keeps the log visible
64 65 66 67 68 69 |
# File 'lib/clack/task_log.rb', line 64 def error(msg, show_log: true) clear_all @output.puts "#{Colors.red(Symbols::S_STEP_ERROR)} #{msg}" render_full_buffer if show_log reset_buffers end |
#group(name) ⇒ TaskLogGroup
Create a named group for messages
45 46 47 48 49 |
# File 'lib/clack/task_log.rb', line 45 def group(name) grp = TaskLogGroup.new(name, self) @groups << grp grp end |
#message(msg) ⇒ Object
Add a message to the log
35 36 37 38 39 40 |
# File 'lib/clack/task_log.rb', line 35 def (msg) clear_buffer @buffer << msg.to_s.gsub(/\e\[[\d;]*[ABCDEFGHfJKSTsu]/, "") # Strip cursor movement codes apply_limit render_buffer if @tty end |
#success(msg, show_log: false) ⇒ Object
Complete with success - clears the log
54 55 56 57 58 59 |
# File 'lib/clack/task_log.rb', line 54 def success(msg, show_log: false) clear_all @output.puts "#{Colors.green(Symbols::S_STEP_SUBMIT)} #{msg}" render_full_buffer if show_log reset_buffers end |