Class: Exa::Shell
- Inherits:
-
Object
- Object
- Exa::Shell
- Defined in:
- lib/exa/shell.rb
Instance Attribute Summary collapse
-
#pwd ⇒ Object
readonly
Returns the value of attribute pwd.
Class Method Summary collapse
Instance Method Summary collapse
- #change_directory(target) ⇒ Object
- #configuration ⇒ Object
-
#initialize(pwd) ⇒ Shell
constructor
A new instance of Shell.
- #kickstart! ⇒ Object
- #pastel ⇒ Object
- #print_collection(elements) ⇒ Object
- #print_info(message) ⇒ Object
- #print_warning(message) ⇒ Object
- #shell_eval(cmd_str) ⇒ Object
Constructor Details
#initialize(pwd) ⇒ Shell
Returns a new instance of Shell.
51 52 53 |
# File 'lib/exa/shell.rb', line 51 def initialize(pwd) @pwd = pwd end |
Instance Attribute Details
#pwd ⇒ Object (readonly)
Returns the value of attribute pwd.
49 50 51 |
# File 'lib/exa/shell.rb', line 49 def pwd @pwd end |
Class Method Details
.repl! {|shell.configuration| ... } ⇒ Object
101 102 103 104 105 |
# File 'lib/exa/shell.rb', line 101 def self.repl! shell = new(Exa['/']) yield shell.configuration shell.kickstart! end |
Instance Method Details
#change_directory(target) ⇒ Object
73 74 75 |
# File 'lib/exa/shell.rb', line 73 def change_directory(target) @pwd = target end |
#configuration ⇒ Object
55 56 57 |
# File 'lib/exa/shell.rb', line 55 def configuration @config ||= ShellConfig.new end |
#kickstart! ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/exa/shell.rb', line 59 def kickstart! loop do print configuration.prompt.call(self) inp = gets.chomp outp = shell_eval(inp) p outp unless outp.nil? || (outp.respond_to?(:empty?) && outp.empty?) end end |
#pastel ⇒ Object
97 98 99 |
# File 'lib/exa/shell.rb', line 97 def pastel @pastel ||= Pastel.new end |
#print_collection(elements) ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/exa/shell.rb', line 77 def print_collection(elements) puts elements.each do |element| puts " - " + pastel.blue(" #{element}") end puts end |
#print_info(message) ⇒ Object
91 92 93 94 95 |
# File 'lib/exa/shell.rb', line 91 def print_info() puts puts pastel.green() puts end |
#print_warning(message) ⇒ Object
85 86 87 88 89 |
# File 'lib/exa/shell.rb', line 85 def print_warning() puts puts pastel.red() puts end |
#shell_eval(cmd_str) ⇒ Object
68 69 70 71 |
# File 'lib/exa/shell.rb', line 68 def shell_eval(cmd_str) cmd = ShellCommand.extract(cmd_str) cmd.evaluate(self) end |