Class: Legion::TTY::Screens::Config

Inherits:
Base
  • Object
show all
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, #teardown

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.expand_path('~/.legionio/settings')
  @files = []
  @selected_file = 0
  @selected_key = 0
  @viewing_file = false
  @file_data = {}
end

Instance Method Details

#activateObject



26
27
28
# File 'lib/legion/tty/screens/config.rb', line 26

def activate
  @files = discover_config_files
end

#discover_config_filesObject



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