module Obfusk::Util::Term

Constants

GET_COLS
GET_LINES
TERM_COLOUR_ALIASES

some colour aliases

TERM_COLOUR_CODES

ansi colour codes

TERM_COLOUR_ESCAPES

ansi colour escapes

Public Class Methods

colour(x, what = :out) click to toggle source

colour code (or ” if not tty)

# File lib/obfusk/util/term.rb, line 54
def self.colour(x, what = :out)
  c = TERM_COLOUR_ESCAPES[x] or raise ArgumentError,
        "No such colour: #{x}"
  tty?(what) ? c : ''
end
colour_e(x) click to toggle source

colour code for $stderr

# File lib/obfusk/util/term.rb, line 61
def self.colour_e(x)
  colour x, :err
end
columns() click to toggle source

terminal columns

# File lib/obfusk/util/term.rb, line 68
def self.columns
  %x[#{GET_COLS}].to_i
end
lines() click to toggle source

terminal lines

# File lib/obfusk/util/term.rb, line 73
def self.lines
  %x[#{GET_LINES}].to_i
end
prompt(prompt, hide = false) click to toggle source

prompt for line; optionally hide input

# File lib/obfusk/util/term.rb, line 85
def self.prompt(prompt, hide = false)
  print prompt; $stdout.flush
  line = hide ? $stdin.noecho { |i| i.gets } .tap { puts } :
                $stdin.gets
  line && line.chomp
end
tty?(what = :out) click to toggle source

is $stdout (or $stderr) a tty?

# File lib/obfusk/util/term.rb, line 78
def self.tty?(what = :out)
  (what == :out ? $stdout : $stderr).isatty
end