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.



14
15
16
17
18
19
20
21
22
23
# File 'lib/legion/tty/screens/config.rb', line 14

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



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

def activate
  @files = discover_config_files
end

#discover_config_filesObject



29
30
31
32
33
34
35
# File 'lib/legion/tty/screens/config.rb', line 29

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



48
49
50
51
52
53
54
# File 'lib/legion/tty/screens/config.rb', line 48

def handle_input(key)
  if @viewing_file
    handle_file_view_input(key)
  else
    handle_file_list_input(key)
  end
end

#render(_width, height) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/legion/tty/screens/config.rb', line 37

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
  lines += ['', Theme.c(:muted, '  Enter=view  e=edit  q=back')]
  pad_lines(lines, height)
end