class Fuelcell::Shell
Constants
- DEFAULT_TERMINAL_WIDTH
- ERROR_EXIT_CODE
- SUCCESS_EXIT_CODE
Attributes
backtrace[R]
backtrace?[R]
error_stream[R]
input_stream[R]
output_stream[R]
Public Class Methods
new(config = {})
click to toggle source
# File lib/fuelcell/shell.rb, line 13 def initialize(config = {}) @output_stream = config[:output_stream] || $stdout @input_stream = config[:input_stream] || $stdin @error_stream = config[:error_stream] || $stderr @backtrace = config[:backtrace] || false @terminal_cols = config[:terminal_cols] @backtrace = @backtrace == true ? true : false end
Public Instance Methods
disable_backtrace()
click to toggle source
# File lib/fuelcell/shell.rb, line 26 def disable_backtrace @backtrace = false end
dynamic_width()
click to toggle source
Determine the width using stty or tput
credit goes to the rake project, I took this from the application.rb @return Integer
# File lib/fuelcell/shell.rb, line 59 def dynamic_width @dynamic_width ||= (dynamic_width_stty.nonzero? || dynamic_width_tput) end
dynamic_width_stty()
click to toggle source
credit goes to the rake project, I took this from the application.rb
@return Integer
# File lib/fuelcell/shell.rb, line 79 def dynamic_width_stty `stty size 2>/dev/null`.split[1].to_i end
dynamic_width_tput()
click to toggle source
credit goes to the rake project, I took this from the application.rb
@return Integer
# File lib/fuelcell/shell.rb, line 86 def dynamic_width_tput `tput cols 2>/dev/null`.to_i end
enable_backtrace()
click to toggle source
# File lib/fuelcell/shell.rb, line 22 def enable_backtrace @backtrace = true end
error(text)
click to toggle source
# File lib/fuelcell/shell.rb, line 30 def error(text) error_stream.puts text end
exception(e)
click to toggle source
# File lib/fuelcell/shell.rb, line 34 def exception(e) message = e.message message << "\n" << e.backtrace.join("\n") if backtrace? error(message) failure_exit end
exit(code)
click to toggle source
# File lib/fuelcell/shell.rb, line 98 def exit(code) Kernel.exit(code) end
failure_exit()
click to toggle source
# File lib/fuelcell/shell.rb, line 94 def failure_exit exit(ERROR_EXIT_CODE) end
successful_exit()
click to toggle source
# File lib/fuelcell/shell.rb, line 90 def successful_exit exit(SUCCESS_EXIT_CODE) end
terminal_width()
click to toggle source
# File lib/fuelcell/shell.rb, line 41 def terminal_width if ENV['FUELCELL_COLUMNS'] result = ENV['FUELCELL_COLUMNS'].to_i elsif @terminal_cols result = @terminal_cols.to_i else result = unix? ? dynamic_width : DEFAULT_TERMINAL_WIDTH end result < 10 ? DEFAULT_TERMINAL_WIDTH : result rescue DEFAULT_TERMINAL_WIDTH end
unix?()
click to toggle source
Determines if we are on a unix like system for determining the width of the terminal
credit goes to the rake project, I took this from the application.rb
@return Boolean
# File lib/fuelcell/shell.rb, line 69 def unix? !( RUBY_PLATFORM =~ /(aix|darwin|linux|(net|free|open)bsd|cygwin|solaris|irix|hpux)/i ).nil? end