Class: GamesAndRpgParadise::Lpc::Shell

Inherits:
Base
  • Object
show all
Defined in:
lib/games_and_rpg_paradise/lpc/shell/shell.rb

Constant Summary collapse

BASE_DIR =
#

BASE_DIR

#
'/home/x/data/rpg/muds/geas/'
DEFAULT_PADDING =
#

DEFAULT_PADDING

#
'   '
PROMPT =
#

PROMPT

#
'> '

Constants included from Base::Extensions::Colours

Base::Extensions::Colours::ARRAY_AVAILABLE_KONSOLE_COLOURS

Constants included from CommonExtensions

CommonExtensions::CONTROL_C_CODE, CommonExtensions::N

Instance Method Summary collapse

Methods included from Base::Extensions::Colours

ecomment, #efancy, #eparse, #forestgreen, #gold, #grey, #lightblue, #mediumseagreen, #mediumslateblue, #peru, #rev, sdir, sfancy, #sfile, simp, #teal, #yellow

Methods included from Base::Extensions::CommandlineArguments

#commandline_arguments?, #filter_away_commandline_arguments, #first_argument?, #first_non_hyphened_argument?, #set_commandline_arguments

Methods included from CommonExtensions

#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

#

initialize

#


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 } # pad it
  e N+N+N+_.join
end

#do_lpc_search_for(i) ⇒ Object

#

do_lpc_search_for

#


242
243
244
# File 'lib/games_and_rpg_paradise/lpc/shell/shell.rb', line 242

def do_lpc_search_for(i)
  ::GamesAndRpgParadise::Lpc::KnowledgeBase.new(i)
end

#get_entry(i) ⇒ Object

#

get_entry

#


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?

#

Returns:

  • (Boolean)


80
81
82
# File 'lib/games_and_rpg_paradise/lpc/shell/shell.rb', line 80

def is_readline_available?
  READLINE_IS_AVAILABLE
end

#list_contentObject

#

list_content

#


131
132
133
# File 'lib/games_and_rpg_paradise/lpc/shell/shell.rb', line 131

def list_content
  pp Dir['*']
end
#

menu (menu tag)

#


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 menu(
    i = @user_input
  )
  case i
  # ======================================================================= #
  # === help
  # ======================================================================= #
  when 'help','hel','he','h','?'
    show_help
  # ======================================================================= #
  # === ll
  # ======================================================================= #
  when 'll',
       'ls',
       'lll'
    list_content
  # ======================================================================= #
  # === open
  # ======================================================================= #
  when 'open'
    open
  # ======================================================================= #
  # === pwd
  # ======================================================================= #
  when 'pwd'
    e Dir.pwd
  # ======================================================================= #
  # === padding?
  # ======================================================================= #
  when 'padding?',
       'padding'
    e DEFAULT_PADDING.size
  # ======================================================================= #
  # === quit
  # ======================================================================= #
  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] # @f is first_argument
      case splitted[0].to_s.downcase # case tag.
      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_filesObject

#

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 # obtain all .rb files in BASE_DIR
  @array_lpc_files = Dir[
    ::GamesAndRpgParadise.project_base_directory?+'lpc/**.rb'
  ]
  # ======================================================================= #
  # Require them next.
  # ======================================================================= #
  @array_lpc_files.each {|this_file|
    e '  Loading file `'+simp(File.basename(this_file))+'` now.'
    require this_file
  }
end

#obtain_user_inputObject

#

fetch_user_input

#


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
    menu
  }
end

#open(_ = '/home/x/data/rpg/muds/geas/wizard/LPC_CODE_SHEET.md') ⇒ Object

#

open

#


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_sigintObject

#

register_sigint

#


62
63
64
# File 'lib/games_and_rpg_paradise/lpc/shell/shell.rb', line 62

def register_sigint
  Signal.trap('SIGINT') { exit }
end

#runObject

#

run (run tag)

#


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

#

show_help (help tag)

#


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
  )
  # ======================================================================= #
  # We iterate over the 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_messageObject

#

show_welcome_message

#


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