f_dot 0.0.1 → 0.0.2
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/.gitignore +2 -1
- data/Gemfile.lock +2 -2
- data/bin/f_dot +14 -1
- data/checksums/f_dot-0.0.1.gem.sha512 +1 -1
- data/checksums/f_dot-0.0.2.gem.sha512 +1 -0
- data/deserialization_testing.rb +12 -6
- data/f_dot.gemspec +1 -1
- data/lib/f_dot/based.rb +48 -13
- data/lib/f_dot/cubicus.rb +178 -0
- data/lib/f_dot/history.rb +5 -4
- data/lib/f_dot/instruction.rb +3 -3
- data/lib/f_dot/interface.rb +54 -31
- data/lib/f_dot/processor.rb +163 -91
- data/lib/f_dot/program.rb +107 -76
- data/lib/f_dot/variable.rb +2 -2
- data/lib/f_dot/version.rb +4 -2
- data/lib/f_dot.rb +11 -0
- data/lib/go/f_dot.go +243 -0
- data/lib/go/go.mod +10 -0
- data/lib/go/go.sum +6 -0
- data/lib/go/index.html +18 -0
- data/lib/go/javascript/.DS_Store +0 -0
- data/lib/go/javascript/canvas.js +33 -0
- data/lib/go/javascript/entry.js +8 -0
- data/lib/go/javascript/f_dot_go.js +250 -0
- data/lib/go/javascript/gl-matrix-min.js +28 -0
- data/lib/go/stylesheets/f_dot_go.css +64 -0
- metadata +15 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b88e18072524eac7b3bcc2c89bc24575df4f8463bf430ca1572058c52823cad1
|
|
4
|
+
data.tar.gz: c2d40369259cefaa3fc9f2b6676e9bcdc4b63d67def0f466daace4859e34b463
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f485a41b3e59a3a5173c71b025d286ee6260997827aee5c749824a2c98df0a05c459f2c7643279ceefa688f19b0462eb225b11d9db4891fafa286367eb903aff
|
|
7
|
+
data.tar.gz: 5276e9c537d47f573c42a4476ed071abd6915a1bc00cd83a1fd2f1e28f31388d5627a09e71c0838c0cce9891455ea7b5ada46106f89333a8c64a1d58db7a4116
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
f_dot (0.0.
|
|
4
|
+
f_dot (0.0.2)
|
|
5
5
|
tty-font (~> 0.5, >= 0.5.0)
|
|
6
6
|
tty-prompt (~> 0.23, >= 0.23.1)
|
|
7
7
|
|
|
@@ -109,7 +109,7 @@ CHECKSUMS
|
|
|
109
109
|
bundler (4.0.22) sha256=d8d5ec84c8555e0af71db63ed7aee4d1a8fb839ec46d84212d61979242a5d75a
|
|
110
110
|
diff-lcs (1.6.2) sha256=9ae0d2cba7d4df3075fe8cd8602a8604993efc0dfa934cff568969efb1909962
|
|
111
111
|
erb (6.0.7) sha256=c5ca6dc25b0ef974a44dc8f59fe847577122483b1968a38dec305c60bf91ee92
|
|
112
|
-
f_dot (0.0.
|
|
112
|
+
f_dot (0.0.2)
|
|
113
113
|
ffi (1.17.4) sha256=bcd1642e06f0d16fc9e09ac6d49c3a7298b9789bcb58127302f934e437d60acf
|
|
114
114
|
ffi (1.17.4-aarch64-linux-gnu) sha256=b208f06f91ffd8f5e1193da3cae3d2ccfc27fc36fba577baf698d26d91c080df
|
|
115
115
|
ffi (1.17.4-aarch64-linux-musl) sha256=9286b7a615f2676245283aef0a0a3b475ae3aae2bb5448baace630bb77b91f39
|
data/bin/f_dot
CHANGED
|
@@ -14,4 +14,17 @@
|
|
|
14
14
|
|
|
15
15
|
require :f_dot.to_s
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
begin
|
|
18
|
+
if ARGV[0]&.strip&.to_sym == :cubicus
|
|
19
|
+
# start in FDot::DISPLAY_MODES[:websockets] display_mode
|
|
20
|
+
# start websocket thread
|
|
21
|
+
FDot::Based::Cubicus.instance.start_ws_thread
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# run based f_dot
|
|
25
|
+
FDot::Based::Processor.instance.run
|
|
26
|
+
rescue StandardError => e
|
|
27
|
+
puts "rescued in f_dot bin for #{e}"
|
|
28
|
+
puts Thread.current.backtrace
|
|
29
|
+
raise e
|
|
30
|
+
end
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
4979bffb11b295e0234895493928b93322e804b6e7d456e7cf364c2a53ac57b7b5b826ccc667f1f641e713cfd442701a7defbd0de04b89313b3f6b73b324caf8
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
13d938dde631803c01e41fdb6ae0ce20fe84d12bbc6af7bd375940061942443c7ed0aefd6d524a7532905414dbf15052fd7204d909e28346e6dd40250d87e464
|
data/deserialization_testing.rb
CHANGED
|
@@ -8,8 +8,6 @@
|
|
|
8
8
|
# right now this is a simple example of utilizing the
|
|
9
9
|
# FDot::Based::Processor.instance.write_state_callback
|
|
10
10
|
#
|
|
11
|
-
# within an oss_om plugin.
|
|
12
|
-
#
|
|
13
11
|
# by i2097i
|
|
14
12
|
|
|
15
13
|
require "f_dot"
|
|
@@ -23,19 +21,27 @@ if File.exist?(load_from_file_name)
|
|
|
23
21
|
serialized_data = JSON.parse File.read(load_from_file_name)
|
|
24
22
|
end
|
|
25
23
|
|
|
26
|
-
|
|
24
|
+
write_state_callback = Proc.new{|incoming_data|
|
|
27
25
|
puts "received #{incoming_data.to_s.length} ascii on callback stream"
|
|
28
26
|
serialized_data = incoming_data.dup
|
|
29
|
-
File.open(load_from_file_name, "w
|
|
27
|
+
File.open(load_from_file_name, "w") do |file|
|
|
30
28
|
file.write(serialized_data.to_json)
|
|
31
29
|
end
|
|
32
30
|
}
|
|
33
31
|
|
|
34
32
|
if File.exist?(load_from_file_name)
|
|
35
|
-
|
|
33
|
+
|
|
34
|
+
# update override_path to change where FDot::Based::Interface projects f_dot into folder space
|
|
35
|
+
#
|
|
36
|
+
# example:
|
|
37
|
+
#
|
|
38
|
+
# override_path = "/alternate/f_dot_space_path"
|
|
39
|
+
override_path = nil
|
|
40
|
+
|
|
41
|
+
FDot::Based::Processor.initialize_with_data(override_path, write_state_callback, serialized_data)
|
|
36
42
|
else
|
|
37
43
|
# create the file
|
|
38
|
-
File.open(load_from_file_name, "w
|
|
44
|
+
File.open(load_from_file_name, "w") do |file|
|
|
39
45
|
file.write(serialized_data.to_json)
|
|
40
46
|
end
|
|
41
47
|
FDot::Based::Processor.instance.run
|
data/f_dot.gemspec
CHANGED
|
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
|
20
20
|
spec.authors = ["i2097i"]
|
|
21
21
|
spec.email = ["i2097i@hotmail.com"]
|
|
22
22
|
|
|
23
|
-
spec.description = GEM_DESCRIPTION + "
|
|
23
|
+
spec.description = GEM_DESCRIPTION + " | v#{FDot::VERSION} | release notes: #{FDot::RELEASE_NOTES}"
|
|
24
24
|
spec.summary = GEM_DESCRIPTION
|
|
25
25
|
spec.homepage = "https://github.com/f-oss-om-foundation/f_dot"
|
|
26
26
|
spec.license = "MIT"
|
data/lib/f_dot/based.rb
CHANGED
|
@@ -46,13 +46,15 @@ module FDot
|
|
|
46
46
|
)
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
-
|
|
50
49
|
def self.generate_uuid
|
|
51
50
|
SecureRandom.send(:uuid_v7)
|
|
52
51
|
end
|
|
53
52
|
|
|
54
53
|
def self.f_dot_space_path
|
|
55
|
-
path = File.join(
|
|
54
|
+
path = File.join(
|
|
55
|
+
FDot::Based::Processor.instance.f_dot_space_override_path || ENV["HOME"],
|
|
56
|
+
FDot::Based::FOLDER_NAME
|
|
57
|
+
)
|
|
56
58
|
unless Dir.exist?(path)
|
|
57
59
|
FileUtils.mkdir_p(path)
|
|
58
60
|
end
|
|
@@ -60,25 +62,58 @@ module FDot
|
|
|
60
62
|
return path
|
|
61
63
|
end
|
|
62
64
|
|
|
65
|
+
def self.ask(message)
|
|
66
|
+
if FDot::Based::Interface.instance.display_mode == FDot::DISPLAY_MODES[:websockets]
|
|
67
|
+
option = {
|
|
68
|
+
type: :text,
|
|
69
|
+
name: message,
|
|
70
|
+
value: nil
|
|
71
|
+
}
|
|
72
|
+
FDot::Based::Cubicus.update_with([option]) {|new_value|
|
|
73
|
+
puts new_value
|
|
74
|
+
yield(new_value)
|
|
75
|
+
}
|
|
76
|
+
else
|
|
77
|
+
return FDot::Based::PROMPT.ask(message)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
63
81
|
def self.less(message)
|
|
64
|
-
|
|
82
|
+
if FDot::Based::Interface.instance.display_mode == FDot::DISPLAY_MODES[:websockets] ||
|
|
83
|
+
!FDot::Based::Processor.user_setting!(:debug_inspectors_enabled)
|
|
84
|
+
message.split("\n").each{|l|
|
|
85
|
+
puts l
|
|
86
|
+
}
|
|
87
|
+
else
|
|
88
|
+
IO.popen("less -X", "w") { |f| f.puts(message) }
|
|
89
|
+
end
|
|
65
90
|
end
|
|
66
91
|
|
|
67
92
|
def self.tty_prompt_select(
|
|
68
93
|
display_text = "select something: ",
|
|
69
94
|
options = []
|
|
70
95
|
)
|
|
71
|
-
if
|
|
72
|
-
puts
|
|
73
|
-
|
|
96
|
+
if FDot::Based::Interface.instance.display_mode == FDot::DISPLAY_MODES[:websockets]
|
|
97
|
+
puts display_text
|
|
98
|
+
FDot::Based::Cubicus.update_with(options) {|selected_option|
|
|
99
|
+
puts selected_option
|
|
100
|
+
yield(selected_option)
|
|
101
|
+
}
|
|
102
|
+
else
|
|
103
|
+
if options.nil? || options.empty?
|
|
104
|
+
puts "there is nothing here"
|
|
105
|
+
return
|
|
106
|
+
end
|
|
107
|
+
yield(
|
|
108
|
+
FDot::Based::PROMPT.select(
|
|
109
|
+
display_text,
|
|
110
|
+
options,
|
|
111
|
+
show_help: :always,
|
|
112
|
+
cycle: true,
|
|
113
|
+
per_page: 11
|
|
114
|
+
)
|
|
115
|
+
)
|
|
74
116
|
end
|
|
75
|
-
FDot::Based::PROMPT.select(
|
|
76
|
-
display_text,
|
|
77
|
-
options,
|
|
78
|
-
show_help: :always,
|
|
79
|
-
cycle: true,
|
|
80
|
-
per_page: 11
|
|
81
|
-
)
|
|
82
117
|
end
|
|
83
118
|
|
|
84
119
|
end
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
=begin
|
|
4
|
+
|
|
5
|
+
cubicus.rb
|
|
6
|
+
|
|
7
|
+
f_dot cubicus.
|
|
8
|
+
|
|
9
|
+
created by i2097i
|
|
10
|
+
|
|
11
|
+
=end
|
|
12
|
+
|
|
13
|
+
module FDot
|
|
14
|
+
module Based
|
|
15
|
+
class Cubicus
|
|
16
|
+
include Singleton
|
|
17
|
+
|
|
18
|
+
VALID_KEYS = [
|
|
19
|
+
:controls,
|
|
20
|
+
:display,
|
|
21
|
+
:input,
|
|
22
|
+
:f_dot_go,
|
|
23
|
+
:"index.html"
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
attr_accessor :ws_thread
|
|
27
|
+
attr_accessor :controls
|
|
28
|
+
attr_accessor :is_running
|
|
29
|
+
attr_accessor :original_stdout
|
|
30
|
+
attr_accessor :controls_delegate
|
|
31
|
+
|
|
32
|
+
FOLDER_NAME = ".cubicus"
|
|
33
|
+
|
|
34
|
+
GO_SERVER_BASENAME = "f_dot.go"
|
|
35
|
+
|
|
36
|
+
def initialize
|
|
37
|
+
self.is_running = false
|
|
38
|
+
self.ws_thread = nil
|
|
39
|
+
self.controls = {}
|
|
40
|
+
self.controls_delegate = nil
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def start_ws_thread
|
|
44
|
+
self.ws_thread&.exit
|
|
45
|
+
self.ws_thread&.kill
|
|
46
|
+
|
|
47
|
+
prepare_f_dot_go!
|
|
48
|
+
|
|
49
|
+
FDot::Based::Interface.instance.display_mode = FDot::DISPLAY_MODES[:websockets]
|
|
50
|
+
go_server_path = self.class.path_for_file(:f_dot_go)
|
|
51
|
+
|
|
52
|
+
self.original_stdout = $stdout
|
|
53
|
+
$stdout.reopen(self.class.path_for_file(:display), "w")
|
|
54
|
+
$stdout.sync = true
|
|
55
|
+
self.ws_thread = Thread.new do
|
|
56
|
+
system("#{go_server_path} > #{go_server_path}.log 2>&1")
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def self.run_exit_cleanup!
|
|
61
|
+
puts __method__
|
|
62
|
+
# do not run if not using websockets
|
|
63
|
+
return unless FDot::Based::Interface.instance.display_mode == FDot::DISPLAY_MODES[:websockets]
|
|
64
|
+
|
|
65
|
+
# do not run if in one_move mode
|
|
66
|
+
if FDot::Based::Processor.instance.processing_mode == FDot::Based::Processor::MODES[:one_move]
|
|
67
|
+
FDot::Based::Processor.instance.processing_mode = FDot::Based::Processor::MODES[:default]
|
|
68
|
+
return
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
self.write_open_system!
|
|
72
|
+
system("pkill f_dot_go") # todo: daemonize
|
|
73
|
+
self.instance.ws_thread&.exit
|
|
74
|
+
self.instance.ws_thread&.kill
|
|
75
|
+
self.instance.ws_thread = nil
|
|
76
|
+
if $stdout != self.instance.original_stdout
|
|
77
|
+
$stdout = self.instance.original_stdout
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def self.read_input!
|
|
82
|
+
unless File.exist?(self.path_for_file(:input))
|
|
83
|
+
raise "invalid #{__method__} file does not exist at #{self.path_for_file(:input)}!"
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
input = JSON.parse(File.read(self.path_for_file(:input)))
|
|
87
|
+
raise "invalid input uuid!" unless self.instance.controls.keys.include?(input["uuid"])
|
|
88
|
+
|
|
89
|
+
self.instance.controls[input["uuid"]][:value]
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def self.write_open_system!
|
|
93
|
+
# write current display
|
|
94
|
+
$stdout.sync = true
|
|
95
|
+
$stdout.flush
|
|
96
|
+
|
|
97
|
+
# write current controls
|
|
98
|
+
File.open(self.path_for_file(:controls), "w") do |f|
|
|
99
|
+
f.write(self.instance.controls.map{|k, v|
|
|
100
|
+
v.merge({uuid: k})
|
|
101
|
+
}.to_json)
|
|
102
|
+
f.fsync
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# clear last input
|
|
106
|
+
FileUtils.rm_rf(self.path_for_file(:input))
|
|
107
|
+
|
|
108
|
+
system("curl -s http://localhost:8080/ready")
|
|
109
|
+
$stdout.reopen(FDot::Based::Cubicus.path_for_file(:display), "w")
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def self.update_with(controls)
|
|
113
|
+
input_value = nil
|
|
114
|
+
Thread.new{
|
|
115
|
+
FDot::Based::Cubicus.instance.controls = {}
|
|
116
|
+
controls.each{|c|
|
|
117
|
+
control_uuid = FDot::Based.generate_uuid
|
|
118
|
+
FDot::Based::Cubicus.instance.controls[control_uuid] = c
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
FDot::Based::Cubicus.write_open_system!
|
|
122
|
+
|
|
123
|
+
# wait for user input
|
|
124
|
+
while !File.exist?(FDot::Based::Cubicus.path_for_file(:input)) ||
|
|
125
|
+
(File.read(FDot::Based::Cubicus.path_for_file(:input)) || "").empty?
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
input_value = FDot::Based::Cubicus.read_input!
|
|
129
|
+
}.join
|
|
130
|
+
|
|
131
|
+
yield(input_value)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
private
|
|
135
|
+
|
|
136
|
+
def prepare_f_dot_go!
|
|
137
|
+
go_directory = File.join(
|
|
138
|
+
FDot.gem_directory, "lib/go"
|
|
139
|
+
)
|
|
140
|
+
go_file_path = File.join(
|
|
141
|
+
go_directory, FDot::Based::Cubicus::GO_SERVER_BASENAME
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
raise "#{go_file_path} is not a valid file path!" unless File.exist?(go_file_path)
|
|
145
|
+
|
|
146
|
+
puts "ensure index.html exists in .f_dot directory:"
|
|
147
|
+
puts "(#{File.join(go_directory, "index.html")}, #{FDot::Based.f_dot_space_path})"
|
|
148
|
+
FileUtils.cp(File.join(go_directory, "index.html"), FDot::Based.f_dot_space_path)
|
|
149
|
+
|
|
150
|
+
puts "ensure .f_dot/javascript directory exists:"
|
|
151
|
+
puts "(#{File.join(go_directory, "javascript")}, #{FDot::Based.f_dot_space_path})"
|
|
152
|
+
FileUtils.cp_r(File.join(go_directory, "javascript"), FDot::Based.f_dot_space_path)
|
|
153
|
+
|
|
154
|
+
puts "ensure .f_dot/stylesheets directory exists:"
|
|
155
|
+
puts "(#{File.join(go_directory, "stylesheets")}, #{FDot::Based.f_dot_space_path})"
|
|
156
|
+
FileUtils.cp_r(File.join(go_directory, "stylesheets"), FDot::Based.f_dot_space_path)
|
|
157
|
+
|
|
158
|
+
if File.exist?(self.class.path_for_file(:f_dot_go))
|
|
159
|
+
FileUtils.rm_rf(self.class.path_for_file(:f_dot_go))
|
|
160
|
+
FileUtils.rm_rf("#{self.class.path_for_file(:f_dot_go)}.log")
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
puts "system(go build -o #{self.class.path_for_file(:f_dot_go)} #{go_file_path})"
|
|
164
|
+
system("go build -C #{go_directory} -o #{self.class.path_for_file(:f_dot_go)} #{go_file_path}")
|
|
165
|
+
|
|
166
|
+
raise "failed to build #{self.class.path_for_file(:f_dot_go)}!" unless File.exist?(self.class.path_for_file(:f_dot_go))
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def self.path_for_file(cubicus_file_key)
|
|
170
|
+
cubicus_file_key = cubicus_file_key.to_sym
|
|
171
|
+
raise "invalid cubicus_file_key!" unless FDot::Based::Cubicus::VALID_KEYS.include?(cubicus_file_key)
|
|
172
|
+
|
|
173
|
+
File.join(FDot::Based.f_dot_space_path, cubicus_file_key.to_s)
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
end
|
data/lib/f_dot/history.rb
CHANGED
|
@@ -78,14 +78,15 @@ module FDot
|
|
|
78
78
|
puts "opening history #(#{self.timestamp})"
|
|
79
79
|
puts self.to_s
|
|
80
80
|
while interface_open
|
|
81
|
-
|
|
81
|
+
FDot::Based.tty_prompt_select(
|
|
82
82
|
"viewing historical_instance #{historical_instance.to_s}",
|
|
83
83
|
[{name: :back, value: :back}] + historical_instance.history_menu_options
|
|
84
|
-
)
|
|
84
|
+
) {|historical_attribute|
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
return if historical_attribute == :back
|
|
87
87
|
|
|
88
|
-
|
|
88
|
+
puts historical_instance.send(historical_attribute)
|
|
89
|
+
}
|
|
89
90
|
end
|
|
90
91
|
end
|
|
91
92
|
|
data/lib/f_dot/instruction.rb
CHANGED
|
@@ -66,13 +66,13 @@ module FDot
|
|
|
66
66
|
:ordinal,
|
|
67
67
|
:compiled_domain,
|
|
68
68
|
:compiler_variable_uuid
|
|
69
|
-
].
|
|
69
|
+
].map{|attribute|
|
|
70
70
|
implementation_notes = ""
|
|
71
71
|
if [:compiled_domain, :compiler_variable_uuid].include?(attribute)
|
|
72
|
-
implementation_notes = "todo: #{attribute} is not implemented."
|
|
72
|
+
implementation_notes = " (todo: #{attribute} is not implemented.)"
|
|
73
73
|
end
|
|
74
74
|
{
|
|
75
|
-
name: "#{attribute}
|
|
75
|
+
name: "#{attribute}#{implementation_notes}",
|
|
76
76
|
value: attribute
|
|
77
77
|
}
|
|
78
78
|
}
|
data/lib/f_dot/interface.rb
CHANGED
|
@@ -15,6 +15,12 @@ module FDot
|
|
|
15
15
|
class Interface
|
|
16
16
|
include Singleton
|
|
17
17
|
|
|
18
|
+
attr_accessor :display_mode
|
|
19
|
+
|
|
20
|
+
def initialize
|
|
21
|
+
self.display_mode = FDot::DISPLAY_MODES[:terminal]
|
|
22
|
+
end
|
|
23
|
+
|
|
18
24
|
def self.get_variable_uuid_from_file(variable_file_path)
|
|
19
25
|
raise "invalid variable_file_path! #{variable_file_path}" unless File.exist?(variable_file_path)
|
|
20
26
|
variable_uuid = nil
|
|
@@ -36,7 +42,9 @@ module FDot
|
|
|
36
42
|
# get listing for path and return sorted tty-prompt options
|
|
37
43
|
[{name: :f_dot_main_menu, value: :f_dot_main_menu}] + Dir[
|
|
38
44
|
File.join(folder_path, "*")
|
|
39
|
-
].
|
|
45
|
+
].select{|d|
|
|
46
|
+
!FDot::Based::Cubicus::VALID_KEYS.any?{|n| File.basename(d).include?(n.to_s)}
|
|
47
|
+
}.map{|d|
|
|
40
48
|
{name: File.basename(d), value: d}
|
|
41
49
|
}.sort_by{|o|
|
|
42
50
|
sorters = [o[:name]]
|
|
@@ -59,50 +67,62 @@ module FDot
|
|
|
59
67
|
def self.show_main_menu!
|
|
60
68
|
main_menu_open = true
|
|
61
69
|
while main_menu_open
|
|
62
|
-
|
|
70
|
+
FDot::Based.tty_prompt_select(
|
|
63
71
|
"f_dot_main_menu =>",
|
|
64
72
|
self.main_menu_options.map{|k|
|
|
65
73
|
{name: k, value: k}
|
|
66
74
|
}
|
|
67
|
-
)
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
75
|
+
) {|user_selection|
|
|
76
|
+
case user_selection
|
|
77
|
+
when :resume_program
|
|
78
|
+
main_menu_open = false
|
|
79
|
+
when :startup_notes
|
|
80
|
+
puts FDot::Based::Program.startup_notes
|
|
81
|
+
when :open_history
|
|
82
|
+
FDot.state[:program].show_history_interface!
|
|
83
|
+
when :open_settings
|
|
84
|
+
FDot::Based::Processor.show_settings_menu!
|
|
85
|
+
when :close_program
|
|
86
|
+
FDot::Based.tty_prompt_select(
|
|
87
|
+
"are you sure?",
|
|
88
|
+
[{name: :back, value: :back}, {name: :i_am_sure, value: :i_am_sure}]
|
|
89
|
+
){|v|
|
|
90
|
+
if v == :i_am_sure
|
|
91
|
+
main_menu_open = false
|
|
92
|
+
FDot::Based::Processor.user_exited!
|
|
93
|
+
end
|
|
94
|
+
}
|
|
95
|
+
end
|
|
96
|
+
}
|
|
84
97
|
end
|
|
85
98
|
end
|
|
86
99
|
|
|
100
|
+
def self.compiler_file_path
|
|
101
|
+
File.join(
|
|
102
|
+
FDot::Based.f_dot_space_path,
|
|
103
|
+
:compiler.to_s
|
|
104
|
+
)
|
|
105
|
+
end
|
|
106
|
+
|
|
87
107
|
def self.reconfigure_user_space!
|
|
88
108
|
# clear user space
|
|
89
|
-
|
|
109
|
+
Dir[File.join(FDot::Based.f_dot_space_path, "*")].each{|f|
|
|
110
|
+
FileUtils.rm_rf(f) unless FDot::Based::Cubicus::VALID_KEYS.any?{|n| File.basename(f).include?(n.to_s)}
|
|
111
|
+
}
|
|
90
112
|
|
|
91
113
|
# build program data
|
|
92
114
|
FDot.state[:program].build_space!
|
|
93
115
|
|
|
94
116
|
# write user space
|
|
95
|
-
compiler_file_path = File.join(
|
|
96
|
-
FDot::Based.f_dot_space_path,
|
|
97
|
-
:compiler.to_s
|
|
98
|
-
)
|
|
99
|
-
|
|
100
117
|
compiler_data = FDot.state[:program].compiler_contents
|
|
101
118
|
compiler_data[:variables] = compiler_data[:variables].sort
|
|
102
119
|
compiler_data[:instructions] = compiler_data[:instructions].sort
|
|
103
|
-
|
|
120
|
+
temp_compiler_file_path = "#{self.compiler_file_path}_temp"
|
|
121
|
+
File.open(temp_compiler_file_path, "w") do |f|
|
|
104
122
|
f.write(compiler_data.to_json)
|
|
123
|
+
f.fsync
|
|
105
124
|
end
|
|
125
|
+
FileUtils.mv(temp_compiler_file_path, self.compiler_file_path)
|
|
106
126
|
|
|
107
127
|
unless FDot.state[:based_uuid].nil?
|
|
108
128
|
# write based variable file
|
|
@@ -113,10 +133,11 @@ module FDot
|
|
|
113
133
|
FDot::Based.f_dot_space_path,
|
|
114
134
|
based_variable.to_s
|
|
115
135
|
)
|
|
116
|
-
File.open(based_file_path, "w
|
|
136
|
+
File.open(based_file_path, "w") do |f|
|
|
117
137
|
f.write({
|
|
118
138
|
uuid: based_variable.uuid
|
|
119
139
|
}.to_json)
|
|
140
|
+
f.fsync
|
|
120
141
|
end
|
|
121
142
|
end
|
|
122
143
|
|
|
@@ -137,29 +158,31 @@ module FDot
|
|
|
137
158
|
)
|
|
138
159
|
|
|
139
160
|
# write variable identifier into variable file
|
|
140
|
-
File.open(variable_file_path, "w
|
|
161
|
+
File.open(variable_file_path, "w") do |f|
|
|
141
162
|
f.write({
|
|
142
163
|
uuid: v
|
|
143
164
|
}.to_json)
|
|
165
|
+
f.fsync
|
|
144
166
|
end
|
|
145
167
|
}
|
|
146
168
|
}
|
|
147
169
|
|
|
148
170
|
# write processor domain folders
|
|
149
171
|
processor_file_path = File.join(FDot::Based.f_dot_space_path, :processor.to_s)
|
|
150
|
-
File.open(processor_file_path, "w
|
|
172
|
+
File.open(processor_file_path, "w") do |f|
|
|
151
173
|
f.write({
|
|
152
174
|
variables: FDot.state[:f_dot_queue],
|
|
153
175
|
instructions: FDot.state[:instructions]
|
|
154
176
|
}.to_json)
|
|
177
|
+
f.fsync
|
|
155
178
|
end
|
|
156
179
|
|
|
157
180
|
# write processor serialized_state file
|
|
158
181
|
serialized_state_file_path = File.join(FDot::Based.f_dot_space_path, "processor_state.json")
|
|
159
|
-
File.open(serialized_state_file_path, "w
|
|
182
|
+
File.open(serialized_state_file_path, "w") do |f|
|
|
160
183
|
f.write(FDot::Based::Processor.instance.serialized_state.to_json)
|
|
184
|
+
f.fsync
|
|
161
185
|
end
|
|
162
|
-
|
|
163
186
|
return true
|
|
164
187
|
end
|
|
165
188
|
|