Class: Legion::TTY::Screens::Config
- 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
Instance Method Summary collapse
- #activate ⇒ Object
- #discover_config_files ⇒ Object
- #handle_input(key) ⇒ Object
-
#initialize(app, output: $stdout, config_dir: nil) ⇒ Config
constructor
A new instance of Config.
- #render(_width, height) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(app, output: $stdout, config_dir: nil) ⇒ Config
Returns a new instance of Config.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/legion/tty/screens/config.rb', line 15 def initialize(app, output: $stdout, config_dir: nil) super(app) @output = output @config_dir = config_dir || File.('~/.legionio/settings') @files = [] @selected_file = 0 @selected_key = 0 @viewing_file = false @file_data = {} end |
Instance Method Details
#activate ⇒ Object
26 27 28 |
# File 'lib/legion/tty/screens/config.rb', line 26 def activate @files = discover_config_files end |
#discover_config_files ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/legion/tty/screens/config.rb', line 30 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 |
#handle_input(key) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/legion/tty/screens/config.rb', line 50 def handle_input(key) if @viewing_file handle_file_view_input(key) else handle_file_list_input(key) end end |
#render(_width, height) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/legion/tty/screens/config.rb', line 38 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 |