Class: Exa::Shell

Inherits:
Object
  • Object
show all
Defined in:
lib/exa/shell.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#pwdObject (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

Yields:



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

#configurationObject



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

#pastelObject



97
98
99
# File 'lib/exa/shell.rb', line 97

def pastel
  @pastel ||= Pastel.new
end


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


91
92
93
94
95
# File 'lib/exa/shell.rb', line 91

def print_info(message)
  puts
  puts pastel.green(message)
  puts
end


85
86
87
88
89
# File 'lib/exa/shell.rb', line 85

def print_warning(message)
  puts
  puts pastel.red(message)
  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