aro 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/Gemfile.lock +1 -1
  4. data/aro.gemspec +3 -3
  5. data/bin/aos +10 -3
  6. data/bin/aro +18 -11
  7. data/checksums/aro-0.2.3.gem.sha512 +1 -0
  8. data/locale/en.abot.yml +81 -0
  9. data/locale/en.aos.yml +6 -2
  10. data/locale/en.cor.yml +47 -0
  11. data/locale/en.data.yml +2 -2
  12. data/locale/en.dom.yml +15 -13
  13. data/locale/en.flie.yml +29 -0
  14. data/locale/en.usage.yml +24 -11
  15. data/locale/en.yml +2 -47
  16. data/sys/aos/abot.rb +256 -0
  17. data/sys/aos/aos.rb +373 -161
  18. data/sys/aos/cor.rb +773 -0
  19. data/sys/aos/data.rb +3 -3
  20. data/sys/aos/db/migrate/1765148774_create_yous.rb +1 -1
  21. data/sys/aos/db/migrate/1765933985_create_agodos.rb +22 -0
  22. data/sys/aos/db/migrate/1766203888_create_fpxies.rb +18 -0
  23. data/sys/aos/db.rb +16 -16
  24. data/sys/aos/flie.rb +144 -0
  25. data/sys/aos/models/agodo.rb +96 -0
  26. data/sys/aos/models/base_model.rb +13 -0
  27. data/sys/aos/models/fpxy.rb +28 -0
  28. data/sys/aos/models/ilib.rb +2 -0
  29. data/sys/aos/models/ilog.rb +5 -3
  30. data/sys/aos/models/you.rb +52 -4
  31. data/sys/aos/s.rb +2 -1
  32. data/sys/aos/vws/base.rb +62 -22
  33. data/sys/aos/vws/dom.rb +1 -1
  34. data/sys/aos/vws/games/abot.rb +21 -0
  35. data/sys/aos/vws/games/{game.rb → teck.rb} +19 -16
  36. data/sys/aos/vws/home.rb +23 -0
  37. data/sys/aos/vws/root/config.rb +4 -4
  38. data/sys/aos/vws/root/flie.rb +21 -0
  39. data/sys/aos/vws/welcome.rb +40 -4
  40. data/sys/aro/d.rb +4 -2
  41. data/sys/aro/db.rb +19 -10
  42. data/sys/aro/mancy.rb +16 -20
  43. data/sys/aro/models/base_model.rb +13 -0
  44. data/sys/aro/models/teck.rb +16 -12
  45. data/sys/aro/models/tlog.rb +2 -1
  46. data/sys/aro/p.rb +1 -1
  47. data/sys/aro/r.rb +2 -1
  48. data/sys/aro/v.rb +2 -2
  49. data/sys/cli/constants.rb +4 -10
  50. data/sys/cli/create.rb +2 -3
  51. data/sys/cli/dom.rb +1 -2
  52. data/sys/cli/teck.rb +26 -33
  53. data/sys/cli.rb +7 -9
  54. data/sys/dom/d.rb +38 -29
  55. data/sys/dom/dom.rb +62 -36
  56. data/sys/dom/p.rb +1 -1
  57. data/sys/fpx.rb +116 -0
  58. data/sys/reiquire.rb +3 -2
  59. data/sys/shr/prompt.rb +2 -2
  60. data/sys/shr/t.rb +11 -13
  61. data/sys/shr/version.rb +1 -1
  62. data/tasks/make.rake +1 -1
  63. metadata +55 -43
  64. data/sys/aos/vws/games/abpps.rb +0 -19
  65. data/sys/aos/vws/games/hbpps.rb +0 -19
  66. data/sys/aos/vws/games/shpps.rb +0 -19
  67. data/sys/aos/vws/games/vipps.rb +0 -19
  68. data/sys/dom/config.rb +0 -718
data/sys/aos/aos.rb CHANGED
@@ -26,11 +26,30 @@ module Aos
26
26
  Aos::Os::instance.process_cmd(cmd)
27
27
  end
28
28
 
29
+ def self.fpx
30
+ require_relative :"../fpx".to_s
31
+ if ARGV[Aro::Mancy::S].nil?
32
+ Aos::Fpx::Server.start
33
+ return
34
+ end
35
+
36
+ case ARGV[Aro::Mancy::S].to_sym
37
+ when :restart
38
+ Aos::Fpx::Server.stop
39
+ sleep(Aro::Mancy::S)
40
+ Aos::Fpx::Server.start
41
+ when :stop
42
+ Aos::Fpx::Server.stop
43
+ end
44
+ end
45
+
29
46
  class Os
30
47
  include Singleton
31
48
 
32
49
  attr_accessor :display_lines,
50
+ :q,
33
51
  :running,
52
+ :stream_pid,
34
53
  :view,
35
54
  :you,
36
55
  :you_flag
@@ -39,10 +58,18 @@ module Aos
39
58
  STAR = :"*"
40
59
  YOU = :you.to_s
41
60
  YOU_FLAG = :"--you".to_s
61
+ DB_POOL = Aro::Mancy::NUMERALS[:XLII]
42
62
  PS1 = :">[#{Aos::Os}]>: "
63
+ Q_PID = :"q.pid"
64
+ Q_UP = :"q.up"
43
65
  DATE_FORMAT = "%A %d %b %Y %I:%M:%S %p"
44
66
 
45
67
  CMDS = {
68
+ ABOT: {
69
+ key: :abot,
70
+ description: I18n.t("aos.commands.description.abot"),
71
+ usage: I18n.t("aos.commands.usage.abot"),
72
+ },
46
73
  AMG: {
47
74
  key: :amg,
48
75
  description: I18n.t("aos.commands.description.amg"),
@@ -53,10 +80,10 @@ module Aos
53
80
  description: I18n.t("aos.commands.description.cd"),
54
81
  usage: I18n.t("aos.commands.usage.cd"),
55
82
  },
56
- CONFIG: {
57
- key: :config,
58
- description: I18n.t("aos.commands.description.config"),
59
- usage: I18n.t("aos.commands.usage.config"),
83
+ COR: {
84
+ key: :cor,
85
+ description: I18n.t("aos.commands.description.cor"),
86
+ usage: I18n.t("aos.commands.usage.cor"),
60
87
  },
61
88
  DATA: {
62
89
  key: :data,
@@ -68,6 +95,11 @@ module Aos
68
95
  description: I18n.t("aos.commands.description.exit"),
69
96
  usage: I18n.t("aos.commands.usage.exit"),
70
97
  },
98
+ FLIE: {
99
+ key: :flie,
100
+ description: I18n.t("aos.commands.description.flie"),
101
+ usage: I18n.t("aos.commands.usage.flie"),
102
+ },
71
103
  HELP: {
72
104
  key: :help,
73
105
  description: I18n.t("aos.commands.description.help"),
@@ -93,7 +125,9 @@ module Aos
93
125
  def self.osify(path, leading_slash = false)
94
126
  return path unless Aro::Dom.in_arodom?
95
127
  path_arr = path.split("/")
96
- Aro::Dom::dom_root.split("/").each{|rdp| path_arr.delete(rdp)}
128
+ Aro::Dom::dom_root.split("/").each{|rdp|
129
+ path_arr.delete_at(path_arr.index(rdp)) unless path_arr.index(rdp).nil?
130
+ }
97
131
  result = path_arr.join("/")
98
132
  if leading_slash
99
133
  result = "/" + result
@@ -107,31 +141,25 @@ module Aos
107
141
  Aos::Os::CMDS.values.map{|v| v[:key]}.include?(arg.to_sym)
108
142
  end
109
143
 
110
- def self.you_flagd?
111
- self.instance.you_flag
112
- end
113
-
114
- def self.sanitize_you(cmd)
115
- if cmd.present? && cmd.include?(Aos::Os::YOU_FLAG)
116
- cmd_split = cmd.split(" ")
117
- i = cmd_split.index(Aos::Os::YOU_FLAG)
118
- cmd_split.delete_at(i)
119
- cmd_split.delete_at(i)
120
- cmd = cmd_split.join(" ")
144
+ def self.sanitize_you(args = [])
145
+ if args.any? && args.include?(Aos::Os::YOU_FLAG)
146
+ i = args.index(Aos::Os::YOU_FLAG)
147
+ args.delete_at(i)
148
+ args.delete_at(i)
121
149
  end
122
150
 
123
- cmd
151
+ args
152
+ end
153
+
154
+ def self.cron
155
+ Aos::Abot.cron
156
+ # ...
124
157
  end
125
158
 
126
159
  def initialize
127
- self.you_flag = false
128
- Aro::Config.instance.load
129
- # if Aro::Dom.in_arodom? && !Aro::Dom.is_initialized?
130
- # Aro::Dom.new.generate unless Aro::Mancy.in_aro?
131
- # end
132
160
  Aos::Db.load
133
161
  load_ilibs
134
- load_you
162
+ Aos::Abot.abot
135
163
  end
136
164
 
137
165
  def load_ilibs
@@ -144,39 +172,61 @@ module Aos
144
172
  Aos::Amg.load(:crs)
145
173
  end
146
174
 
147
- def load_you
148
- return if @you.present?
149
-
150
- if ARGV.include?(Aos::Os::YOU_FLAG)
151
- self.you_flag = true
152
- you_name = ARGV[ARGV.index(Aos::Os::YOU_FLAG) + Aro::Mancy::S]
153
- @you = Aos::You.find_by(name: you_name)
154
- if @you.nil?
155
- @you = Aos::You.create(name: you_name)
175
+ def self.you_name_from_flag_arg
176
+ yfi = ARGV.index(Aos::Os::YOU_FLAG)
177
+ return ARGV[yfi + Aro::Mancy::S]&.strip unless yfi.nil?
178
+ end
179
+
180
+ Mutex.new.synchronize do
181
+ def load_you!
182
+ self.you_flag = nil
183
+ self.you = Aos::You.find_by(access: :root)
184
+ if ARGV.include?(Aos::Os::YOU_FLAG)
185
+ you_name = Aos::Os.you_name_from_flag_arg
186
+ unless you_name == self.you.name
187
+ self.you = Aos::You.find_by(name: you_name)
188
+ if self.you.nil?
189
+ self.you = Aos::You.create(name: you_name)
190
+ self.you.reload
191
+ end
192
+ self.you_flag = self.you
193
+ end
156
194
  end
157
- else
158
- # todo: make more secure
159
- @you = Aos::You.find_by(access: :root)
195
+
196
+ Aro::V.say("you loaded:\n#{caller[Aro::Mancy::O..Aro::Mancy::N].join("\n")}")
197
+ Aro::V.say(self.you.name)
198
+ Aro::V.say(Aos::Os.osify(self.you.pwd))
160
199
  end
200
+ end
161
201
 
162
- self.display_lines = [Aos::Os.osify(@you.pwd, true)]
202
+ def load_you
203
+ return unless self.you_flag.nil?
204
+ load_you!
205
+ end
206
+
207
+ def get_pwd_for(you_name)
208
+ Aos::You.find_by(name: you_name)&.pwd
163
209
  end
164
210
 
165
211
  def load_view
166
- view_name = Aos::Os.osify(@you.pwd).split("/").last || :dom.to_s
212
+ view_name = Aos::Os.osify(self.you.pwd).split("/").last || :dom.to_s
167
213
  view_cls = nil
168
214
 
169
- cls_name = (Aos::Vw.name + "::#{view_name.capitalize}")
170
- Aro::D.say("attempting to load view class #{cls_name}")
171
- begin
172
- view_cls = cls_name.constantize
173
- rescue
174
- view_cls = Aos::Vw::Base
175
- end
215
+ if self.you.home?
216
+ view_cls = Aos::Vw::Home
217
+ else
218
+ cls_name = (Aos::Vw.name + "::#{view_name.capitalize}")
219
+ Aro::D.say("attempting to load view class #{cls_name}")
220
+ begin
221
+ view_cls = cls_name.constantize
222
+ rescue
223
+ view_cls = Aos::Vw::Base
224
+ end
176
225
 
177
- Dir.chdir(@you.pwd) do
178
- if Aro::Mancy.in_aro? && Aro::Mancy.is_initialized?
179
- view_cls = Aos::Vw::Game
226
+ Dir.chdir(self.you.pwd) do
227
+ if Aro::Mancy.in_aro? && Aro::Mancy.is_initialized?
228
+ view_cls = Aos::Vw::Teck
229
+ end
180
230
  end
181
231
  end
182
232
 
@@ -184,85 +234,216 @@ module Aos
184
234
  @view = view_cls
185
235
  end
186
236
 
187
- def render
188
- load_view
189
- return if @view.nil?
190
- Dir.chdir(@you.reload.pwd) do
191
- if Aro::Mancy.in_aro? && Aro::Mancy.is_initialized?
192
- system(:aro.to_s)
237
+ Mutex.new.synchronize do
238
+ def render
239
+ load_view
240
+ return if @view.nil?
241
+
242
+ Dir.chdir(self.you.reload.pwd) do
243
+ if Aro::Mancy.in_aro?
244
+ Aro::Mancy.init
245
+ if Aro::Mancy.is_initialized? && !Aro::Mancy.teck.nil?
246
+ Aro::Mancy.teck.show
247
+ end
248
+ else
249
+ @view.show
250
+ end
251
+ end
252
+ end
253
+ end
254
+
255
+ def self.q
256
+ self.instance.q
257
+ end
258
+
259
+ Mutex.new.synchronize do
260
+ def self.say(lines)
261
+ unless Aro::Dom.is_initialized?
262
+ Aos::S.say(lines.join("\n"))
263
+ return
264
+ end
265
+ Aos::Db.load
266
+ current_you = self.instance.you_flag || self.instance.you
267
+ lines = [lines] unless lines.kind_of?(Array)
268
+ if current_you.nil?
269
+ Aos::S.say(lines.join("\n"))
193
270
  else
194
- @view.show
271
+ # Mutex.new.synchronize do
272
+ Aos::Os.instance.q ||= {}
273
+ Aos::Os.q[current_you.name] ||= []
274
+ Aos::Os.q[current_you.name] += lines
275
+ # Aos::S.say("adding lines to #{current_you.name} (#{lines.count})")
276
+ # Aos::S.say("total: #{Aos::Os.q[current_you.name].count})")
277
+ # Aos::Os.streamq unless File.exist?(Aos::Os.q_pid_file)
278
+ Aos::Os.q.keys.each{|you_name|
279
+ current_you = Aos::You.find_by(
280
+ name: you_name
281
+ )
282
+ # Aos::S.say("streaming #{Aos::Os.q[you_name].count} lines to #{current_you.name}")
283
+ current_you.stream(
284
+ Aos::Os.q.delete(you_name)
285
+ )
286
+ }
287
+ # end
195
288
  end
196
289
  end
197
290
  end
198
291
 
292
+ # def self.streamq
293
+ # return unless !Aos::Cor.is_test? && self.instance.stream_pid.nil?
294
+ # puts self.instance.q.inspect
295
+ # Mutex.new.synchronize do
296
+ # self.instance.stream_pid = fork {
297
+ # loop do
298
+ # sleep(Aro::Mancy::OS)
299
+
300
+ # Aos::S.say("processing streamq #{self.instance.q.inspect}...")
301
+ # Aos::Db.load
302
+ # next if Aos::Os.q.nil?
303
+ # qdup = Aos::Os.q.keys.dup
304
+ # qdup.each{|you_name|
305
+ # current_you = Aos::You.find_by(
306
+ # name: you_name
307
+ # )
308
+ # Aos::S.say("streaming #{Aos::Os.q[you_name].count} lines to #{current_you.name}")
309
+ # current_you.stream(
310
+ # Aos::Os.q.delete(you_name)
311
+ # )
312
+ # }
313
+ # end
314
+ # }
315
+ # end
316
+ # Process.detach(self.instance.stream_pid)
317
+ # File.open(Aos::Os.q_pid_file, "w") do |f|
318
+ # f.write(self.instance.stream_pid)
319
+ # end
320
+ # end
321
+
322
+ # def self.q_pid_file
323
+ # File.join(Aos::Cor.dom_cor_path, Aos::Os::Q_PID.to_s)
324
+ # end
325
+
326
+ # def self.q_up_file
327
+ # File.join(Aos::Cor.dom_cor_path, Aos::Os::Q_UP.to_s)
328
+ # end
329
+
330
+ # def self.read_q_up
331
+ # # return unless Aro::Dom.is_initialized?
332
+ # # Aos::You.pluck(:name).each{|you_name|
333
+ # # q_up_file = Aos::Os.q_up_file_for_you(you_name)
334
+ # # if File.exist?(q_up_file)
335
+ # # self.instance.q[you_name] = JSON.parse(File.read(q_up_file))
336
+ # # end
337
+ # # }
338
+ # end
339
+
340
+ # def self.write_q_up
341
+ # self.instance.q.keys.each{|you_name|
342
+ # File.open(Aos::Os.q_up_file_for_you(you_name), "w") do |q_up|
343
+ # q_up.write(self.instance.q[you_name].to_json)
344
+ # end
345
+ # }
346
+ # end
347
+
348
+ # def self.q_up_file_for_you(you_name)
349
+ # "#{you_name}.#{Aos::Os.q_up_file}"
350
+ # end
351
+
352
+ # def self.terminateq
353
+ # qpf = Aos::Os.q_pid_file
354
+ # if File.exist?(qpf)
355
+ # system("kill -9 #{File.read(qpf)}")
356
+ # FileUtils.rm(qpf)
357
+ # # Aos::Os.write_q_up
358
+ # end
359
+ # end
360
+
361
+ def handle_aro_override(args)
362
+ return nil unless args[0].include?(:aro.to_s)
363
+ # !self.you_flag.nil?
364
+ yfi = args.index(Aos::Os::YOU_FLAG)
365
+ if yfi.nil?
366
+ args = "#{args.join(" ")} #{:aos.to_s} #{Aos::Os::YOU_FLAG} #{self.you.name}".split(" ")
367
+ else
368
+ args.insert(yfi, :aos.to_s)
369
+ end
370
+
371
+ `#{args.join(" ")}`
372
+ end
373
+
199
374
  def process_cmd(cmd)
200
- Dir.chdir(@you.reload.pwd) do
201
- configure_readline
375
+ # load config
376
+ Aos::Cor.instance.load
377
+ load_you!
378
+ Dir.chdir(self.you.reload.pwd) do
202
379
  send_to_system_call = main(cmd)
203
- if Aro::Config.is_format_text?
204
- # IO.console.goto(Aro::Mancy::O, Aro::Mancy::O)
205
- end
206
380
  nothing = nil
207
- if send_to_system_call
208
- nothing = system(cmd)
209
- Aos::S.say(nothing) if nothing.nil?
381
+ unless cmd.nil? || cmd.empty?
382
+ nothing = handle_aro_override(cmd.split(" "))
383
+ self.you.generate_ilog(cmd)
210
384
  end
211
-
212
- if nothing.nil?
213
- render
385
+ if send_to_system_call && nothing.nil?
386
+ nothing = `#{cmd}`
214
387
  end
215
388
 
216
- unless cmd.nil?
217
- @you.generate_ilog(cmd)
389
+ unless nothing.nil?
390
+ Aos::Os.say(nothing)
391
+ else
392
+ render
218
393
  end
219
394
  end
220
395
 
221
396
  CLI::EXIT_CODES[:SUCCESS]
222
397
  end
223
398
 
224
- def configure_readline
225
- # configure Readline
226
- Readline.completion_append_character = "/"
227
- Readline.completion_proc = Proc.new{|str|
228
- # Aro::V.say(str)
229
- dir_matcher = @you.pwd + "/" + str + Aos::Os::STAR.to_s
230
- dir_listing = Dir.glob(dir_matcher, File::FNM_DOTMATCH).map{|d| Aos::Os.osify(d)}
231
- r_str = Regexp.escape(str)
232
-
233
- # Aro::V.say(dir_listing.join(" ")) if dir_listing.any?
234
- # checks pwd
235
- matches = dir_listing.grep(/^#{r_str}/)
236
- if matches.any?
237
- matches
238
- else
239
- # checks reserved words
240
- Aro::Dom::D.reserved_words.grep(/^#{r_str}/)
241
- end
242
- }
399
+ def configure_readline(env)
400
+ # case env
401
+ # when :home
402
+ Readline.completion_append_character = "/"
403
+ Readline.completion_proc = Proc.new{|str|
404
+ pwd = self.you_flag&.reload&.pwd || self.you&.reload&.pwd || ""
405
+ dir_matcher = File.join(pwd, str + Aos::Os::STAR.to_s)
406
+ # Aro::V.say(dir_matcher)
407
+ dir_listing = Dir.glob(dir_matcher, File::FNM_DOTMATCH).map{|d| Aos::Os.osify(d).split("/").reject{|p| pwd.include?(p)}.join("/")}
408
+ # Aro::V.say(dir_listing)
409
+ dir_listing.grep(/^#{Regexp.escape(str)}/)
410
+ }
411
+ # when :aos
412
+ # Readline.completion_append_character = "/"
413
+ # Readline.completion_proc = Proc.new{|str|
414
+ # Aro::Dom::D.reserved_words.grep(/^#{Regexp.escape(str)}/)
415
+ # }
416
+ # end
243
417
  end
244
418
 
245
- def run
246
- # run condition
247
- @running = true
419
+ Mutex.new.synchronize do
420
+ def run
421
+ # run condition
422
+ self.running = true
423
+
424
+ # start cron
425
+ Aos::Os.cron
426
+
427
+ original_stdout = $stdout
428
+ $stdout = StringIO.open do |out|
429
+ cmd = nil
430
+
431
+ loop do
432
+ configure_readline :aos
433
+ break unless self.running && cmd = Readline.readline(calc_ps1)
434
+ IO.console.erase_screen(Aro::Mancy::S)
435
+ height, width = IO.console.winsize
436
+ IO.console.goto(height, Aro::Mancy::O)
437
+ process_cmd(cmd)
438
+ end
248
439
 
249
- original_stdout = $stdout
250
- $stdout = StringIO.open do |out|
251
- cmd = nil
252
- loop do
253
- # erase before cursor
254
- process_cmd(cmd)
255
- IO.console.goto(Aro::Config.display_configuration[:HEIGHT], Aro::Mancy::O)
256
- break unless @running && cmd = Readline.readline(calc_ps1, true)
257
- IO.console.erase_screen(Aro::Mancy::S)
440
+ out
258
441
  end
259
442
 
260
- out
443
+ CLI::EXIT_CODES[:SUCCESS]
444
+ ensure
445
+ $stdout = original_stdout
261
446
  end
262
-
263
- CLI::EXIT_CODES[:SUCCESS]
264
- ensure
265
- $stdout = original_stdout
266
447
  end
267
448
 
268
449
  def main(cmd)
@@ -270,43 +451,57 @@ module Aos
270
451
  return false if cmd.nil?
271
452
 
272
453
  # get args
273
- args = Aos::Os.sanitize_you(cmd).split(" ")
454
+ args = cmd.split(" ")
274
455
  return false if args[0].nil?
275
456
  return false if args[0] == :aos.to_s
276
457
 
277
- args = handle_aro_override(args)
458
+ # if self.you.home? && self.you.user?
459
+ # configure_readline :home
460
+ # self.display_lines = [`#{cmd}`]
461
+ # # render
462
+
463
+ # return false
464
+ # end
278
465
 
279
466
  # send to "system" call in process_cmd method
280
467
  # if args[Aro::Mancy::O] is not in Aos::Os::CMDS
281
- send_to_system_call = !Aos::Os.is_aos_command?(args[Aro::Mancy::O]) ||
282
- args.include?(:aos.to_s)
468
+ send_to_system_call = !Aos::Os.is_aos_command?(args[Aro::Mancy::O])
283
469
 
284
- # set aos pwd
470
+ # the command is valid
285
471
  unless send_to_system_call
286
- Dir.chdir(@you.pwd) do
472
+
473
+ Dir.chdir(self.you.pwd) do
287
474
  # process commands
288
475
  case args[Aro::Mancy::O].to_sym
476
+ when Aos::Os::CMDS[:ABOT][:key]
477
+ # abot
478
+ send_to_system_call = Aos::Abot.process_cmd(args)
289
479
  when Aos::Os::CMDS[:AMG][:key]
290
480
  # amg
291
- send_to_system_call = handle_amg(args)
481
+ send_to_system_call = Aos::Amg.process_cmd(args)
292
482
  when Aos::Os::CMDS[:CD][:key]
293
483
  # cd
294
484
  handle_cd(args)
295
- when Aos::Os::CMDS[:CONFIG][:key]
485
+ when Aos::Os::CMDS[:COR][:key]
296
486
  # config
297
- send_to_system_call = handle_config(args)
487
+ send_to_system_call = true
488
+ Aos::Cor.process_command(args)
298
489
  when Aos::Os::CMDS[:DATA][:key]
299
490
  # data
300
- send_to_system_call = handle_data(args)
491
+ send_to_system_call = Aos::Data.process_cmd(args)
301
492
  when Aos::Os::CMDS[:EXIT][:key]
302
493
  # exit
303
494
  send_to_system_call = true
304
495
  handle_exit(args)
496
+ when Aos::Os::CMDS[:FLIE][:key]
497
+ # amg
498
+ send_to_system_call = Aos::Flie.process_cmd(args)
305
499
  when Aos::Os::CMDS[:HELP][:key]
306
500
  # help
307
501
  send_to_system_call = handle_help(args)
308
502
  when Aos::Os::CMDS[:LL][:key]
309
503
  # ll
504
+ send_to_system_call = false
310
505
  handle_ll(args)
311
506
  when Aos::Os::CMDS[:LS][:key]
312
507
  # ls
@@ -340,104 +535,121 @@ module Aos
340
535
  end
341
536
 
342
537
  def calc_ps1
343
- you_pwd = Aos::Os::osify(@you.pwd)
344
- "#{Aos::Os::PS1}"
345
- end
346
-
347
- def handle_aro_override(args)
348
- if args[0].include?(:aro.to_s)
349
- args = "#{args.join(" ")} #{:aos.to_s}".split(" ")
350
- end
351
- args
352
- end
353
-
354
- def handle_config(args)
355
- Aro::Config.process_config_command(args)
356
- return true
538
+ self.you_flag.nil? ? Aos::Os::PS1.to_s : ">[#{self.you_flag.name}]>: "
357
539
  end
358
540
 
359
541
  def redirect_to_room(arg)
360
542
  # search for reserved room path
361
543
  handled = false
362
- room_path = Aro::Dom.room_path(arg)
363
- if !room_path.empty?
544
+ if arg.to_sym == Aro::Dom::COR
364
545
  handled = true
365
- @you.update(pwd: File.join(
366
- File.dirname(Aro::Dom.ethergeist_path),
367
- room_path
368
- ))
546
+ self.you.home!
547
+ else
548
+ room_path = Aro::Dom.room_path(arg)
549
+ if !self.you.root? &&
550
+ room_path.include?(Aro::Dom::ROOT.to_s)
551
+ self.display_lines = ["invalid access to #{room_path}. doing nothing."]
552
+ elsif !room_path.empty?
553
+ handled = true
554
+ if room_path == Aro::Dom::HOME.to_s
555
+ self.you.home!
556
+ else
557
+ Aro::D.say("#{__method__}#{Aos::Os::A}#{room_path}")
558
+ self.you.update(pwd: File.join(
559
+ Aro::Dom.dom_root,
560
+ room_path
561
+ ))
562
+ end
563
+ end
369
564
  end
370
565
  handled
371
566
  end
372
567
 
373
- def handle_amg(args)
374
- Aos::Amg.process_cmd(args)
375
- end
376
-
377
- def handle_data(args)
378
- Aos::Data.process_cmd(args)
379
- end
380
-
381
568
  def handle_help(args)
382
569
  redirect_to_room(Aro::Dom::WAITE)
383
570
  return false
384
571
  end
385
572
 
386
573
  def handle_ls(args)
387
- self.display_lines = [
388
- Dir.glob(File.join(@you.pwd, (args[1] || "") + Aos::Os::STAR.to_s), File::FNM_EXTGLOB).map{|p| "/" + Aos::Os::osify(p)}.join("\n")
389
- ]
574
+ args = Aos::Os.sanitize_you(args)
575
+ self.display_lines = [get_ls(args)]
576
+ end
577
+
578
+ def get_ls(args, split = false)
579
+ "\n" + Dir.glob(
580
+ File.join(
581
+ self.you.pwd,
582
+ (args[1] || "") + Aos::Os::STAR.to_s
583
+ ),
584
+ File::FNM_EXTGLOB
585
+ ).map{|p|
586
+ ">/" + Aos::Os::osify(p)
587
+ }.join("\n")
390
588
  end
391
589
 
392
590
  def handle_ll(args)
393
- self.display_lines = [
394
- Dir.glob(File.join(@you.pwd, (args[1] || "") + Aos::Os::STAR.to_s), File::FNM_DOTMATCH).map{|p| Aos::Os::osify(p.strip, true)}.join("\n")
395
- ]
591
+ args = Aos::Os.sanitize_you(args)
592
+ self.display_lines = [Dir.glob(File.join(self.you.pwd, (args[1] || "") + Aos::Os::STAR.to_s), File::FNM_DOTMATCH).map{|p| Aos::Os::osify(p.strip, true)}.join("\n")]
396
593
  end
397
594
 
398
595
  def handle_pwd(args)
399
- osified = "/" + Aos::Os::osify(@you.pwd)
596
+ osified = "/" + Aos::Os::osify(self.you.pwd)
400
597
  self.display_lines = [osified]
401
598
  end
402
599
 
403
600
  def handle_exit(args)
404
- Aos::S.say("#{Aos::Os} is exiting...")
405
- @running = false
601
+ Aos::Os.say(["#{Aos::Os} is exiting..."])
602
+ begin
603
+ Aos::Abot.terminate
604
+ Aos::Os.terminateq
605
+ rescue StandardError => e
606
+ Aro::D.say(e)
607
+ end
608
+ self.running = false
609
+ end
610
+
611
+ def handle_new_pwd(new_pwd)
612
+ if !you.root? &&
613
+ new_pwd.include?(Aro::Dom::ROOT.to_s)
614
+ self.display_lines = ["invalid access to #{Aos::Os.osify(new_pwd)}. doing nothing."]
615
+ elsif Aos::Os.osify(new_pwd) == Aro::Dom::HOME.to_s
616
+ self.you.home!
617
+ else
618
+ Aro::V.say("new_pwd: #{new_pwd}")
619
+ self.you.update(pwd: new_pwd)
620
+ end
406
621
  end
407
622
 
408
623
  def handle_cd(args)
624
+ args = Aos::Os.sanitize_you(args)
409
625
  if args[1].nil? || args[1] == "~/"
410
626
  # no arg takes you to arodom root
411
- @you.update(pwd: File.dirname(Aro::Dom.ethergeist_path))
627
+ self.you.update(pwd: File.dirname(Aro::Dom.ethergeist_path))
412
628
  else
413
629
  if args[1].include?(Aro::Dom::DOTT.to_s)
414
630
  # going up
415
- if File.dirname(Aro::Dom.ethergeist_path) == @you.pwd
631
+ if File.dirname(Aro::Dom.ethergeist_path) == self.you.pwd
416
632
  self.display_lines = ["within #{Aos::Os}, one cannot leave the #{Aro::Dom}."]
417
633
  else
418
634
  # todo: support dots in paths
419
635
  # this only supports moving one level up
420
636
 
421
- pwd_arr = @you.pwd.split("/")
637
+ pwd_arr = self.you.pwd.split("/")
422
638
  new_pwd = (pwd_arr.first(pwd_arr.length - 1)).join("/")
423
639
 
424
- @you.update(pwd: new_pwd)
640
+ handle_new_pwd(new_pwd)
425
641
  end
426
642
  else
427
643
  # this particular block needs to be better
428
644
  if args[1][0] == "/"
429
- Aro::V.say("handling cd to root (/) arg...")
430
- Aro::V.say(Aro::Dom::dom_root)
431
- Aro::V.say(args[1][1..])
432
645
  args[1] = args[1][1..]
433
646
  new_pwd = File.join(Aro::Dom.dom_root, args[1])
434
647
  if Dir.exist?(new_pwd)
435
- @you.update(pwd: new_pwd)
648
+ handle_new_pwd(new_pwd)
436
649
  end
437
650
  elsif Dir.exist?(args[1]) && args[1] != Aro::Dom::DOT.to_s
438
- new_pwd = File.join(@you.pwd, args[1])
439
- Aro::V.say("new_pwd: #{new_pwd}")
440
- @you.update(pwd: new_pwd)
651
+ new_pwd = File.join(self.you.pwd, args[1])
652
+ handle_new_pwd(new_pwd)
441
653
  else
442
654
  self.display_lines = ["that directory is invalid."]
443
655
  end