Module: Drakkon::Run
- Extended by:
- PlatformCompat
- Defined in:
- lib/drakkon/run.rb,
lib/drakkon/run/tty.rb,
lib/drakkon/run/helpers.rb,
lib/drakkon/run/commands/log.rb,
lib/drakkon/run/commands/utils.rb,
lib/drakkon/run/commands/images.rb,
lib/drakkon/run/commands/restart.rb
Overview
Defined Under Namespace
Modules: Commands
Class Method Summary
collapse
build_env, path_divider, run_env, windows?
Class Method Details
.args(raw = []) ⇒ Object
38
39
40
41
42
|
# File 'lib/drakkon/run/helpers.rb', line 38
def self.args(raw = [])
@args ||= raw
@args
end
|
.back ⇒ Object
91
92
93
94
|
# File 'lib/drakkon/run/tty.rb', line 91
def self.back
raise Interrupt
end
|
.build_index ⇒ Object
11
12
13
14
15
|
# File 'lib/drakkon/run/helpers.rb', line 11
def self.build_index
Commands.public_methods.select { |x| x.to_s[0..3] == 'cmd_' }.map do |cmd|
cmd.to_s.gsub('cmd_', '')
end
end
|
.cli ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/drakkon/run/tty.rb', line 22
def self.cli
Commands.send(:cmd_tail, [])
value ||= ''
loop do
line = reader.read_line(readline_notch, value: value)
value = ''
if reader.breaker
value = line
puts ''
next
end
break if line =~ /^exit/i
process
run
end
end
|
.context ⇒ Object
Helper for external access
35
36
37
38
39
|
# File 'lib/drakkon/run.rb', line 35
def self.context
@context ||= Dir.pwd
@context
end
|
.cursor ⇒ Object
104
105
106
107
108
|
# File 'lib/drakkon/run/tty.rb', line 104
def self.cursor
@cursor ||= TTY::Cursor
@cursor
end
|
.dragonruby(value = nil) ⇒ Object
No longer used def self.log_file
"#{Hub.dir}/log.txt"
end
32
33
34
35
36
|
# File 'lib/drakkon/run/helpers.rb', line 32
def self.dragonruby(value = nil)
@dragonruby ||= value
@dragonruby
end
|
.force_fonts? ⇒ Boolean
56
57
58
|
# File 'lib/drakkon/run/helpers.rb', line 56
def self.force_fonts?
args.include?('fonts')
end
|
.force_images? ⇒ Boolean
48
49
50
|
# File 'lib/drakkon/run/helpers.rb', line 48
def self.force_images?
args.include?('images')
end
|
.force_manifest? ⇒ Boolean
52
53
54
|
# File 'lib/drakkon/run/helpers.rb', line 52
def self.force_manifest?
args.include?('manifest')
end
|
.force_sounds? ⇒ Boolean
60
61
62
|
# File 'lib/drakkon/run/helpers.rb', line 60
def self.force_sounds?
args.include?('sounds')
end
|
.go!(raw) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/drakkon/run.rb', line 5
def self.go!(raw)
Settings.ready?
Settings.check_version!
args(raw)
@context = Dir.pwd
run_setup
watcher!
Dir.chdir(version_dir) do
runtime
cli
end
rescue SystemExit, Interrupt
LogBot.info('Run', 'Exiting')
puts
exit
ensure
Process.kill('TERM', dragonruby&.pid) if dragonruby
watcher&.kill
end
|
.index ⇒ Object
6
7
8
9
|
# File 'lib/drakkon/run/helpers.rb', line 6
def self.index
@index ||= build_index
@index
end
|
.logs ⇒ Object
110
111
112
113
114
|
# File 'lib/drakkon/run/tty.rb', line 110
def self.logs
@logs ||= []
@logs
end
|
.process ⇒ Object
Auto/Run Process - Populate and parse: @list
97
98
99
100
101
102
|
# File 'lib/drakkon/run/tty.rb', line 97
def self.process
line = reader.line
@list = Shellwords.split line.text
rescue StandardError => e
puts "#{'Invalid Command'.pastel(:red)}: #{e.message.pastel(:green)}"
end
|
.prompt ⇒ Object
64
65
66
|
# File 'lib/drakkon/run/helpers.rb', line 64
def self.prompt
TTY::Prompt.new(active_color: :cyan, interrupt: :exit)
end
|
.reader ⇒ Object
45
46
47
|
# File 'lib/drakkon/run/tty.rb', line 45
def self.reader
@reader ||= reader_setup
end
|
.reader_setup ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/drakkon/run/tty.rb', line 49
def self.reader_setup
reader = TTY::Reader.new(history_duplicates: false, interrupt: -> { back })
reader.add_to_history ''
reader.on(:keyctrl_u) do |_event|
reader.line.remove reader.line.text.size
end
reader.on(:keyctrl_left) { reader.line.move_word_left }
reader.on(:keyctrl_right) { reader.line.move_word_right }
reader.on(:keyctrl_a) { reader.line.move_to_start }
reader.on(:keyctrl_e) { reader.line.move_to_end }
reader.on(:keyback_tab) { back }
reader.instance_variable_get(:@history)
reader.on(:keyctrl_p) do |event|
binding.pry
end
reader
end
|
.readline_notch ⇒ Object
17
18
19
|
# File 'lib/drakkon/run/helpers.rb', line 17
def self.readline_notch
"#{'drakkon'.pastel(:bright_black)} » "
end
|
.restart ⇒ Object
76
77
78
79
|
# File 'lib/drakkon/run.rb', line 76
def self.restart
Process.kill('TERM', dragonruby&.pid)
runtime
end
|
.run ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/drakkon/run/tty.rb', line 5
def self.run
return true if @list.empty?
cmd = @list.shift
if index.include? cmd
Commands.send(:"cmd_#{cmd}", @list)
else
puts "Unknown Command: '#{cmd.pastel(:red)}'"
puts
puts "Available Commands: #{index.join(', ').pastel(:green)}"
end
rescue StandardError => e
LogBot.fatal('CLI Run', e.message)
puts e.backtrace[0..4].join("\n").pastel(:red)
end
|
.run_cmd ⇒ Object
Exec skips the weird shell stuff
22
23
24
25
|
# File 'lib/drakkon/run/helpers.rb', line 22
def self.run_cmd
['./dragonruby', @context, *args]
end
|
.runtime ⇒ Object
72
73
74
|
# File 'lib/drakkon/run.rb', line 72
def self.runtime
@dragonruby = IO.popen(run_env, run_cmd)
end
|
.version_dir ⇒ Object
44
45
46
|
# File 'lib/drakkon/run/helpers.rb', line 44
def self.version_dir
"#{Hub.dir}/#{Settings.version}"
end
|
.watcher ⇒ Object
45
46
47
|
# File 'lib/drakkon/run.rb', line 45
def self.watcher
@watcher
end
|
.watcher! ⇒ Object
41
42
43
|
# File 'lib/drakkon/run.rb', line 41
def self.watcher!
@watcher = Thread.new { watch }
end
|