Class: Ronin::Core::CLI::Shell
- Inherits:
-
Object
- Object
- Ronin::Core::CLI::Shell
- Includes:
- CommandKit::Colors, CommandKit::Printing, Banner
- Defined in:
- lib/ronin/core/cli/shell.rb
Overview
Base class for all interactive CLI shells.
Direct Known Subclasses
Constant Summary
Constants included from Banner
Instance Attribute Summary collapse
-
#prompt_sigil ⇒ String
readonly
The prompt sigil character (ex:
>
). -
#shell_name ⇒ String?
readonly
The shell's name.
Class Method Summary collapse
-
.prompt_sigil(new_sigil = nil) ⇒ String
The default prompt sigil.
-
.shell_name(new_name = nil) ⇒ String
The default shell prompt name.
-
.start(*arguments, **kwargs) ⇒ Object
Starts the shell and processes each line of input.
Instance Method Summary collapse
-
#complete(word, preposing) ⇒ Array<String>?
abstract
The partially input being tab completed.
-
#exec(line) ⇒ Object
abstract
Executes a command.
-
#initialize(shell_name: self.class.shell_name, prompt_sigil: self.class.prompt_sigil, **kwargs) ⇒ Shell
constructor
Initializes the shell instance.
-
#prompt ⇒ String
The shell prompt.
Methods included from Banner
Constructor Details
#initialize(shell_name: self.class.shell_name, prompt_sigil: self.class.prompt_sigil, **kwargs) ⇒ Shell
Initializes the shell instance.
164 165 166 167 168 169 170 171 |
# File 'lib/ronin/core/cli/shell.rb', line 164 def initialize(shell_name: self.class.shell_name, prompt_sigil: self.class.prompt_sigil, **kwargs) super(**kwargs) @shell_name = shell_name @prompt_sigil = prompt_sigil end |
Instance Attribute Details
#prompt_sigil ⇒ String (readonly)
The prompt sigil character (ex: >
).
153 154 155 |
# File 'lib/ronin/core/cli/shell.rb', line 153 def prompt_sigil @prompt_sigil end |
#shell_name ⇒ String? (readonly)
The shell's name.
148 149 150 |
# File 'lib/ronin/core/cli/shell.rb', line 148 def shell_name @shell_name end |
Class Method Details
.prompt_sigil(new_sigil = nil) ⇒ String
The default prompt sigil.
65 66 67 68 69 70 71 72 73 |
# File 'lib/ronin/core/cli/shell.rb', line 65 def self.prompt_sigil(new_sigil=nil) if new_sigil @prompt_sigil = new_sigil else @prompt_sigil ||= if superclass <= Shell superclass.prompt_sigil end end end |
.shell_name(new_name = nil) ⇒ String
The default shell prompt name.
46 47 48 49 50 51 52 53 54 |
# File 'lib/ronin/core/cli/shell.rb', line 46 def self.shell_name(new_name=nil) if new_name @shell_name = new_name else @shell_name ||= if superclass < Shell superclass.shell_name end end end |
.start(*arguments, **kwargs) ⇒ Object
Note:
The shell will exit if Ctrl^C
or Ctrl^D
is pressed.
Starts the shell and processes each line of input.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/ronin/core/cli/shell.rb', line 89 def self.start(*arguments,**kwargs) shell = new(*arguments,**kwargs) prev_completion_proc = Reline.completion_proc Reline.completion_proc = shell.method(:complete) shell. if shell.stdout.tty? begin loop do line = Reline.readline("#{shell.prompt} ", true) if line.nil? # Ctrl^D puts break end line.chomp! unless line.empty? begin shell.exec(line) rescue Interrupt # catch Ctrl^C but keep reading input rescue SystemExit break rescue => error shell.print_exception(error) end end end rescue Interrupt # catch Ctrl^C and return ensure Reline.completion_proc = prev_completion_proc end end |
Instance Method Details
#complete(word, preposing) ⇒ Array<String>?
This method is abstract.
The partially input being tab completed.
142 143 |
# File 'lib/ronin/core/cli/shell.rb', line 142 def complete(word,preposing) end |
#exec(line) ⇒ Object
This method is abstract.
Executes a command.
192 193 194 |
# File 'lib/ronin/core/cli/shell.rb', line 192 def exec(line) raise(NotImplementedError,"#{self.class}##{__method__} was not implemented") end |
#prompt ⇒ String
The shell prompt.
178 179 180 181 182 |
# File 'lib/ronin/core/cli/shell.rb', line 178 def prompt c = colors(stdout) "#{c.red(shell_name)}#{c.bold(c.bright_red(prompt_sigil))}" end |