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
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
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
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
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
@param str [String] String
with header content @param underline [Boolean] True to underline the header
# File lib/cli_helper.rb, line 229 def self.print_header(str, underline = true) if $stdout.tty? print_tty_header(str, underline) else print str end puts end
Print pretty header
@param str [String] String
with header content @param underline [Boolean] True to underline the header
# File lib/cli_helper.rb, line 243 def self.print_tty_header(str, underline = true) scr_bold scr_underline if underline print str scr_restore end
Sets bold font
# File lib/cli_helper.rb, line 150 def self.scr_bold print "\33[1m" end
Clears screen
# File lib/cli_helper.rb, line 165 def self.scr_cls print "\33[2J\33[H" end
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
Restore normal font
# File lib/cli_helper.rb, line 160 def self.scr_restore print "\33[0m" end
Sets underline
# File lib/cli_helper.rb, line 155 def self.scr_underline print "\33[4m" end