aromancer 0.0.7 → 0.0.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.
data/lib/aromancer.rb CHANGED
@@ -14,8 +14,7 @@ require_relative :reiquire.to_s
14
14
  Reiquire::aromancer
15
15
 
16
16
  module Aromancer
17
- THROTTLE_MS = 0.1
18
- ERROR_EXPIRATION = 7.77.to_f
17
+ ERROR_EXPIRATION = 11.11.to_f
19
18
  FONT = TTY::Font.new(:standard)
20
19
  DATE_FORMAT = "%A %d %b %Y %I:%M:%S %p"
21
20
  TIME_FORMAT = "%I:%M:%S %p"
@@ -25,136 +24,30 @@ module Aromancer
25
24
  check: "\u2713"
26
25
  }
27
26
 
28
- class Serve
29
- def self.run
30
- unless Dir.exist?("#{Aromancer.to_s.downcase}_serve")
31
- system("git clone git@github.com:arowmancy/aromancer_serve.git")
32
- end
33
- FileUtils.chdir :aromancer_serve.to_s do
34
- system("bin/setup")
35
- end
36
- end
27
+ def self.print_large_text(text = Aromancer.to_s.downcase, letter_spacing = 1)
28
+ Aromancer::Prompt.say(Aromancer::FONT.write(text, letter_spacing: letter_spacing))
37
29
  end
38
30
 
39
- # instance runs on main thread
40
- class Cli
41
- include Singleton
42
-
43
- attr_accessor :ui_thread, :ws_thread, :busy, :ws_busy, :last_render, :error_timeout
44
-
45
- # user entry point
46
- def self.run
47
- # ensure preferences exist
48
- Aromancer::Storage.get_preference(:debug, default: false)
49
- Aromancer::Storage.get_preference(:force_ssl, default: true)
50
- Aromancer::Storage.get_preference(:hide_sentences, default: true)
51
- Aromancer::Storage.get_preference(:hide_stream, default: true)
52
-
53
- self.instance.last_render = 0
54
- self.instance.error_timeout = Time.now.to_i
55
-
56
- # load player on-start
57
- Aromancer::Api.set_active_legend_id(nil) unless Aromancer::Storage.get_player.nil?
58
-
59
- Thread.main[:route] = :authentication
60
- Thread.main[:menu_runners] = {}
61
- Thread.main[:menu_options] = {}
62
- Aromancer::Prompt.say(I18n.t("shared.welcome", version: Aromancer::VERSION))
63
- Aromancer::Prompt.say(I18n.t("shared.server_url", url: Aromancer::Storage::get_server_url))
64
- self.instance.start_ui_thread
65
- self.instance.start_ws_thread
66
- loop do
67
- begin
68
- self.instance.ui_thread.join
69
- rescue NoMethodError => e
70
- if Aromancer::Storage.get_preference(:debug)
71
- Aromancer::Prompt.say(I18n.t("shared.last_error"))
72
- Aromancer::Prompt.say(JSON.pretty_generate(e[:body.to_s]))
73
- Aromancer::Prompt.say("sleeping 5 on main thread...")
74
- sleep(5)
75
- end
76
- self.instance.start_ui_thread
77
- self.instance.start_ws_thread
78
- sleep(1)
79
- rescue Interrupt => e
80
- Aromancer::Prompt.say("interrupt on main thread...exiting immediately.")
81
- exit
82
- end
83
- end
84
- end
85
-
86
- def get_view(view_key)
87
- Thread.main[:menu_options][view_key.to_sym]
88
- end
89
-
90
- def start_ui_thread(force = false)
91
- return if (@busy || Time.now - @last_render < 2.0) && !force
92
-
93
- @busy = true
94
- self.ui_thread&.exit
95
- self.ui_thread&.kill
96
- Thread.main[:menu_runners] = {}
97
- Thread.main[:menu_options] = {}
98
- Aromancer::Prompt.instance.reload!
99
- self.ui_thread = Thread.new do
100
- loop do
101
- menu_options = Thread.main[:menu_options][Thread.main[:route]]
102
- menu_runners = Thread.main[:menu_runners][Thread.main[:route]]
103
- unless menu_options.nil? || menu_runners.nil?
104
- Aromancer::Routes.resume
105
- Aromancer.print_hud
106
- sleep(THROTTLE_MS)
107
- v = Aromancer::Prompt.p.select("", menu_options, show_help: :always, cycle: true, per_page: 11)
108
- runners = menu_runners.select{|r| r[:value] == v}
109
- runners = menu_runners.select{|r| r[:value].nil?} if runners.empty?
110
-
111
- if runners.any?
112
- r = runners.first
113
- r[:proc].call(v)
114
- end
115
-
116
- else
117
- Aromancer::Routes.resume
118
- end
119
- Aromancer::Cli.instance.busy = false
120
- Aromancer::Cli.instance.last_render = Time.now
121
- sleep(THROTTLE_MS)
122
- end
123
- end
124
- end
125
-
126
- def start_ws_thread
127
- return if @ws_busy
128
- @ws_busy = true
129
- self.ws_thread.kill unless self.ws_thread.nil?
130
- self.ws_thread = Thread.new do
131
- Aromancer::Websocket.instance.disconnect
132
- loop do
133
- player = Aromancer::Storage.get_player
134
- if player.nil?
135
- @ws_busy = true
136
- Aromancer::Websocket.instance.disconnect
137
- elsif !player["api_key"].nil?
138
- # attempt websocket connection
139
- @ws_busy = true
140
- Aromancer::Websocket.instance.connect
141
- end
142
- @ws_busy = false
143
- sleep(4)
144
- end
31
+ def self.configure_home
32
+ FileUtils.mkdir_p(Aromancer.home_directory) unless Dir.exist? Aromancer.home_directory
33
+ FileUtils.mkdir_p(Aromancer.arena_directory) unless Dir.exist? Aromancer.arena_directory
34
+ unless Dir.exist? File.join(Aromancer.home_directory, :".git".to_s)
35
+ FileUtils.chdir Aromancer.home_directory do
36
+ system(:"git init".to_s)
37
+ system(:"git add .".to_s)
38
+ system(:"git commit -m \"#{self.name} initial commit\"".to_s)
145
39
  end
146
40
  end
147
-
148
- end
149
-
150
- def self.get_font(text = :aromancer.to_s, letter_spacing = 1)
151
- Aromancer::FONT.write(text, letter_spacing: letter_spacing).split("\n")
152
41
  end
153
42
 
154
43
  def self.home_directory
155
44
  "#{`echo $HOME`.strip}/.aromancer"
156
45
  end
157
46
 
47
+ def self.arena_directory
48
+ File.join(home_directory, :arena.to_s)
49
+ end
50
+
158
51
  def self.date_display(raw)
159
52
  DateTime.parse(raw)&.strftime(Aromancer::DATE_FORMAT).downcase.gsub(" ", "_")
160
53
  end
@@ -165,15 +58,42 @@ module Aromancer
165
58
 
166
59
  def self.print_hud
167
60
  print_last_error
168
- websocket_status = "#{Aromancer::Storage.instance.get_key(:websocket_scheme)}: #{Aromancer::Websocket.instance.socket.nil? ? UNICODE[:close] : UNICODE[:check] }"
61
+ ws_status_symbol = (
62
+ Aromancer::Websocket.instance.socket.nil? || Aromancer::Websocket.instance.socket.closed?
63
+ ) ? UNICODE[:close] : UNICODE[:check]
64
+ websocket_status = "#{Aromancer::Storage.instance.get_key(:websocket_scheme)}: #{ws_status_symbol}"
169
65
  player_status = if Aromancer::Storage.get_player.nil?
170
66
  I18n.t("routes.main_menu.not_signed_in")
171
67
  else
172
68
  I18n.t("shared.signed_in_as", as: Aromancer::Storage.get_player["alias"])
173
69
  end
70
+ server_status = I18n.t("shared.server_url", url: Aromancer::Storage::get_server_url)
71
+ force_ssl_value = Aromancer::Storage.get_preference(:force_ssl)
72
+ force_ssl_status_symbol = (
73
+ force_ssl_value
74
+ ) ? UNICODE[:check] : UNICODE[:close]
75
+ force_ssl_status = "ssl: #{force_ssl_status_symbol}"
76
+
77
+ debug_value = Aromancer::Storage.get_preference(:debug)
78
+ hud = [
79
+ nil,
80
+ player_status,
81
+ server_status,
82
+ force_ssl_status,
83
+ websocket_status,
84
+ :v.to_s + Aromancer::VERSION,
85
+ nil
86
+ ]
87
+
88
+ if debug_value
89
+ debug_status_symbol = (
90
+ debug_value
91
+ ) ? UNICODE[:check] : UNICODE[:close]
92
+ hud.insert(1, "d: #{debug_status_symbol}")
93
+ end
174
94
 
175
95
  Aromancer::Prompt.say(
176
- [nil, :v.to_s + Aromancer::VERSION, player_status, websocket_status, nil,].join(" | ")
96
+ hud.join(" | ")
177
97
  )
178
98
  end
179
99
 
@@ -184,14 +104,15 @@ module Aromancer
184
104
  return
185
105
  end
186
106
 
187
- last_error = Aromancer::Storage.get_last_error
188
- return if last_error.nil?
107
+ last_error = Aromancer::Storage.get_last_error&.symbolize_keys
189
108
 
190
- last_error = last_error.symbolize_keys
109
+ return if last_error.nil?
191
110
  message = last_error[:body]
192
111
  begin
193
112
  message = JSON.parse(message).symbolize_keys
194
113
  message = message[:error_message] if message.keys.include?(:error_message)
114
+ rescue TypeError => e
115
+ message = last_error[:body]
195
116
  rescue JSON::ParserError => e
196
117
  message = last_error[:body]
197
118
  end
data/lib/reiquire.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  =begin
2
4
 
3
5
  reiquire.rb
data/listen.rb CHANGED
@@ -1,10 +1,6 @@
1
1
  require :listen.to_s
2
2
 
3
3
  listener = Listen.to(*[:lib.to_s, :bin.to_s, :spec.to_s, :locale.to_s], only: /[\.rb\.yml]/) {|modified, added, removed|
4
- # puts modified
5
- # puts added
6
- # puts removed
7
- # system("exec rake make")
8
4
  system("exec rake install")
9
5
  }
10
6
  listener.start
data/locale/en.yml CHANGED
@@ -6,13 +6,14 @@ en:
6
6
  key_press: "press enter to continue: "
7
7
  inturrupt: "exiting due to user inturrupt..."
8
8
  reader_initialized: "input reader initialized."
9
- welcome: "welcome to aromancer. loading v%{version}..."
9
+ welcome: "welcome aromancer. loading v%{version}..."
10
10
  server_url: "current server: %{url}"
11
11
  navigate: "navigate to %{route}."
12
12
  update_cancel: "update cancelled."
13
13
  update_confirm: "confirm update [%{new_value}] (enter y): "
14
14
  signed_in_as: "authenticated as %{as}"
15
15
  last_error: "error (%{status}). %{error}"
16
+ spelling: "spelling..."
16
17
  back: "back"
17
18
  exit: "exit"
18
19
  routes:
@@ -68,7 +69,7 @@ en:
68
69
  place_on_scroll: "place %{word} on the scroll."
69
70
  options_for_word: "available options for the %{word} word."
70
71
  last_error: "last error"
71
- returning_to_main: "returning to main menu..."
72
+ returning_to_: "returning to %{route}..."
72
73
  your_alchemy: "alchemy"
73
74
  legends:
74
75
  help: ""
data/tasks/make.rake CHANGED
@@ -1,4 +1,4 @@
1
- desc "bundle graph && rake install && rspec --backtrace"
1
+ desc "rake install"
2
2
  task :make do
3
- exec "bundle graph && rake install && rspec --backtrace"
3
+ exec "rake install"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aromancer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - i2097i
@@ -227,6 +227,7 @@ executables:
227
227
  extensions: []
228
228
  extra_rdoc_files: []
229
229
  files:
230
+ - ".DS_Store"
230
231
  - ".gitignore"
231
232
  - ".rspec"
232
233
  - ".ruby-version"
@@ -235,7 +236,6 @@ files:
235
236
  - Gemfile
236
237
  - Gemfile.lock
237
238
  - LICENSE
238
- - LICENSE.txt
239
239
  - README.md
240
240
  - Rakefile
241
241
  - aromancer.gemspec
@@ -247,14 +247,18 @@ files:
247
247
  - checksums/aromancer-0.0.5.gem.sha512
248
248
  - checksums/aromancer-0.0.6.gem.sha512
249
249
  - checksums/aromancer-0.0.7.gem.sha512
250
- - gem_graph.png
250
+ - checksums/aromancer-0.0.8.gem.sha512
251
+ - checksums/aromancer-0.0.9.gem.sha512
251
252
  - lib/aromancer.rb
252
253
  - lib/aromancer/.DS_Store
253
254
  - lib/aromancer/api.rb
255
+ - lib/aromancer/cli.rb
254
256
  - lib/aromancer/prompt.rb
255
257
  - lib/aromancer/routes.rb
258
+ - lib/aromancer/serve.rb
256
259
  - lib/aromancer/server.rb
257
260
  - lib/aromancer/storage.rb
261
+ - lib/aromancer/unix_dom.rb
258
262
  - lib/aromancer/version.rb
259
263
  - lib/aromancer/websocket.rb
260
264
  - lib/reiquire.rb
data/LICENSE.txt DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2026 i2097i
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
data/gem_graph.png DELETED
Binary file