Class: GamesAndRpgParadise::Lpc::Shell
- Inherits:
-
Base
- Object
- Base
- GamesAndRpgParadise::Lpc::Shell
show all
- Defined in:
- lib/games_and_rpg_paradise/lpc/shell/shell.rb
Constant Summary
collapse
- BASE_DIR =
'/home/x/data/rpg/muds/geas/'
- DEFAULT_PADDING =
' '
- PROMPT =
'> '
Base::Extensions::Colours::ARRAY_AVAILABLE_KONSOLE_COLOURS
CommonExtensions::CONTROL_C_CODE, CommonExtensions::N
Instance Method Summary
collapse
ecomment, #efancy, #eparse, #forestgreen, #gold, #grey, #lightblue, #mediumseagreen, #mediumslateblue, #peru, #rev, sdir, sfancy, #sfile, simp, #teal, #yellow
#commandline_arguments?, #filter_away_commandline_arguments, #first_argument?, #first_non_hyphened_argument?, #set_commandline_arguments
#cat, #cd, #cliner, #copy_file, #delete, #dirname_but_retains_the_trailing_slash, #disable_colours, #ensure_that_the_log_directory_exists, #esystem, #get_user_input, #infer_the_namespace, #is_on_roebe?, #log_dir?, #mkdir, #mkdir_then_cd_into_it, #mv, #namespace?, #opne, #opnn, #project_base_directory?, #project_image_directory?, #project_yaml_directory?, #rds, #remove_this_directory, #rename_file, #reset, #reset_the_internal_hash, #return_pwd, #return_today, #touch_file, #wrap, #write_what_into
Constructor Details
#initialize(run_already = true) ⇒ Shell
52
53
54
55
56
57
|
# File 'lib/games_and_rpg_paradise/lpc/shell/shell.rb', line 52
def initialize(
run_already = true
)
register_sigint
run if run_already
end
|
Instance Method Details
#display_file(i, default_padding = DEFAULT_PADDING) ⇒ Object
#
display_file
Display a file via this method.
#
120
121
122
123
124
125
126
|
# File 'lib/games_and_rpg_paradise/lpc/shell/shell.rb', line 120
def display_file(
i, default_padding = DEFAULT_PADDING
)
_ = File.readlines(i)
_ = _.map {|entry| default_padding+entry } e N+N+N+_.join
end
|
#do_lpc_search_for(i) ⇒ Object
#get_entry(i) ⇒ Object
138
139
140
141
142
|
# File 'lib/games_and_rpg_paradise/lpc/shell/shell.rb', line 138
def get_entry(i)
@file = @array_lpc_files[i - 1]
e @file
display_file(@file)
end
|
#is_readline_available? ⇒ Boolean
#
is_readline_available?
#
80
81
82
|
# File 'lib/games_and_rpg_paradise/lpc/shell/shell.rb', line 80
def is_readline_available?
READLINE_IS_AVAILABLE
end
|
#list_content ⇒ Object
131
132
133
|
# File 'lib/games_and_rpg_paradise/lpc/shell/shell.rb', line 131
def list_content
pp Dir['*']
end
|
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
# File 'lib/games_and_rpg_paradise/lpc/shell/shell.rb', line 147
def (
i = @user_input
)
case i
when 'help','hel','he','h','?'
show_help
when 'll',
'ls',
'lll'
list_content
when 'open'
open
when 'pwd'
e Dir.pwd
when 'padding?',
'padding'
e DEFAULT_PADDING.size
when 'quit',
'q',
'exit'
exit
else
if @user_input =~ /^\d+/
get_entry(@user_input.to_i)
end
if @user_input.include? ' '
splitted = @user_input.split ' '
@f = splitted[1] case splitted[0].to_s.downcase when 'open'
open(@f)
when 'cat','display'
display_file(@f)
when 'search','?','sea','src','lpc'
do_lpc_search_for(@f)
end
end
end
end
|
#obtain_all_lpc_rb_files ⇒ Object
#
obtain_all_lpc_rb_files
#
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/games_and_rpg_paradise/lpc/shell/shell.rb', line 102
def obtain_all_lpc_rb_files @array_lpc_files = Dir[
::GamesAndRpgParadise.project_base_directory?+'lpc/**.rb'
]
@array_lpc_files.each {|this_file|
e ' Loading file `'+simp(File.basename(this_file))+'` now.'
require this_file
}
end
|
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/games_and_rpg_paradise/lpc/shell/shell.rb', line 87
def obtain_user_input
loop {
if is_readline_available?
@user_input = Readline.readline(PROMPT)
else
ee PROMPT
@user_input = $stdin.gets.chomp
end
}
end
|
#open(_ = '/home/x/data/rpg/muds/geas/wizard/LPC_CODE_SHEET.md') ⇒ Object
233
234
235
236
237
|
# File 'lib/games_and_rpg_paradise/lpc/shell/shell.rb', line 233
def open(
_ = '/home/x/data/rpg/muds/geas/wizard/LPC_CODE_SHEET.md'
)
Open.in_editor(_)
end
|
#register_sigint ⇒ Object
62
63
64
|
# File 'lib/games_and_rpg_paradise/lpc/shell/shell.rb', line 62
def register_sigint
Signal.trap('SIGINT') { exit }
end
|
#run ⇒ Object
249
250
251
252
253
|
# File 'lib/games_and_rpg_paradise/lpc/shell/shell.rb', line 249
def run
obtain_all_lpc_rb_files
show_welcome_message
obtain_user_input
end
|
#show_help(i = @array_lpc_files) ⇒ Object
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
# File 'lib/games_and_rpg_paradise/lpc/shell/shell.rb', line 208
def show_help(
i = @array_lpc_files
)
i.each_with_index {|x, index|
index += 1; e '('+sfancy(index.to_s)+') '+x.to_s
}
e 'Also, you can use LPC Searching from the file '+LpcKnowledgeBase.file?+'.'
e
e 'For this, do '+sfancy('"search <keyword>"')+rev+'.'
e
e 'Example:'
e
e ' search druids'
e
end
|
#show_welcome_message ⇒ Object
69
70
71
72
73
74
75
|
# File 'lib/games_and_rpg_paradise/lpc/shell/shell.rb', line 69
def show_welcome_message
e rev+
'Welcome to the '+Colours.steelblue('LPC Shell')+'.'
e 'This shell just bundles together some LPC files and '\
'functionality'
e 'that may be useful for LPC-related activities.'
end
|