module Bovem::ConsoleMethods::Logging
Methods for logging activities to the user.
Constants
- DEFAULT_STATUSES
Available statuses for tasks.
Public Instance Methods
Writes a message prepending a green banner.
@param message [String] The message to format. @param suffix [Object] If not `nil` or `false`, a suffix to add to the message. `true` means to add `n`. @param indented [Object] If not `nil` or `false`, the width to use for indentation. `true` means to use the current indentation,
a negative value of `-x` will indent of `x` absolute spaces.
@param wrap [Object] If not `nil` or `false`, the maximum length of a line for wrapped text. `true` means the current line width. @param plain [Boolean] If ignore color markers into the message. @param indented_banner [Boolean] If also the banner should be indented. @param full_colored [Boolean] If the banner should be fully colored. @param print [Boolean] If `false`, the result will be returned instead of be printed.
@see format
# File lib/bovem/console.rb, line 405 def begin(message, suffix: "\n", indented: true, wrap: false, plain: false, indented_banner: false, full_colored: false, print: true) banner = get_banner("*", "bright green", full_colored: full_colored) message = indent(message, indented_banner ? 0 : indented) write(banner + " " + message, suffix: suffix, indented: indented_banner ? indented : 0, wrap: wrap, plain: plain, print: print) end
Writes a message prepending a magenta banner.
@param message [String] The message to format. @param suffix [Object] If not `nil` or `false`, a suffix to add to the message. `true` means to add `n`. @param indented [Object] If not `nil` or `false`, the width to use for indentation. `true` means to use the current indentation,
a negative value of `-x` will indent of `x` absolute spaces.
@param wrap [Object] If not `nil` or `false`, the maximum length of a line for wrapped text. `true` means the current line width. @param plain [Boolean] If ignore color markers into the message. @param indented_banner [Boolean] If also the banner should be indented. @param full_colored [Boolean] If the banner should be fully colored. @param print [Boolean] If `false`, the result will be returned instead of be printed.
@see format
# File lib/bovem/console.rb, line 465 def debug(message, suffix: "\n", indented: true, wrap: false, plain: false, indented_banner: false, full_colored: false, print: true) info( message, suffix: suffix, indented: indented, wrap: wrap, plain: plain, indented_banner: indented_banner, full_colored: full_colored, print: print, banner: ["D", "bright magenta"] ) end
Writes a message prepending a red banner.
@param message [String] The message to format. @param suffix [Object] If not `nil` or `false`, a suffix to add to the message. `true` means to add `n`. @param indented [Object] If not `nil` or `false`, the width to use for indentation. `true` means to use the current indentation,
a negative value of `-x` will indent of `x` absolute spaces.
@param wrap [Object] If not `nil` or `false`, the maximum length of a line for wrapped text. `true` means the current line width. @param plain [Boolean] If ignore color markers into the message. @param indented_banner [Boolean] If also the banner should be indented. @param full_colored [Boolean] If the banner should be fully colored. @param print [Boolean] If `false`, the result will be returned instead of be printed.
@see format
# File lib/bovem/console.rb, line 519 def error(message, suffix: "\n", indented: true, wrap: false, plain: false, indented_banner: false, full_colored: false, print: true) info( message, suffix: suffix, indented: indented, wrap: wrap, plain: plain, indented_banner: indented_banner, full_colored: full_colored, print: print, banner: ["E", "bright red"] ) end
Writes a message prepending a red banner and then quits the application.
@param message [String] The message to format. @param suffix [Object] If not `nil` or `false`, a suffix to add to the message. `true` means to add `n`. @param indented [Object] If not `nil` or `false`, the width to use for indentation. `true` means to use the current indentation,
a negative value of `-x` will indent of `x` absolute spaces.
@param wrap [Object] If not `nil` or `false`, the maximum length of a line for wrapped text. `true` means the current line width. @param plain [Boolean] If ignore color markers into the message. @param indented_banner [Boolean] If also the banner should be indented. @param full_colored [Boolean] If the banner should be fully colored. @param return_code [Fixnum] The code to return to the shell. @param print [Boolean] If `false`, the result will be returned instead of be printed.
@see format
# File lib/bovem/console.rb, line 425 def fatal(message, suffix: "\n", indented: true, wrap: false, plain: false, indented_banner: false, full_colored: false, return_code: -1, print: true) error(message, suffix: suffix, indented: indented, wrap: wrap, plain: plain, indented_banner: indented_banner, full_colored: full_colored, print: print) Kernel.exit(return_code.to_integer(-1)) end
Writes a message prepending a cyan banner.
@param message [String] The message to format. @param suffix [Object] If not `nil` or `false`, a suffix to add to the message. `true` means to add `n`. @param indented [Object] If not `nil` or `false`, the width to use for indentation. `true` means to use the current indentation,
a negative value of `-x` will indent of `x` absolute spaces.
@param wrap [Object] If not `nil` or `false`, the maximum length of a line for wrapped text. `true` means the current line width. @param plain [Boolean] If ignore color markers into the message. @param indented_banner [Boolean] If also the banner should be indented. @param full_colored [Boolean] If the banner should be fully colored. @param print [Boolean] If `false`, the result will be returned instead of be printed. @param banner [Array] An array with at last letter and style to use for the banner.
@see format
# File lib/bovem/console.rb, line 444 def info(message, suffix: "\n", indented: true, wrap: false, plain: false, indented_banner: false, full_colored: false, print: true, banner: []) banner = banner.ensure_array(no_duplicates: true, compact: true, flatten: true) banner = ["I", "bright cyan"] if banner.blank? banner = get_banner(banner[0], banner[1], full_colored: full_colored) message = indent(message, indented_banner ? 0 : indented) write(banner + " " + message, suffix: suffix, indented: indented_banner ? indented : 0, wrap: wrap, plain: plain, print: print) end
Formats a progress for pretty printing.
@param current [Fixnum] The current progress index (e.g. the number of the current operation). @param total [Fixnum] The total progress index (e.g. the total number of operations). @param type [Symbol] The progress type. Can be `:list` (e.g. 01/15) or `:percentage` (e.g. 99.56%). @param precision [Fixnum] The precision of the percentage to return. *Ignored for list progress.* @return [String] The formatted progress.
# File lib/bovem/console.rb, line 382 def progress(current, total, type: :list, precision: 0) if type == :list compute_list_progress(current, total) else precision = [0, precision].max result = total == 0 ? 100 : (100 * (current.to_f / total)) sprintf("%0.#{precision}f %%", result.round(precision)).rjust(5 + (precision > 0 ? precision + 1 : 0)) end end
Writes a status to the output. Valid values are `:ok`, `:pass`, `:fail`, `:warn`, `skip`.
@param status [Symbol] The status to write. @param plain [Boolean] If not use colors. @param go_up [Boolean] If go up one line before formatting. @param right [Boolean] If to print results on the right. @param print [Boolean] If `false`, the result will be returned instead of be printed. @return [Array] An dictionary with `:label` and `:color` keys for the status.
# File lib/bovem/console.rb, line 340 def status(status, plain: false, go_up: true, right: true, print: true) statuses = DEFAULT_STATUSES.dup statuses.default = statuses[:ok] rv = statuses[status] if print banner = get_banner(rv[:label], rv[:color]) if right Kernel.puts(format_right(banner + " ", width: true, go_up: go_up, plain: plain)) else Kernel.puts(format(banner + " ", suffix: "\n", indent: true, wrap: true, plain: plain)) end end rv end
Writes a message prepending a yellow banner.
@param message [String] The message to format. @param suffix [Object] If not `nil` or `false`, a suffix to add to the message. `true` means to add `n`. @param indented [Object] If not `nil` or `false`, the width to use for indentation. `true` means to use the current indentation,
a negative value of `-x` will indent of `x` absolute spaces.
@param wrap [Object] If not `nil` or `false`, the maximum length of a line for wrapped text. `true` means the current line width. @param plain [Boolean] If ignore color markers into the message. @param indented_banner [Boolean] If also the banner should be indented. @param full_colored [Boolean] If the banner should be fully colored. @param print [Boolean] If `false`, the result will be returned instead of be printed.
@see format
# File lib/bovem/console.rb, line 492 def warn(message, suffix: "\n", indented: true, wrap: false, plain: false, indented_banner: false, full_colored: false, print: true) info( message, suffix: suffix, indented: indented, wrap: wrap, plain: plain, indented_banner: indented_banner, full_colored: full_colored, print: print, banner: ["W", "bright yellow"] ) end
Writes a message.
@param message [String] The message to format. @param suffix [Object] If not `nil` or `false`, a suffix to add to the message. `true` means to add `n`. @param indented [Object] If not `nil` or `false`, the width to use for indentation. `true` means to use the current indentation,
a negative value of `-x` will indent of `x` absolute spaces.
@param wrap [Object] If not `nil` or `false`, the maximum length of a line for wrapped text. `true` means the current line width. @param plain [Boolean] If ignore color markers into the message. @param print [Boolean] If `false`, the result will be returned instead of be printed. @return [String] The printed message.
@see format
# File lib/bovem/console.rb, line 303 def write(message, suffix: "\n", indented: true, wrap: false, plain: false, print: true) rv = format(message, suffix: suffix, indented: indented, wrap: wrap, plain: plain) Kernel.puts(rv) if print rv end