module CLIHelper

CLI Helper

Constants

ADJUST
ANSI_GREEN
ANSI_RED

CLI state colors

ANSI_RESET
ANSI_YELLOW
BAD_STATES
CSV_DEL
CSV_OPT
DELAY
EXPAND
FILTER
FILTER_OPS

Available operators for filtering operations

LIST

CLI general options

LISTCONF
NO_EXPAND
NO_HEADER
NO_PAGER
OK_STATES

CLI states

OPERATOR
OPTIONS
REGULAR_STATES
SIZE

Public Class Methods

base64?(value) click to toggle source

Check if value is in base64

@param value [String] Value to check

@return [Boolean] True if it's base64

# File lib/cli_helper.rb, line 264
def self.base64?(value)
    re = %r(^([A-Za-z0-9+\/]{4})*([A-Za-z0-9+\/]{3}=|[A-Za-z0-9+\/]{2}==)?$)

    !value.match(re).nil?
end
color_state(state) click to toggle source

Set state color

@param stat [String] Current state

# File lib/cli_helper.rb, line 197
def self.color_state(state)
    if $stdout.tty?
        case state.strip
        when *OK_STATES
            ANSI_GREEN + state + ANSI_RESET
        when *BAD_STATES
            ANSI_RED + state + ANSI_RESET
        when *REGULAR_STATES
            ANSI_YELLOW + state + ANSI_RESET
        else
            state
        end
    else
        state
    end
end
fail(message) click to toggle source

Show error message and exit with error

@param message [String] Error message to show

# File lib/cli_helper.rb, line 253
def self.fail(message)
    STDERR.puts message

    exit(-1)
end
green(text) click to toggle source

Get text in green colour

@param text [String] String to print

# File lib/cli_helper.rb, line 217
def self.green(text)
    if $stdout.tty?
        ANSI_GREEN + text + ANSI_RESET
    else
        text
    end
end
print_header(str, underline = true) click to toggle source

Print header

@param str [String] String with header content @param underline [Boolean] True to underline the header

print_tty_header(str, underline = true) click to toggle source

Print pretty header

@param str [String] String with header content @param underline [Boolean] True to underline the header

scr_bold() click to toggle source

Sets bold font

# File lib/cli_helper.rb, line 150
def self.scr_bold
    print "\33[1m"
end
scr_cls() click to toggle source

Clears screen

# File lib/cli_helper.rb, line 165
def self.scr_cls
    print "\33[2J\33[H"
end
scr_move(cord_x, cord_y) click to toggle source

Moves the cursor

@param cord_x [Integer] Coordinate x @param cord_y [Integer] Coordinate y

# File lib/cli_helper.rb, line 173
def self.scr_move(cord_x, cord_y)
    print "\33[#{cord_x};#{cord_y}H"
end
scr_restore() click to toggle source

Restore normal font

# File lib/cli_helper.rb, line 160
def self.scr_restore
    print "\33[0m"
end
scr_underline() click to toggle source

Sets underline

# File lib/cli_helper.rb, line 155
def self.scr_underline
    print "\33[4m"
end