aro 0.1.7 → 0.1.9
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.
- checksums.yaml +4 -4
- data/aro.gemspec +3 -3
- data/bin/aos +24 -0
- data/bin/aro +5 -2
- data/checksums/aro-0.1.7.gem.sha512 +1 -0
- data/checksums/aro-0.1.8.gem.sha512 +1 -0
- data/checksums/aro-0.1.9.gem.sha512 +1 -0
- data/db/migrate/1763374647_create_decks.rb +5 -2
- data/db/migrate/1763432541_create_logs.rb +1 -0
- data/db/migrate/1765148774_create_yous.rb +19 -0
- data/listen.rb +1 -1
- data/locale/en.aos.yml +31 -0
- data/locale/en.cngelog.yml +5 -0
- data/locale/en.dom.yml +42 -0
- data/locale/en.usage.yml +23 -13
- data/locale/en.yml +43 -34
- data/sys/aos/aos.rb +282 -0
- data/sys/aos/db.rb +80 -0
- data/sys/aos/s.rb +25 -0
- data/sys/aos/views/base.rb +155 -0
- data/sys/aos/views/dom.rb +36 -0
- data/sys/aos/views/games/abpps.rb +21 -0
- data/sys/aos/views/games/game.rb +114 -0
- data/sys/aos/views/games/hbpps.rb +21 -0
- data/sys/aos/views/games/shpps.rb +21 -0
- data/sys/aos/views/games/vipps.rb +21 -0
- data/sys/aos/views/games.rb +19 -0
- data/sys/aos/views/know/library.rb +19 -0
- data/sys/aos/views/know/temple.rb +19 -0
- data/sys/aos/views/know.rb +19 -0
- data/sys/aos/views/setup/settings.rb +37 -0
- data/sys/aos/views/setup.rb +19 -0
- data/sys/aos/views/welcome/waite.rb +19 -0
- data/sys/aos/views/welcome/winner.rb +19 -0
- data/sys/aos/views/welcome.rb +19 -0
- data/sys/aos/you.rb +19 -0
- data/sys/aro/d.rb +1 -1
- data/sys/aro/db.rb +5 -13
- data/sys/aro/mancy.rb +23 -19
- data/sys/aro/p.rb +2 -2
- data/sys/aro/v.rb +2 -3
- data/sys/aro.rb +1 -0
- data/sys/cli/config.rb +244 -123
- data/sys/cli/constants.rb +8 -5
- data/sys/cli/deck.rb +13 -8
- data/sys/cli/dom.rb +16 -17
- data/sys/cli/nterface.rb +6 -0
- data/sys/dom/d.rb +24 -19
- data/sys/dom/dom.rb +74 -96
- data/sys/dom/p.rb +1 -1
- data/sys/models/deck.rb +23 -13
- data/sys/models/log.rb +12 -2
- data/sys/reiquire.rb +3 -2
- data/sys/shr/prompt.rb +12 -4
- data/sys/shr/t.rb +12 -10
- data/sys/shr/version.rb +4 -4
- metadata +52 -27
- data/sys/views/base.rb +0 -29
- data/sys/views/dom.rb +0 -27
- data/sys/views/games/deck.rb +0 -97
- data/sys/views/games/menu.rb +0 -27
- data/sys/views/setup/setup.rb +0 -27
data/sys/aos/aos.rb
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
|
|
3
|
+
aos.rb
|
|
4
|
+
|
|
5
|
+
aos.
|
|
6
|
+
|
|
7
|
+
by i2097i
|
|
8
|
+
|
|
9
|
+
=end
|
|
10
|
+
|
|
11
|
+
require :aro.to_s
|
|
12
|
+
|
|
13
|
+
module Aos
|
|
14
|
+
|
|
15
|
+
def self.run
|
|
16
|
+
Aos::Db.new
|
|
17
|
+
Aos::Os::boot(Aos::you)
|
|
18
|
+
begin
|
|
19
|
+
Aos::Os.instance.run
|
|
20
|
+
rescue Interrupt => e
|
|
21
|
+
Aos::run
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.watch
|
|
26
|
+
Aos::Db.new
|
|
27
|
+
Aos::Os::boot(Aos::you)
|
|
28
|
+
Aos::Os::instance.render
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def self.you
|
|
32
|
+
you = Aos::You.where(name: :you).first
|
|
33
|
+
you = Aos::You.create(name: :you, pwd: Dir.pwd) if you.nil?
|
|
34
|
+
you
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
class Os
|
|
38
|
+
include Singleton
|
|
39
|
+
|
|
40
|
+
attr_accessor :you, :running, :view
|
|
41
|
+
|
|
42
|
+
A = :"@"
|
|
43
|
+
STAR = :"*"
|
|
44
|
+
PS1 = :">[#{Aos::Os}]>: "
|
|
45
|
+
DATE_FORMAT = "%A %d %b %Y %I:%M:%S %p"
|
|
46
|
+
|
|
47
|
+
CMDS = {
|
|
48
|
+
CD: {
|
|
49
|
+
key: :cd,
|
|
50
|
+
description: I18n.t("aos.commands.description.cd"),
|
|
51
|
+
usage: I18n.t("aos.commands.usage.cd"),
|
|
52
|
+
},
|
|
53
|
+
CONFIG: {
|
|
54
|
+
key: :config,
|
|
55
|
+
description: I18n.t("aos.commands.description.config"),
|
|
56
|
+
usage: I18n.t("aos.commands.usage.config"),
|
|
57
|
+
cmds: {
|
|
58
|
+
SET: {
|
|
59
|
+
key: :set,
|
|
60
|
+
description: I18n.t("aos.commands.description.config_set", prefix: CLI::Config::ARO_CONFIG_PREFIX),
|
|
61
|
+
usage: I18n.t("aos.commands.usage.config_set"),
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
EXIT: {
|
|
66
|
+
key: :exit,
|
|
67
|
+
description: I18n.t("aos.commands.description.exit"),
|
|
68
|
+
usage: I18n.t("aos.commands.usage.exit"),
|
|
69
|
+
},
|
|
70
|
+
LS: {
|
|
71
|
+
key: :ls,
|
|
72
|
+
description: I18n.t("aos.commands.description.ls"),
|
|
73
|
+
usage: I18n.t("aos.commands.usage.ls"),
|
|
74
|
+
},
|
|
75
|
+
LL: {
|
|
76
|
+
key: :ll,
|
|
77
|
+
description: I18n.t("aos.commands.description.ll"),
|
|
78
|
+
usage: I18n.t("aos.commands.usage.ll"),
|
|
79
|
+
},
|
|
80
|
+
PWD: {
|
|
81
|
+
key: :pwd,
|
|
82
|
+
description: I18n.t("aos.commands.description.pwd"),
|
|
83
|
+
usage: I18n.t("aos.commands.usage.pwd"),
|
|
84
|
+
},
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
def self.boot(you)
|
|
88
|
+
self.instance.you = you
|
|
89
|
+
self.instance.load_view
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def render
|
|
93
|
+
return if view.nil?
|
|
94
|
+
Dir.chdir(you.pwd) do
|
|
95
|
+
view.show(you)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def run
|
|
100
|
+
# run loop exit condition
|
|
101
|
+
self.running = true
|
|
102
|
+
|
|
103
|
+
# set aos pwd
|
|
104
|
+
Dir.chdir(you.pwd)
|
|
105
|
+
|
|
106
|
+
# configure Readline
|
|
107
|
+
# Readline.completion_append_character = "/"
|
|
108
|
+
Readline.completion_proc = Proc.new{|str|
|
|
109
|
+
# todo: the reserved_words search is working but the || case is not
|
|
110
|
+
Aro::Dom::D.reserved_words.grep(/^#{Regexp.escape(str)}/) ||
|
|
111
|
+
Dir[Dir.pwd + str + Aos::Os::STAR.to_s].grep(/^#{Regexp.escape(str)}/)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
# begin game loop
|
|
115
|
+
while running && cmd = Readline.readline(calc_ps1, true)
|
|
116
|
+
next if cmd.nil?
|
|
117
|
+
|
|
118
|
+
# get args
|
|
119
|
+
args = cmd.split(" ")
|
|
120
|
+
|
|
121
|
+
next if handle_room_path(args[Aro::Mancy::O]) || handle_aro_override(args)
|
|
122
|
+
|
|
123
|
+
passthrough = !is_aos_command?(args[Aro::Mancy::O])
|
|
124
|
+
|
|
125
|
+
# process commands
|
|
126
|
+
case args[Aro::Mancy::O].to_sym
|
|
127
|
+
when Aos::Os::CMDS[:CONFIG][:key]
|
|
128
|
+
# config
|
|
129
|
+
handle_config(args)
|
|
130
|
+
when Aos::Os::CMDS[:LS][:key]
|
|
131
|
+
# ls
|
|
132
|
+
handle_ls(args)
|
|
133
|
+
when Aos::Os::CMDS[:LL][:key]
|
|
134
|
+
# ll
|
|
135
|
+
handle_ll(args)
|
|
136
|
+
when Aos::Os::CMDS[:PWD][:key]
|
|
137
|
+
# pwd
|
|
138
|
+
handle_pwd(args)
|
|
139
|
+
when Aos::Os::CMDS[:EXIT][:key]
|
|
140
|
+
# exit
|
|
141
|
+
handle_exit(args)
|
|
142
|
+
when Aos::Os::CMDS[:CD][:key]
|
|
143
|
+
# cd
|
|
144
|
+
handle_cd(args)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
Aos::S.say(system(cmd)) if passthrough
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
CLI::EXIT_CODES[:SUCCESS]
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def load_view
|
|
154
|
+
view_name = Aos::Os.osify(you.pwd).split("/").last || :dom.to_s
|
|
155
|
+
view_cls = nil
|
|
156
|
+
begin
|
|
157
|
+
view_cls = (Aos::Vi.name + "::#{view_name.capitalize}").constantize
|
|
158
|
+
rescue
|
|
159
|
+
view_cls = Aos::Vi::Base
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
Aro::D.say("loading view #{view_cls}")
|
|
163
|
+
self.view = view_cls
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def calc_ps1
|
|
167
|
+
you_pwd = Aos::Os::osify(you.pwd)
|
|
168
|
+
"#{Aos::Os::PS1}#{you_pwd.empty? ? "" : "#{you_pwd}:"}$ "
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
def self.osify(path)
|
|
172
|
+
return path unless Aro::Dom.in_arodom?
|
|
173
|
+
path_arr = path.split("/")
|
|
174
|
+
Aro::Dom::dom_root.split("/").each{|rdp| path_arr.delete(rdp)}
|
|
175
|
+
path_arr.join("/")
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
def is_aos_command?(arg)
|
|
179
|
+
# determine if command is Aos::Os::CMDS
|
|
180
|
+
# passthrough to system if command is not in Aos::Os::CMDS
|
|
181
|
+
Aos::Os::CMDS.values.map{|v| v[:key]}.include?(arg.to_sym)
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
def handle_room_path(arg)
|
|
185
|
+
# search for reserved room path
|
|
186
|
+
handled = false
|
|
187
|
+
room_path = Aro::Dom.room_path(arg)
|
|
188
|
+
if !room_path.empty?
|
|
189
|
+
handled = true
|
|
190
|
+
you.update(pwd: File.join(
|
|
191
|
+
File.dirname(Aro::Dom.ethergeist_path),
|
|
192
|
+
room_path
|
|
193
|
+
))
|
|
194
|
+
end
|
|
195
|
+
handled
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
def handle_aro_override(args)
|
|
199
|
+
# run all aro commands in aos context
|
|
200
|
+
handled = false
|
|
201
|
+
if args[0].include?(:aro.to_s)
|
|
202
|
+
# passthrough aro cmd with aos appended
|
|
203
|
+
handled = true
|
|
204
|
+
system("#{args.join(" ")} #{:aos.to_s}")
|
|
205
|
+
end
|
|
206
|
+
handled
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
def handle_config(args)
|
|
210
|
+
if args[1].nil?
|
|
211
|
+
# show settings
|
|
212
|
+
you.update(pwd:
|
|
213
|
+
File.join(
|
|
214
|
+
File.dirname(Aro::Dom.ethergeist_path),
|
|
215
|
+
Aro::Dom::SETUP.to_s,
|
|
216
|
+
Aro::Dom::SETTINGS.to_s
|
|
217
|
+
)
|
|
218
|
+
)
|
|
219
|
+
else
|
|
220
|
+
CLI::Config.process_config_command(args)
|
|
221
|
+
end
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
def handle_ls(args)
|
|
225
|
+
Aos::S.say(Dir[File.join(Dir.pwd, (args[1] || "") + Aos::Os::STAR.to_s)].map{|p| "/" + Aos::Os::osify(p)}.join("\n"))
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
def handle_ll(args)
|
|
229
|
+
Aos::S.say(Dir.glob(File.join(Dir.pwd, (args[1] || "") + Aos::Os::STAR.to_s), File::FNM_DOTMATCH).map{|p| "/" + Aos::Os::osify(p)}.join("\n"))
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
def handle_pwd(args)
|
|
233
|
+
osified = "/" + Aos::Os::osify(you.pwd)
|
|
234
|
+
Aos::S.say(osified)
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
def handle_exit(args)
|
|
238
|
+
Aos::S.say("#{Aos::Os} is exiting...")
|
|
239
|
+
self.running = false
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
def handle_cd(args)
|
|
243
|
+
if args[1].nil? || args[1] == "~/"
|
|
244
|
+
# no arg takes you to arodom root
|
|
245
|
+
you.update(pwd: File.dirname(Aro::Dom.ethergeist_path))
|
|
246
|
+
else
|
|
247
|
+
if args[1].include?(Aro::Dom::DOTT.to_s)
|
|
248
|
+
# going up
|
|
249
|
+
if File.dirname(Aro::Dom.ethergeist_path) == you.pwd
|
|
250
|
+
Aos::S.say("within #{Aos::Os}, one cannot leave the #{Aro::Dom}.")
|
|
251
|
+
else
|
|
252
|
+
# todo: support dots in paths
|
|
253
|
+
# this only supports moving one level up
|
|
254
|
+
|
|
255
|
+
pwd_arr = you.pwd.split("/")
|
|
256
|
+
new_pwd = (pwd_arr.first(pwd_arr.length - 1)).join("/")
|
|
257
|
+
|
|
258
|
+
you.update(pwd: new_pwd)
|
|
259
|
+
end
|
|
260
|
+
else
|
|
261
|
+
# this particular block needs to be better
|
|
262
|
+
if args[1][0] == "/"
|
|
263
|
+
Aro::V.say("handling cd to root (/) arg...")
|
|
264
|
+
Aro::V.say(Aro::Dom::dom_root)
|
|
265
|
+
Aro::V.say(args[1][1..])
|
|
266
|
+
args[1] = args[1][1..]
|
|
267
|
+
new_pwd = File.join(Aro::Dom.dom_root, args[1])
|
|
268
|
+
if Dir.exist?(new_pwd)
|
|
269
|
+
you.update(pwd: new_pwd)
|
|
270
|
+
end
|
|
271
|
+
elsif Dir.exist?(args[1]) && args[1] != Aro::Dom::DOT.to_s
|
|
272
|
+
new_pwd = File.join(you.pwd, args[1])
|
|
273
|
+
Aro::V.say("new_pwd: #{new_pwd}")
|
|
274
|
+
you.update(pwd: new_pwd)
|
|
275
|
+
else
|
|
276
|
+
Aos::S.say("that directory is invalid.")
|
|
277
|
+
end
|
|
278
|
+
end
|
|
279
|
+
end
|
|
280
|
+
end
|
|
281
|
+
end
|
|
282
|
+
end
|
data/sys/aos/db.rb
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
|
|
3
|
+
db.rb
|
|
4
|
+
|
|
5
|
+
database for aos room.
|
|
6
|
+
|
|
7
|
+
by i2097i
|
|
8
|
+
|
|
9
|
+
=end
|
|
10
|
+
|
|
11
|
+
module Aos
|
|
12
|
+
class Db < Aro::Db
|
|
13
|
+
DATABASE_YML = :"database.yml"
|
|
14
|
+
SQL_FILE = :"database.sql"
|
|
15
|
+
SCHEMA_FILE = :"schema.rb"
|
|
16
|
+
MIGRATIONS_DIR = :"db/migrate"
|
|
17
|
+
|
|
18
|
+
def initialize
|
|
19
|
+
# ActiveRecord::Base.logger = Logger.new(STDOUT)
|
|
20
|
+
if Aro::Dom.in_arodom?
|
|
21
|
+
set_up_aos
|
|
22
|
+
else
|
|
23
|
+
Aro::P.say(I18n.t("cli.errors.not_in_aro" , cmd: Aro::Dom.name))
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def self.base_aro_dir
|
|
28
|
+
Aro::Dom.ethergeist_path
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def db_config_filepath
|
|
32
|
+
File.join(Aos::Db.base_aro_dir, Aos::Db::DATABASE_YML.to_s)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def set_up_aos
|
|
36
|
+
name = Aro::Dom.ethergeist_name
|
|
37
|
+
return if name.nil?
|
|
38
|
+
|
|
39
|
+
# create local /.ethergeist directory
|
|
40
|
+
unless File.exist?(Aos::Db.base_aro_dir)
|
|
41
|
+
FileUtils.mkdir(Aos::Db.base_aro_dir)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
unless File.exist?(db_config_filepath)
|
|
45
|
+
Aro::D.say("creating database: #{db_config_filepath}")
|
|
46
|
+
# create database config yaml file
|
|
47
|
+
c = {
|
|
48
|
+
adapter: :sqlite3.to_s,
|
|
49
|
+
database: File.join(Aos::Db.base_aro_dir, Aos::Db::SQL_FILE.to_s),
|
|
50
|
+
username: name,
|
|
51
|
+
password: name
|
|
52
|
+
}.to_yaml
|
|
53
|
+
File.open(db_config_filepath, "w") do |file|
|
|
54
|
+
file.write(c)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
connect(name)
|
|
59
|
+
migrate(name)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def migrate(name)
|
|
63
|
+
local_migrate_dir = File.join(Aos::Db.base_aro_dir, Aos::Db::MIGRATIONS_DIR.to_s)
|
|
64
|
+
unless Dir.exist?(local_migrate_dir)
|
|
65
|
+
gem_dir = Dir[Gem.loaded_specs[:aro.to_s]&.full_gem_path || '.'].first
|
|
66
|
+
FileUtils.cp_r(File.join(gem_dir, "db"), Aos::Db::base_aro_dir)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
migration_version = Dir["#{local_migrate_dir}/*.rb"].map{|n|
|
|
70
|
+
Pathname.new(n).basename.to_s.split("_")[0].to_i
|
|
71
|
+
}.max
|
|
72
|
+
ActiveRecord::MigrationContext.new(local_migrate_dir).migrate(migration_version)
|
|
73
|
+
|
|
74
|
+
filename = File.join(Aos::Db.base_aro_dir, Aos::Db::SCHEMA_FILE.to_s)
|
|
75
|
+
File.open(filename, "w+") do |f|
|
|
76
|
+
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection_pool, f)
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
data/sys/aos/s.rb
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
|
|
3
|
+
s.rb
|
|
4
|
+
|
|
5
|
+
s logger for i2097i.
|
|
6
|
+
|
|
7
|
+
by i2097i
|
|
8
|
+
|
|
9
|
+
=end
|
|
10
|
+
|
|
11
|
+
require_relative :"../shr/prompt".to_s
|
|
12
|
+
|
|
13
|
+
module Aos
|
|
14
|
+
class S < Aro::Prompt
|
|
15
|
+
def self.say(message)
|
|
16
|
+
return unless Aos::S.should_print?
|
|
17
|
+
Aro::P::p.say(message)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.should_print?
|
|
21
|
+
true
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
|
|
3
|
+
views/base.rb
|
|
4
|
+
|
|
5
|
+
the base view (abstract).
|
|
6
|
+
|
|
7
|
+
by i2097i
|
|
8
|
+
|
|
9
|
+
=end
|
|
10
|
+
|
|
11
|
+
require :aro.to_s
|
|
12
|
+
|
|
13
|
+
module Aos
|
|
14
|
+
module Vi
|
|
15
|
+
class Base
|
|
16
|
+
BAR = :"|".to_s
|
|
17
|
+
MARGIN_V = Aro::Mancy::S
|
|
18
|
+
MARGIN_H = Aro::Mancy::S
|
|
19
|
+
|
|
20
|
+
def self.show(model)
|
|
21
|
+
unless Aro::Mancy.game.nil?
|
|
22
|
+
Aro::Mancy.game.show
|
|
23
|
+
return
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# default view
|
|
27
|
+
draw([self.name], model)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.draw(lines, you = nil)
|
|
31
|
+
return false unless lines.kind_of?(Array)
|
|
32
|
+
|
|
33
|
+
dc = CLI::Config.display_config
|
|
34
|
+
height = dc[:HEIGHT]
|
|
35
|
+
width = dc[:WIDTH]
|
|
36
|
+
|
|
37
|
+
# lines printed
|
|
38
|
+
printed = Aro::Mancy::O
|
|
39
|
+
|
|
40
|
+
# max printable lines
|
|
41
|
+
# vertical margins
|
|
42
|
+
max_lines = height - Aos::Vi::Base::MARGIN_V * Aro::Mancy::OS
|
|
43
|
+
# footer
|
|
44
|
+
max_lines = max_lines + Aro::Mancy::S
|
|
45
|
+
|
|
46
|
+
# header
|
|
47
|
+
Aro::Mancy::S.times do |i|
|
|
48
|
+
printed += Aro::Mancy::OS
|
|
49
|
+
Aos::S.say("".center(width, dc[:DIVIDER]))
|
|
50
|
+
printed += Aro::Mancy::OS
|
|
51
|
+
Aos::S.say("".center(width))
|
|
52
|
+
Aos::S.say("\n")
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
half = ((width - self.name.length) / Aro::Mancy::OS.to_f).ceil
|
|
56
|
+
domain = Aro::Dom.in_arodom? ? Aro::Dom::domain : Aro::Mancy.domain
|
|
57
|
+
clock = Time.now.strftime(Aos::Os::DATE_FORMAT)
|
|
58
|
+
printed += Aro::Mancy::S
|
|
59
|
+
Aos::S.say(
|
|
60
|
+
(
|
|
61
|
+
domain.ljust(half) + self.name.to_s.upcase
|
|
62
|
+
).ljust(width - clock.length) + clock
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
Aro::Mancy::S.times do
|
|
66
|
+
printed += Aro::Mancy::S
|
|
67
|
+
Aos::S.say("".center(width, dc[:DIVIDER]))
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# top vertical margin
|
|
71
|
+
Aos::Vi::Base::MARGIN_V.times do
|
|
72
|
+
printed += Aro::Mancy::S
|
|
73
|
+
print_regular_line("")
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# yield => print lines
|
|
77
|
+
lines.each{|line|
|
|
78
|
+
next if printed == max_lines
|
|
79
|
+
|
|
80
|
+
printed += Aro::Mancy::S
|
|
81
|
+
print_regular_line(line)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
# fill empty space
|
|
85
|
+
while printed < max_lines
|
|
86
|
+
printed += Aro::Mancy::S
|
|
87
|
+
print_regular_line("")
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# bottom vertical margin
|
|
91
|
+
Aos::Vi::Base::MARGIN_V.times do
|
|
92
|
+
printed += Aro::Mancy::S
|
|
93
|
+
Aos::S.say("[#{Aos::Os} v#{Aro::VERSION.to_s}]".center(width, :"-".to_s))
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# footer
|
|
97
|
+
dimension = (Aro::T.is_dev_tarot? ? Aro::T::DEV_TAROT : Aro::T::RUBY_FACOT)
|
|
98
|
+
dt = Aro::T.read_dev_tarot.strip[Aro::Mancy::S..]
|
|
99
|
+
display_dim = "#{dt.rjust(Aro::Mancy::V)} :<[#{dimension}]<"
|
|
100
|
+
Aos::S.say(
|
|
101
|
+
(
|
|
102
|
+
">#{domain}>#{Aos::Os::osify(you&.pwd || Dir.pwd)}"
|
|
103
|
+
).ljust(width - display_dim.length) + display_dim
|
|
104
|
+
)
|
|
105
|
+
Aos::S.say("".center(width, dc[:DIVIDER]))
|
|
106
|
+
|
|
107
|
+
# debug logging
|
|
108
|
+
Aro::D.say("invalid printed height: #{height}, printed: #{printed}") if printed != height
|
|
109
|
+
|
|
110
|
+
# explicitly return true
|
|
111
|
+
true
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def self.viewport_width
|
|
115
|
+
dc = CLI::Config.display_config
|
|
116
|
+
width = dc[:WIDTH]
|
|
117
|
+
bar_width = (Aos::Vi::Base::BAR.length * Aro::Mancy::OS)
|
|
118
|
+
h_margin_width = (Aos::Vi::Base::MARGIN_H * Aro::Mancy::OS)
|
|
119
|
+
|
|
120
|
+
(width - (bar_width + h_margin_width))
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def self.print_regular_line(line)
|
|
124
|
+
hm = Aos::Vi::Base::MARGIN_H
|
|
125
|
+
bar = Aos::Vi::Base::BAR
|
|
126
|
+
hm_space = " " * Aos::Vi::Base::MARGIN_H
|
|
127
|
+
just = CLI::Config.display_config[:WIDTH] - (hm_space.length + bar.length)
|
|
128
|
+
Aos::S.say((bar + hm_space + (line || "")).ljust(just) + hm_space + bar)
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def self.lines_for_cmd(cmd)
|
|
132
|
+
just_cmds = Aro::Mancy::NUMERALS[:IX]
|
|
133
|
+
cmd_lines = []
|
|
134
|
+
key_proc = Proc.new{|k| "$ #{k}"}
|
|
135
|
+
desc_proc = Proc.new{|desc| "#{"desc:".rjust(just_cmds)} #{desc}"}
|
|
136
|
+
usage_proc = Proc.new{|usage| "#{"usage:".rjust(just_cmds)} #{usage}"}
|
|
137
|
+
|
|
138
|
+
cmd_lines << key_proc.call(cmd[:key])
|
|
139
|
+
cmd_lines << desc_proc.call(cmd[:description])
|
|
140
|
+
cmd_lines << usage_proc.call(cmd[:usage])
|
|
141
|
+
(cmd[:cmds] || []).each{|k, v|
|
|
142
|
+
cmd_lines << key_proc.call("#{cmd[:key]} #{v[:key]}")
|
|
143
|
+
cmd_lines << desc_proc.call(v[:description])
|
|
144
|
+
cmd_lines << usage_proc.call(v[:usage])
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
cmd_lines
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def self.debug_log(lines)
|
|
151
|
+
Aro::V.say(lines)
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
|
|
3
|
+
views/dom.rb
|
|
4
|
+
|
|
5
|
+
the dom view.
|
|
6
|
+
|
|
7
|
+
by i2097i
|
|
8
|
+
|
|
9
|
+
=end
|
|
10
|
+
|
|
11
|
+
require_relative :"./base".to_s
|
|
12
|
+
|
|
13
|
+
module Aos
|
|
14
|
+
module Vi
|
|
15
|
+
class Dom < Aos::Vi::Base
|
|
16
|
+
|
|
17
|
+
def self.show(model)
|
|
18
|
+
lines = []
|
|
19
|
+
lines << I18n.t("aos.views.dom.title")
|
|
20
|
+
lines << I18n.t("aos.views.dom.description")
|
|
21
|
+
lines << ""
|
|
22
|
+
lines << I18n.t("aos.constants.commands")
|
|
23
|
+
Aos::Os::CMDS.keys.sort.each{|cmd|
|
|
24
|
+
lines += lines_for_cmd(Aos::Os::CMDS[cmd])
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
lines << ""
|
|
28
|
+
lines << I18n.t("aos.views.dom.quick_navigation")
|
|
29
|
+
lines << ""
|
|
30
|
+
lines << " => #{Aro::Dom::D.reserved_words.join(" ")}"
|
|
31
|
+
lines << ""
|
|
32
|
+
draw(lines, model)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
|
|
3
|
+
views/games/abpps.rb
|
|
4
|
+
|
|
5
|
+
the apbbs view.
|
|
6
|
+
|
|
7
|
+
by i2097i
|
|
8
|
+
|
|
9
|
+
=end
|
|
10
|
+
|
|
11
|
+
require_relative :"./game".to_s
|
|
12
|
+
|
|
13
|
+
module Aos
|
|
14
|
+
module Vi
|
|
15
|
+
class Abpps < Aos::Vi::Game
|
|
16
|
+
def self.show(model)
|
|
17
|
+
draw(super, model)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
|
|
3
|
+
views/games/game.rb
|
|
4
|
+
|
|
5
|
+
the game view.
|
|
6
|
+
|
|
7
|
+
by i2097i
|
|
8
|
+
|
|
9
|
+
=end
|
|
10
|
+
|
|
11
|
+
require_relative :"../../../models/deck".to_s
|
|
12
|
+
require_relative :"../base".to_s
|
|
13
|
+
|
|
14
|
+
module Aos
|
|
15
|
+
module Vi
|
|
16
|
+
class Game < Aos::Vi::Base
|
|
17
|
+
|
|
18
|
+
DECK_PARAMS = [
|
|
19
|
+
:deck,
|
|
20
|
+
:h_logs,
|
|
21
|
+
:count_n,
|
|
22
|
+
:order_o,
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
def self.show(model)
|
|
26
|
+
unless Aro::Mancy.game.nil?
|
|
27
|
+
Aro::Mancy.game.show
|
|
28
|
+
return
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
lines = []
|
|
32
|
+
lines << I18n.t("aos.views.game.title").center(viewport_width)
|
|
33
|
+
lines << I18n.t("aos.views.game.description").center(viewport_width)
|
|
34
|
+
|
|
35
|
+
room_def = Aro::Dom::D::WINGS[:GAMES].values.filter{|gr|
|
|
36
|
+
"#{Aos::Vi.name}::#{gr[:name].to_s.downcase.capitalize}" == self.name
|
|
37
|
+
}.first
|
|
38
|
+
unless room_def.nil?
|
|
39
|
+
lines << I18n.t("aos.views.game.is_the", name: room_def[:name].to_s)
|
|
40
|
+
lines << I18n.t("aos.views.game.designed_for", description: room_def[:description])
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
draw(lines, model)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def self.show_game(model)
|
|
47
|
+
mk = model.keys
|
|
48
|
+
dp = Aos::Vi::Game::DECK_PARAMS
|
|
49
|
+
return nil unless (mk & dp).count == dp.count
|
|
50
|
+
return nil unless model.values.all?{|v| v != nil}
|
|
51
|
+
|
|
52
|
+
deck = model[:deck]
|
|
53
|
+
h_logs = model[:h_logs]
|
|
54
|
+
count_n = model[:count_n]
|
|
55
|
+
order_o = model[:order_o]
|
|
56
|
+
|
|
57
|
+
dc = CLI::Config.display_config
|
|
58
|
+
width = dc[:WIDTH] = viewport_width
|
|
59
|
+
divider = dc[:DIVIDER] * viewport_width
|
|
60
|
+
lines = []
|
|
61
|
+
lines << "#{deck.name.upcase.center(width)}"
|
|
62
|
+
h_logs.each_with_index{|l, i|
|
|
63
|
+
lines << divider
|
|
64
|
+
lines << ""
|
|
65
|
+
timestamp = l.created_at.strftime(CLI::Config::DATE_FORMAT)
|
|
66
|
+
of_text = "#{order_o.to_sym == Aro::Log::ORDERING[:DESC] ? deck.logs.count - i : 1 + i} of #{deck.logs.count}"
|
|
67
|
+
lines << of_text.ljust(width - timestamp.length) + timestamp
|
|
68
|
+
lines << divider
|
|
69
|
+
cards = Base64::decode64(l.card_data).split(Aro::Deck::CARD_DELIM.to_s)
|
|
70
|
+
if !cards.nil? && cards.any?
|
|
71
|
+
lines << ""
|
|
72
|
+
lines += self.get_display_for_cards(cards)
|
|
73
|
+
lines << divider
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
drawn_cards = Base64::decode64(l.drawn_data).split(Aro::Deck::CARD_DELIM.to_s)
|
|
77
|
+
if !drawn_cards.nil? && drawn_cards.any?
|
|
78
|
+
lines << ""
|
|
79
|
+
lines << I18n.t("cli.messages.history_drawn").center(width)
|
|
80
|
+
lines << divider
|
|
81
|
+
lines << ""
|
|
82
|
+
lines += self.get_display_for_cards(
|
|
83
|
+
drawn_cards
|
|
84
|
+
)
|
|
85
|
+
lines << ""
|
|
86
|
+
lines << divider
|
|
87
|
+
end
|
|
88
|
+
}
|
|
89
|
+
if count_n == Aro::Mancy::S
|
|
90
|
+
draw(lines)
|
|
91
|
+
else
|
|
92
|
+
Aro::P.less(lines.join("\n"))
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def self.get_display_for_cards(input = [])
|
|
97
|
+
columns = CLI::Config.display_config[:COLUMNS].to_i
|
|
98
|
+
lines = []
|
|
99
|
+
return lines unless input.any?
|
|
100
|
+
card_line = ""
|
|
101
|
+
input.each_with_index{|c, i|
|
|
102
|
+
s = (i + Aro::Mancy::S) % [Aro::Mancy::S, columns].max
|
|
103
|
+
card_line += c.ljust(columns)
|
|
104
|
+
if Aro::Mancy::O == s || i == input.count - Aro::Mancy::S
|
|
105
|
+
lines << card_line
|
|
106
|
+
card_line = ""
|
|
107
|
+
end
|
|
108
|
+
}
|
|
109
|
+
lines << ""
|
|
110
|
+
lines
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|