Class: Legion::TTY::Screens::Config
- Inherits:
-
Base
- Object
- Base
- Legion::TTY::Screens::Config
show all
- Includes:
- Logging::Helper
- Defined in:
- lib/legion/tty/screens/config.rb
Overview
rubocop:disable Metrics/ClassLength
Constant Summary
collapse
- MASKED_PATTERNS =
%w[vault:// env://].freeze
Instance Attribute Summary
Attributes inherited from Base
#app
Instance Method Summary
collapse
Methods inherited from Base
#deactivate, #needs_input_bar?, #teardown
Constructor Details
#initialize(app, output: $stdout, config_dir: nil) ⇒ Config
Returns a new instance of Config.
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/legion/tty/screens/config.rb', line 18
def initialize(app, output: $stdout, config_dir: nil)
super(app)
@output = output
@config_dir = config_dir || File.expand_path('~/.legionio/settings')
@files = []
@selected_file = 0
@selected_key = 0
@viewing_file = false
@file_data = {}
end
|
Instance Method Details
#activate ⇒ Object
29
30
31
|
# File 'lib/legion/tty/screens/config.rb', line 29
def activate
@files = discover_config_files
end
|
#discover_config_files ⇒ Object
33
34
35
36
37
38
39
|
# File 'lib/legion/tty/screens/config.rb', line 33
def discover_config_files
return [] unless Dir.exist?(@config_dir)
Dir.glob(File.join(@config_dir, '*.json')).map do |path|
{ name: File.basename(path), path: path }
end
end
|
53
54
55
56
57
58
59
|
# File 'lib/legion/tty/screens/config.rb', line 53
def handle_input(key)
if @viewing_file
handle_file_view_input(key)
else
handle_file_list_input(key)
end
end
|
#render(_width, height) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/legion/tty/screens/config.rb', line 41
def render(_width, height)
lines = [Theme.c(:accent, ' Settings'), '']
lines += if @viewing_file
file_detail_lines(height - 4)
else
file_list_lines(height - 4)
end
hint = @viewing_file ? ' Enter=edit b=backup q=back' : ' Enter=view e=edit q=back'
lines += ['', Theme.c(:muted, hint)]
pad_lines(lines, height)
end
|