aro 0.2.1 → 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 (93) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/Gemfile.lock +1 -1
  4. data/README.md +1 -1
  5. data/aro.gemspec +3 -3
  6. data/bin/aos +10 -3
  7. data/bin/aro +18 -11
  8. data/checksums/aro-0.2.1.gem.sha512 +1 -0
  9. data/checksums/aro-0.2.2.gem.sha512 +1 -0
  10. data/checksums/aro-0.2.3.gem.sha512 +1 -0
  11. data/locale/en.abot.yml +81 -0
  12. data/locale/en.amg.yml +44 -0
  13. data/locale/en.aos.yml +8 -38
  14. data/locale/en.cor.yml +47 -0
  15. data/locale/en.data.yml +30 -0
  16. data/locale/en.dom.yml +22 -18
  17. data/locale/en.flie.yml +29 -0
  18. data/locale/en.usage.yml +39 -26
  19. data/locale/en.yml +10 -51
  20. data/sys/aos/abot.rb +256 -0
  21. data/sys/aos/amg.rb +58 -56
  22. data/sys/aos/aos.rb +425 -180
  23. data/sys/aos/cor.rb +773 -0
  24. data/sys/aos/data.rb +117 -0
  25. data/sys/aos/db/migrate/1765148774_create_yous.rb +1 -0
  26. data/sys/aos/db/migrate/{1765762724_create_libs.rb → 1765762724_create_ilibs.rb} +5 -5
  27. data/sys/aos/db/migrate/1765907766_create_ilogs.rb +18 -0
  28. data/sys/aos/db/migrate/1765933985_create_agodos.rb +22 -0
  29. data/sys/aos/db/migrate/1766203888_create_fpxies.rb +18 -0
  30. data/sys/aos/db.rb +47 -27
  31. data/sys/aos/flie.rb +144 -0
  32. data/sys/aos/models/agodo.rb +96 -0
  33. data/sys/aos/models/base_model.rb +13 -0
  34. data/sys/aos/models/fpxy.rb +28 -0
  35. data/sys/{shr/lib/lib.rb → aos/models/ilib.rb} +11 -6
  36. data/sys/aos/models/ilog.rb +29 -0
  37. data/sys/aos/models/you.rb +98 -0
  38. data/sys/aos/s.rb +2 -1
  39. data/sys/aos/vws/base.rb +69 -78
  40. data/sys/aos/vws/dom.rb +1 -2
  41. data/sys/aos/vws/games/abot.rb +21 -0
  42. data/sys/aos/vws/games/{game.rb → teck.rb} +27 -24
  43. data/sys/aos/vws/home.rb +23 -0
  44. data/sys/aos/vws/know/{temple.rb → body.rb} +3 -3
  45. data/sys/aos/vws/know/{library.rb → mind.rb} +3 -3
  46. data/sys/aos/vws/know/spirit.rb +19 -0
  47. data/sys/aos/vws/{setup → root}/amg.rb +1 -2
  48. data/sys/aos/vws/{setup → root}/config.rb +4 -4
  49. data/sys/aos/vws/root/data.rb +21 -0
  50. data/sys/aos/vws/root/flie.rb +21 -0
  51. data/sys/aos/vws/{setup.rb → root.rb} +3 -3
  52. data/sys/aos/vws/welcome/waite.rb +1 -0
  53. data/sys/aos/vws/welcome.rb +47 -0
  54. data/sys/aro/d.rb +4 -2
  55. data/sys/aro/db/migrate/{1763374647_create_decks.rb → 1763374647_create_tecks.rb} +5 -5
  56. data/sys/aro/db/migrate/1763432541_create_tlogs.rb +20 -0
  57. data/sys/aro/db.rb +28 -19
  58. data/sys/aro/mancy.rb +18 -22
  59. data/sys/aro/models/base_model.rb +13 -0
  60. data/sys/{models/deck.rb → aro/models/teck.rb} +60 -57
  61. data/sys/aro/models/tlog.rb +21 -0
  62. data/sys/aro/p.rb +1 -1
  63. data/sys/aro/r.rb +2 -1
  64. data/sys/aro/v.rb +2 -2
  65. data/sys/cli/constants.rb +4 -10
  66. data/sys/cli/create.rb +2 -3
  67. data/sys/cli/dom.rb +1 -2
  68. data/sys/cli/{deck.rb → teck.rb} +38 -45
  69. data/sys/cli.rb +10 -11
  70. data/sys/dom/d.rb +68 -46
  71. data/sys/dom/dom.rb +79 -44
  72. data/sys/dom/p.rb +1 -1
  73. data/sys/fpx.rb +116 -0
  74. data/sys/reiquire.rb +8 -8
  75. data/sys/shr/prompt.rb +2 -6
  76. data/sys/shr/t.rb +11 -13
  77. data/sys/shr/version.rb +1 -1
  78. data/tasks/make.rake +1 -1
  79. metadata +82 -62
  80. data/locale/en.cngelog.yml +0 -5
  81. data/sys/aos/vws/games/abpps.rb +0 -19
  82. data/sys/aos/vws/games/hbpps.rb +0 -19
  83. data/sys/aos/vws/games/shpps.rb +0 -19
  84. data/sys/aos/vws/games/vipps.rb +0 -19
  85. data/sys/aos/you.rb +0 -21
  86. data/sys/aro/db/migrate/1763432541_create_logs.rb +0 -20
  87. data/sys/dom/config.rb +0 -665
  88. data/sys/models/log.rb +0 -20
  89. /data/sys/shr/{lib → ilib}/crs/CMakeLists.txt +0 -0
  90. /data/sys/shr/{lib → ilib}/crs/compile.sh +0 -0
  91. /data/sys/shr/{lib → ilib}/crs/crs.c +0 -0
  92. /data/sys/shr/{lib → ilib}/crs/crs.o +0 -0
  93. /data/sys/shr/{lib → ilib}/crs/libcrs.so +0 -0
data/sys/aos/aos.rb CHANGED
@@ -26,19 +26,50 @@ 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
- attr_accessor :you, :libs, :running, :view, :db, :display_lines
49
+ attr_accessor :display_lines,
50
+ :q,
51
+ :running,
52
+ :stream_pid,
53
+ :view,
54
+ :you,
55
+ :you_flag
33
56
 
34
57
  A = :"@"
35
58
  STAR = :"*"
36
59
  YOU = :you.to_s
37
60
  YOU_FLAG = :"--you".to_s
61
+ DB_POOL = Aro::Mancy::NUMERALS[:XLII]
38
62
  PS1 = :">[#{Aos::Os}]>: "
63
+ Q_PID = :"q.pid"
64
+ Q_UP = :"q.up"
39
65
  DATE_FORMAT = "%A %d %b %Y %I:%M:%S %p"
40
66
 
41
67
  CMDS = {
68
+ ABOT: {
69
+ key: :abot,
70
+ description: I18n.t("aos.commands.description.abot"),
71
+ usage: I18n.t("aos.commands.usage.abot"),
72
+ },
42
73
  AMG: {
43
74
  key: :amg,
44
75
  description: I18n.t("aos.commands.description.amg"),
@@ -49,23 +80,26 @@ module Aos
49
80
  description: I18n.t("aos.commands.description.cd"),
50
81
  usage: I18n.t("aos.commands.usage.cd"),
51
82
  },
52
- CONFIG: {
53
- key: :config,
54
- description: I18n.t("aos.commands.description.config"),
55
- usage: I18n.t("aos.commands.usage.config"),
56
- cmds: {
57
- SET: {
58
- key: :set,
59
- description: I18n.t("aos.commands.description.config_set", prefix: Aro::Config::ARO_CONFIG_PREFIX),
60
- usage: I18n.t("aos.commands.usage.config_set"),
61
- }
62
- }
83
+ COR: {
84
+ key: :cor,
85
+ description: I18n.t("aos.commands.description.cor"),
86
+ usage: I18n.t("aos.commands.usage.cor"),
87
+ },
88
+ DATA: {
89
+ key: :data,
90
+ description: I18n.t("aos.commands.description.data"),
91
+ usage: I18n.t("aos.commands.usage.data"),
63
92
  },
64
93
  EXIT: {
65
94
  key: :exit,
66
95
  description: I18n.t("aos.commands.description.exit"),
67
96
  usage: I18n.t("aos.commands.usage.exit"),
68
97
  },
98
+ FLIE: {
99
+ key: :flie,
100
+ description: I18n.t("aos.commands.description.flie"),
101
+ usage: I18n.t("aos.commands.usage.flie"),
102
+ },
69
103
  HELP: {
70
104
  key: :help,
71
105
  description: I18n.t("aos.commands.description.help"),
@@ -91,7 +125,9 @@ module Aos
91
125
  def self.osify(path, leading_slash = false)
92
126
  return path unless Aro::Dom.in_arodom?
93
127
  path_arr = path.split("/")
94
- 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
+ }
95
131
  result = path_arr.join("/")
96
132
  if leading_slash
97
133
  result = "/" + result
@@ -102,72 +138,95 @@ module Aos
102
138
 
103
139
  def self.is_aos_command?(arg)
104
140
  # determine if command is Aos::Os::CMDS
105
- # passthrough to system if command is not in Aos::Os::CMDS
106
141
  Aos::Os::CMDS.values.map{|v| v[:key]}.include?(arg.to_sym)
107
142
  end
108
143
 
109
- def self.you_flagd?
110
- self.instance.you&.name != Aos::Os::YOU
111
- end
112
-
113
- def self.sanitize_you(cmd)
114
- if cmd.present? && cmd.include?(Aos::Os::YOU_FLAG)
115
- cmd_split = cmd.split(" ")
116
- i = cmd_split.index(Aos::Os::YOU_FLAG)
117
- cmd_split.delete_at(i)
118
- cmd_split.delete_at(i)
119
- 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)
120
149
  end
121
150
 
122
- cmd
151
+ args
152
+ end
153
+
154
+ def self.cron
155
+ Aos::Abot.cron
156
+ # ...
123
157
  end
124
158
 
125
159
  def initialize
126
- Aro::Config.instance.load
127
- if Aro::Dom.in_arodom? && !Aro::Dom.is_initialized?
128
- Aro::Dom.new.generate
129
- end
130
- @db = Aos::Db.new
131
- load_libs
132
- load_you
160
+ Aos::Db.load
161
+ load_ilibs
162
+ Aos::Abot.abot
133
163
  end
134
164
 
135
- def load_libs
136
- # todo: load from directory of libs.
165
+ def load_ilibs
166
+ # todo: load from directory of ilibs.
137
167
  # something like:
138
168
  #
139
- # Dir[lib_something_something].each do{|l| Aos::Lib.install(l)}
169
+ # Dir[lib_something_something].each do{|l| Aos::Ilib.install(l)}
140
170
 
141
171
  # for now static
142
172
  Aos::Amg.load(:crs)
143
173
  end
144
174
 
145
- def load_you
146
- return if @you.present?
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
147
179
 
148
- you_name = Aos::Os::YOU
149
- if ARGV.include?(Aos::Os::YOU_FLAG)
150
- you_name = ARGV[ARGV.index(Aos::Os::YOU_FLAG) + Aro::Mancy::S]
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
194
+ end
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))
151
199
  end
200
+ end
152
201
 
153
- @you = Aos::You.find_by(name: you_name)
154
- @you = Aos::You.create(name: you_name, pwd: Dir.pwd) if @you.nil?
202
+ def load_you
203
+ return unless self.you_flag.nil?
204
+ load_you!
205
+ end
155
206
 
156
- self.display_lines = [Aos::Os.osify(@you.pwd, true)]
207
+ def get_pwd_for(you_name)
208
+ Aos::You.find_by(name: you_name)&.pwd
157
209
  end
158
210
 
159
211
  def load_view
160
- 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
161
213
  view_cls = nil
162
- begin
163
- view_cls = (Aos::Vw.name + "::#{view_name.capitalize}").constantize
164
- rescue
165
- view_cls = Aos::Vw::Base
166
- end
167
214
 
168
- Dir.chdir(@you.pwd) do
169
- if Aro::Mancy.in_aro? && Aro::Mancy.is_initialized?
170
- view_cls = Aos::Vw::Game
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
225
+
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
171
230
  end
172
231
  end
173
232
 
@@ -175,32 +234,161 @@ module Aos
175
234
  @view = view_cls
176
235
  end
177
236
 
178
- def render
179
- load_view
180
- return if @view.nil?
181
- Dir.chdir(@you.reload.pwd) do
182
- if Aro::Mancy.in_aro? && Aro::Mancy.is_initialized?
183
- 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"))
184
270
  else
185
- @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
186
288
  end
187
289
  end
188
290
  end
189
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
+
190
374
  def process_cmd(cmd)
191
- Dir.chdir(@you.reload.pwd) do
192
- configure_readline
193
- passthrough = main(cmd)
194
- if Aro::Config.is_format_text?
195
- # IO.console.goto(Aro::Mancy::O, Aro::Mancy::O)
196
- end
375
+ # load config
376
+ Aos::Cor.instance.load
377
+ load_you!
378
+ Dir.chdir(self.you.reload.pwd) do
379
+ send_to_system_call = main(cmd)
197
380
  nothing = nil
198
- if passthrough
199
- nothing = system(cmd)
200
- 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)
384
+ end
385
+ if send_to_system_call && nothing.nil?
386
+ nothing = `#{cmd}`
201
387
  end
202
388
 
203
- if nothing.nil?
389
+ unless nothing.nil?
390
+ Aos::Os.say(nothing)
391
+ else
204
392
  render
205
393
  end
206
394
  end
@@ -208,48 +396,54 @@ module Aos
208
396
  CLI::EXIT_CODES[:SUCCESS]
209
397
  end
210
398
 
211
- def configure_readline
212
- # configure Readline
213
- Readline.completion_append_character = "/"
214
- Readline.completion_proc = Proc.new{|str|
215
- # Aro::V.say(str)
216
- dir_matcher = @you.pwd + "/" + str + Aos::Os::STAR.to_s
217
- dir_listing = Dir.glob(dir_matcher, File::FNM_DOTMATCH).map{|d| Aos::Os.osify(d)}
218
- r_str = Regexp.escape(str)
219
-
220
- # Aro::V.say(dir_listing.join(" ")) if dir_listing.any?
221
- # checks pwd
222
- matches = dir_listing.grep(/^#{r_str}/)
223
- if matches.any?
224
- matches
225
- else
226
- # checks reserved words
227
- Aro::Dom::D.reserved_words.grep(/^#{r_str}/)
228
- end
229
- }
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
230
417
  end
231
418
 
232
- def run
233
- # run condition
234
- @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
235
439
 
236
- original_stdout = $stdout
237
- $stdout = StringIO.open do |out|
238
- cmd = nil
239
- loop do
240
- # erase before cursor
241
- process_cmd(cmd)
242
- IO.console.goto(Aro::Config.display_configuration[:HEIGHT], Aro::Mancy::O)
243
- break unless @running && cmd = Readline.readline(calc_ps1, true)
244
- IO.console.erase_screen(Aro::Mancy::S)
440
+ out
245
441
  end
246
442
 
247
- out
443
+ CLI::EXIT_CODES[:SUCCESS]
444
+ ensure
445
+ $stdout = original_stdout
248
446
  end
249
-
250
- CLI::EXIT_CODES[:SUCCESS]
251
- ensure
252
- $stdout = original_stdout
253
447
  end
254
448
 
255
449
  def main(cmd)
@@ -257,154 +451,205 @@ module Aos
257
451
  return false if cmd.nil?
258
452
 
259
453
  # get args
260
- args = Aos::Os.sanitize_you(cmd).split(" ")
454
+ args = cmd.split(" ")
261
455
  return false if args[0].nil?
262
456
  return false if args[0] == :aos.to_s
263
457
 
264
- 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
465
+
466
+ # send to "system" call in process_cmd method
467
+ # if args[Aro::Mancy::O] is not in Aos::Os::CMDS
468
+ send_to_system_call = !Aos::Os.is_aos_command?(args[Aro::Mancy::O])
265
469
 
266
- passthrough = !Aos::Os.is_aos_command?(args[Aro::Mancy::O]) ||
267
- args.include?(:aos.to_s)
470
+ # the command is valid
471
+ unless send_to_system_call
268
472
 
269
- # set aos pwd
270
- unless passthrough
271
- Dir.chdir(@you.pwd) do
473
+ Dir.chdir(self.you.pwd) do
272
474
  # process commands
273
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)
274
479
  when Aos::Os::CMDS[:AMG][:key]
275
- # inst
276
- passthrough = handle_amg(args)
277
- when Aos::Os::CMDS[:CONFIG][:key]
480
+ # amg
481
+ send_to_system_call = Aos::Amg.process_cmd(args)
482
+ when Aos::Os::CMDS[:CD][:key]
483
+ # cd
484
+ handle_cd(args)
485
+ when Aos::Os::CMDS[:COR][:key]
278
486
  # config
279
- passthrough = handle_config(args)
280
- when Aos::Os::CMDS[:LS][:key]
281
- # ls
282
- handle_ls(args)
487
+ send_to_system_call = true
488
+ Aos::Cor.process_command(args)
489
+ when Aos::Os::CMDS[:DATA][:key]
490
+ # data
491
+ send_to_system_call = Aos::Data.process_cmd(args)
492
+ when Aos::Os::CMDS[:EXIT][:key]
493
+ # exit
494
+ send_to_system_call = true
495
+ handle_exit(args)
496
+ when Aos::Os::CMDS[:FLIE][:key]
497
+ # amg
498
+ send_to_system_call = Aos::Flie.process_cmd(args)
499
+ when Aos::Os::CMDS[:HELP][:key]
500
+ # help
501
+ send_to_system_call = handle_help(args)
283
502
  when Aos::Os::CMDS[:LL][:key]
284
503
  # ll
504
+ send_to_system_call = false
285
505
  handle_ll(args)
506
+ when Aos::Os::CMDS[:LS][:key]
507
+ # ls
508
+ handle_ls(args)
286
509
  when Aos::Os::CMDS[:PWD][:key]
287
510
  # pwd
288
511
  handle_pwd(args)
289
- when Aos::Os::CMDS[:EXIT][:key]
290
- # exit
291
- passthrough = true
292
- handle_exit(args)
293
- when Aos::Os::CMDS[:HELP][:key]
294
- # help
295
- passthrough = handle_help(args)
296
- when Aos::Os::CMDS[:CD][:key]
297
- # cd
298
- handle_cd(args)
299
512
  end
300
513
  end
301
514
  end
302
515
 
303
- # if system is going to run
304
- # but redirect happens
305
- # cancel system run
306
- if passthrough && redirect_to_room(args[Aro::Mancy::O])
307
- return false
516
+ if send_to_system_call
517
+ # process ilib commands
518
+ ilib = Aos::Ilib.find_by(
519
+ name: args[Aro::Mancy::O],
520
+ status: :installed
521
+ )
522
+ unless ilib.nil?
523
+ self.display_lines = [ilib.usage]
524
+ send_to_system_call = false
525
+ end
526
+
527
+ # if system is going to run, but redirect happens,
528
+ # cancel system run.
529
+ if redirect_to_room(args[Aro::Mancy::O])
530
+ send_to_system_call = false
531
+ end
308
532
  end
309
533
 
310
- return passthrough
534
+ return send_to_system_call
311
535
  end
312
536
 
313
537
  def calc_ps1
314
- you_pwd = Aos::Os::osify(@you.pwd)
315
- "#{Aos::Os::PS1}"
316
- end
317
-
318
- def handle_aro_override(args)
319
- if args[0].include?(:aro.to_s)
320
- args = "#{args.join(" ")} #{:aos.to_s}".split(" ")
321
- end
322
- args
323
- end
324
-
325
- def handle_config(args)
326
- Aro::Config.process_config_command(args)
327
- return true
538
+ self.you_flag.nil? ? Aos::Os::PS1.to_s : ">[#{self.you_flag.name}]>: "
328
539
  end
329
540
 
330
541
  def redirect_to_room(arg)
331
542
  # search for reserved room path
332
543
  handled = false
333
- room_path = Aro::Dom.room_path(arg)
334
- if !room_path.empty?
544
+ if arg.to_sym == Aro::Dom::COR
335
545
  handled = true
336
- @you.update(pwd: File.join(
337
- File.dirname(Aro::Dom.ethergeist_path),
338
- room_path
339
- ))
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
340
564
  end
341
565
  handled
342
566
  end
343
567
 
344
- def handle_amg(args)
345
- Aos::Amg.process_cmd(args)
346
- end
347
-
348
568
  def handle_help(args)
349
569
  redirect_to_room(Aro::Dom::WAITE)
350
570
  return false
351
571
  end
352
572
 
353
573
  def handle_ls(args)
354
- self.display_lines = [
355
- Dir.glob(File.join(@you.pwd, (args[1] || "") + Aos::Os::STAR.to_s), File::FNM_EXTGLOB).map{|p| "/" + Aos::Os::osify(p)}.join("\n")
356
- ]
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")
357
588
  end
358
589
 
359
590
  def handle_ll(args)
360
- self.display_lines = [
361
- 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")
362
- ]
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")]
363
593
  end
364
594
 
365
595
  def handle_pwd(args)
366
- osified = "/" + Aos::Os::osify(@you.pwd)
596
+ osified = "/" + Aos::Os::osify(self.you.pwd)
367
597
  self.display_lines = [osified]
368
598
  end
369
599
 
370
600
  def handle_exit(args)
371
- Aos::S.say("#{Aos::Os} is exiting...")
372
- @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
373
621
  end
374
622
 
375
623
  def handle_cd(args)
624
+ args = Aos::Os.sanitize_you(args)
376
625
  if args[1].nil? || args[1] == "~/"
377
626
  # no arg takes you to arodom root
378
- @you.update(pwd: File.dirname(Aro::Dom.ethergeist_path))
627
+ self.you.update(pwd: File.dirname(Aro::Dom.ethergeist_path))
379
628
  else
380
629
  if args[1].include?(Aro::Dom::DOTT.to_s)
381
630
  # going up
382
- if File.dirname(Aro::Dom.ethergeist_path) == @you.pwd
631
+ if File.dirname(Aro::Dom.ethergeist_path) == self.you.pwd
383
632
  self.display_lines = ["within #{Aos::Os}, one cannot leave the #{Aro::Dom}."]
384
633
  else
385
634
  # todo: support dots in paths
386
635
  # this only supports moving one level up
387
636
 
388
- pwd_arr = @you.pwd.split("/")
637
+ pwd_arr = self.you.pwd.split("/")
389
638
  new_pwd = (pwd_arr.first(pwd_arr.length - 1)).join("/")
390
639
 
391
- @you.update(pwd: new_pwd)
640
+ handle_new_pwd(new_pwd)
392
641
  end
393
642
  else
394
643
  # this particular block needs to be better
395
644
  if args[1][0] == "/"
396
- Aro::V.say("handling cd to root (/) arg...")
397
- Aro::V.say(Aro::Dom::dom_root)
398
- Aro::V.say(args[1][1..])
399
645
  args[1] = args[1][1..]
400
646
  new_pwd = File.join(Aro::Dom.dom_root, args[1])
401
647
  if Dir.exist?(new_pwd)
402
- @you.update(pwd: new_pwd)
648
+ handle_new_pwd(new_pwd)
403
649
  end
404
650
  elsif Dir.exist?(args[1]) && args[1] != Aro::Dom::DOT.to_s
405
- new_pwd = File.join(@you.pwd, args[1])
406
- Aro::V.say("new_pwd: #{new_pwd}")
407
- @you.update(pwd: new_pwd)
651
+ new_pwd = File.join(self.you.pwd, args[1])
652
+ handle_new_pwd(new_pwd)
408
653
  else
409
654
  self.display_lines = ["that directory is invalid."]
410
655
  end