Class: UniversalPipeHandler::Shell
- Inherits:
-
Base
- Object
- Base
- UniversalPipeHandler::Shell
show all
- Defined in:
- lib/universal_pipe_handler/shell/shell.rb
Overview
UniversalPipeHandler::Shell
Constant Summary
collapse
- NAMESPACE =
inspect
Class Method Summary
collapse
-
.[](i = '') ⇒ Object
# === UniversalPipeHandler::Shell[] ========================================================================= #.
Instance Method Summary
collapse
Methods inherited from Base
#allowed_actions?, #chdir, #commandline_arguments?, #copy, #first_argument?, #mkdir, #register_sigint, #remove_quotes, #return_pwd, #set_commandline_arguments
Constructor Details
#initialize(commandline_arguments = ARGV, run_already = true) ⇒ Shell
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/universal_pipe_handler/shell/shell.rb', line 34
def initialize(
commandline_arguments = ARGV,
run_already = true
)
register_sigint
consider_enabling_readline_support
reset
set_commandline_arguments(
commandline_arguments
)
run if run_already
end
|
Class Method Details
.[](i = '') ⇒ Object
#
UniversalPipeHandler::Shell[]
#
248
249
250
|
# File 'lib/universal_pipe_handler/shell/shell.rb', line 248
def self.[](i = '')
new(i)
end
|
Instance Method Details
#consider_enabling_readline_support ⇒ Object
#
consider_enabling_readline_support
We will enable readline support, if it is available.
The registered actions are part of the sanitize_pipe project.
#
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/universal_pipe_handler/shell/shell.rb', line 76
def consider_enabling_readline_support
if readline_is_available?
Readline.completion_append_character = ' '
completion_proc = proc { |input|
input = input.to_s.strip
aliases = all_aliases
aliases.grep(/^#{input}/)
}
Readline.completion_proc = completion_proc
else
e 'No support for Readline is available.'
end
end
|
#enter_the_main_loop ⇒ Object
#
enter_the_main_loop (loop tag)
#
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
# File 'lib/universal_pipe_handler/shell/shell.rb', line 108
def enter_the_main_loop
loop {
_ = fetch_user_input
case _ when 'aliases?'
show_all_aliases
when 'value?',
'result?'
show_last_return_value
when 'test1'
_ = 'all images | resize 25%'
set_user_input(_)
when 'test2'
_ = 'ls | camelCase'
set_user_input(_)
when 'quit',
'q',
'exit',
'd',
'x'
verbose_exit
end
if _.include? '|' evaluate_this_pipe_instruction(_)
else if _.empty?
e
else
e rev+'The instruction '+
::Colours.steelblue(_)+
' is not registered or understood.'
end
end
}
end
|
#evaluate_this_pipe_instruction(i) ⇒ Object
Also known as:
test
#
evaluate_this_pipe_instruction
Usage example:
ls | camelCase
#
229
230
231
232
233
234
235
|
# File 'lib/universal_pipe_handler/shell/shell.rb', line 229
def evaluate_this_pipe_instruction(i)
i = i.to_s.dup
e tomato("Debug: `#{i}` in evaluate_this_pipe_instruction")
result = UniversalPipeHandler::CmdletsHandler.new(i)
@last_result = result.result?
end
|
170
171
172
173
174
175
176
177
|
# File 'lib/universal_pipe_handler/shell/shell.rb', line 170
def fetch_user_input
if readline_is_available?
set_user_input(Readline.readline('', true))
else
set_user_input($stdin.gets.chomp)
end
return @user_input
end
|
#is_readline_available? ⇒ Boolean
Also known as:
readline_is_available?
#
is_readline_available?
#
65
66
67
|
# File 'lib/universal_pipe_handler/shell/shell.rb', line 65
def is_readline_available?
return Object.const_defined? :Readline
end
|
#reset ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/universal_pipe_handler/shell/shell.rb', line 50
def reset
super()
@namespace = NAMESPACE
@last_result = nil
end
|
#run ⇒ Object
240
241
242
243
|
# File 'lib/universal_pipe_handler/shell/shell.rb', line 240
def run
show_startup_message
enter_the_main_loop
end
|
182
183
184
|
# File 'lib/universal_pipe_handler/shell/shell.rb', line 182
def set_user_input(i)
@user_input = i
end
|
#show_all_aliases ⇒ Object
94
95
96
|
# File 'lib/universal_pipe_handler/shell/shell.rb', line 94
def show_all_aliases
pp UniversalPipeHandler.pipe_aliases?.keys.sort
end
|
#show_last_return_value ⇒ Object
#
show_last_return_value
#
101
102
103
|
# File 'lib/universal_pipe_handler/shell/shell.rb', line 101
def show_last_return_value
e @last_result
end
|
#show_startup_message ⇒ Object
211
212
213
214
215
216
217
218
219
|
# File 'lib/universal_pipe_handler/shell/shell.rb', line 211
def show_startup_message
e ::Colours.rev+
'Welcome to the interactive Shell for the '+
::Colours.steelblue('UniversalPipeHandler')+
' project.'
e
e silver('Input your pipe-instruction next to see it be evaluated:')
e
end
|
#silver(i) ⇒ Object
204
205
206
|
# File 'lib/universal_pipe_handler/shell/shell.rb', line 204
def silver(i)
::Colours.silver(i)
end
|
189
190
191
|
# File 'lib/universal_pipe_handler/shell/shell.rb', line 189
def user_input?
@user_input.to_s.strip
end
|
#verbose_exit ⇒ Object
196
197
198
199
|
# File 'lib/universal_pipe_handler/shell/shell.rb', line 196
def verbose_exit
e 'Bye.'
exit
end
|