Module: Fatty::Config

Defined in:
lib/fatty/config.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.dirObject

Returns the value of attribute dir.



8
9
10
# File 'lib/fatty/config.rb', line 8

def dir
  @dir
end

.prognameObject

Returns the value of attribute progname.



6
7
8
# File 'lib/fatty/config.rb', line 6

def progname
  @progname
end

.readerObject

Returns the value of attribute reader.



7
8
9
# File 'lib/fatty/config.rb', line 7

def reader
  @reader
end

Class Method Details

.configObject

Read in the general configuration for fatty in config.yml for certain user-adjustable features of fatty. One of these is the logging, including the location of the log file.



18
19
20
21
# File 'lib/fatty/config.rb', line 18

def self.config
  @reader ||= FatConfig::Reader.new(progname, user_dir: dir)
  @config = reader.read('config')
end

.default_user_path(name = 'config') ⇒ Object



60
61
62
# File 'lib/fatty/config.rb', line 60

def self.default_user_path(name = 'config')
  "~/.config/#{progname}/#{name}.yml"
end

.install_default_themes!Object



76
77
78
79
80
81
82
83
84
# File 'lib/fatty/config.rb', line 76

def self.install_default_themes!
  FileUtils.mkdir_p(user_themes_dir)

  Dir.glob(File.join(sys_themes_dir, "*.yml")).each do |src|
    dst = File.join(user_themes_dir, File.basename(src))
    FileUtils.cp(src, dst) unless File.exist?(dst)
  end
  nil
end

.keybindingsObject

Read in the keybindings.yml config file that maps key names (together with any modifiers, shift, ctrl, meta) to action names to be triggered by the key chord.



52
53
54
55
56
57
58
# File 'lib/fatty/config.rb', line 52

def self.keybindings
  kb_cfg = FatConfig::Reader.new(progname).read("keybindings")
  return [] unless kb_cfg.is_a?(Hash)

  bindings = kb_cfg[:keybindings]
  Array(bindings)
end

.keydefsObject

Read in the keydefs.yml config file that maps numeric keycodes returned by curses but not assigned a key name.



45
46
47
# File 'lib/fatty/config.rb', line 45

def self.keydefs
  FatConfig::Reader.new(progname).read('keydefs')
end

.sys_themes_dirObject



64
65
66
# File 'lib/fatty/config.rb', line 64

def self.sys_themes_dir
  File.expand_path("config_files/themes", __dir__)
end

.user_config_dirObject



68
69
70
# File 'lib/fatty/config.rb', line 68

def self.user_config_dir
  dir || File.join(ENV.fetch("XDG_CONFIG_HOME", File.expand_path("~/.config")), progname)
end

.user_config_pathObject



28
29
30
31
# File 'lib/fatty/config.rb', line 28

def self.user_config_path
  @reader ||= FatConfig::Reader.new(progname, user_dir: dir)
  reader.config_paths[:user].first || default_user_path('config')
end

.user_keybindings_pathObject



38
39
40
41
# File 'lib/fatty/config.rb', line 38

def self.user_keybindings_path
  self.reader ||= FatConfig::Reader.new(progname)
  reader.config_paths('keybindings')[:user].first || default_user_path('keybindings')
end

.user_keydefs_pathObject



33
34
35
36
# File 'lib/fatty/config.rb', line 33

def self.user_keydefs_path
  @reader ||= FatConfig::Reader.new(progname)
  reader.config_paths('keydefs')[:user].first || default_user_path('keydefs')
end

.user_themes_dirObject



72
73
74
# File 'lib/fatty/config.rb', line 72

def self.user_themes_dir
  File.join(user_config_dir, "themes")
end