class Bauxite::Loggers::TerminalLogger

Terminal logger.

This logger outputs text using basic text formatting for a terminal window.

Public Class Methods

new(options) click to toggle source

Constructs a new Terminal logger instance.

Calls superclass method Bauxite::Loggers::NullLogger.new
# File lib/bauxite/loggers/terminal.rb, line 30
def initialize(options)
        super(options)
        @max_cmd_size = Bauxite::Context::max_action_name_size
end

Public Instance Methods

debug_prompt() click to toggle source

Returns a colorized debug prompt.

# File lib/bauxite/loggers/terminal.rb, line 65
def debug_prompt
        _fmt(:white, super)
end
log(s, type = :info) click to toggle source

Prints the specified string.

See Bauxite::Loggers::NullLogger#print

Calls superclass method Bauxite::Loggers::NullLogger#log
# File lib/bauxite/loggers/terminal.rb, line 80
def log(s, type = :info)
        color = :gray
        case type
        when :error
                color = :red
        when :warning
                color = :yellow
        when :debug
                color = :purple
        end
        super _fmt(color, s), type
end
log_cmd(action) { || ... } click to toggle source

Pretty prints action information and status.

# File lib/bauxite/loggers/terminal.rb, line 36
def log_cmd(action)
        width = _screen_width
        cmd = action.cmd.downcase
        color = _cmd_color(cmd)
        cmd = cmd.ljust(@max_cmd_size)
        max_args_size = width-cmd.size-1-6-1-1

        print "#{_fmt(color, cmd)} "
        s = action.args(true).join(' ')
        s = s[0...max_args_size-3]+'...' if s.size > max_args_size
        print s.ljust(max_args_size)
        _save_cursor
        color = :green
        text  = 'OK'
        ret = yield
        if not ret
                color = :yellow
                text  = 'SKIP'
        end
        _restore_cursor
        puts " #{_block(color, text, 5)}"
        ret
rescue
        _restore_cursor
        puts " #{_block(:red, 'ERROR', 5)}"
        raise
end
progress(value) click to toggle source

Updates action progress.

# File lib/bauxite/loggers/terminal.rb, line 70
def progress(value)
        if _restore_cursor
                print " #{_block(:gray, value.to_s, 5)}"
        end
end

Protected Instance Methods

_block(color, text, size) click to toggle source

Prints text centered inside a square-bracketed block.

# File lib/bauxite/loggers/terminal.rb, line 110
def _block(color, text, size)
        "#{_fmt(:white, '[')}#{_fmt(color, text, size)}#{_fmt(:white, ']')}"
end
_cmd_color(cmd) click to toggle source

Get the color of cmd.

# File lib/bauxite/loggers/terminal.rb, line 115
def _cmd_color(cmd)
        case cmd
        when 'load'
                return :cyan
        when 'test'
                return :purple
        else
                return :blue
        end
end
_fmt(color, text, size = 0) click to toggle source

Centers text to a fixed size with.

# File lib/bauxite/loggers/terminal.rb, line 95
def _fmt(color, text, size = 0)
        text.center(size)
end
_restore_cursor() click to toggle source

Restores the cursor to the previously saved cursor position.

# File lib/bauxite/loggers/terminal.rb, line 105
def _restore_cursor
        false
end
_save_cursor() click to toggle source

Save the current cursor position,

# File lib/bauxite/loggers/terminal.rb, line 100
def _save_cursor
        false
end
_screen_width() click to toggle source

Returns the terminal screen width.

# File lib/bauxite/loggers/terminal.rb, line 127
def _screen_width
        80
end