class Barabara::Configuration

Load configuration from a file and store it as an object.

Attributes

config[R]
modules[R]
monitors[R]
session[R]

Public Class Methods

dump_default_config(path) click to toggle source
# File lib/barabara/config.rb, line 29
def self.dump_default_config(path)
  File.open(File.expand_path(path), 'w') do |f|
    f.write default_config.to_yaml
  end
end
new(config_file) click to toggle source
# File lib/barabara/config.rb, line 13
def initialize(config_file)
  @config = YAML.load_file config_file
  @modules = parse_module_list(@config['modules'])
  @session  = ENV['XDG_SESSION_DESKTOP']
  @monitors = Modules::WM.get_monitors(@session)
end

Private Class Methods

default_config() click to toggle source
# File lib/barabara/config.rb, line 52
def self.default_config
  {
    "modules" => ["Battery", "WM", "Clock", "Wttr", "Volume"],
    "colors"  => { al_winbi:   "#000000", in_framebr: "#101010",
                   in_framebg: "#565656", in_winbr:   "#454545",
                   ac_framebr: "#222222", ac_framebg: "#345F0C",
                   ac_winbr:   "#9FBC00", ac_winbo:   "#3E4A00",
                   ac_winbi:   "#3E4A00", ur_winbr:   "#FF0675",
                   se_text:    "#101010", in_text:    "#909090",
                   mi_text:    "#BCBCBC", ac_text:    "#EFEFEF" },
    "module_options" => {
      "lemonbar" => {
        name: "barabara", height: 12,
        format: "%%{S%<monitor>s}%%{l}%<tags>s%<sep>s %%{c} %<window_title>s %%{r} %<volume>s %<battery>s %<sep>s %<time>s %<sep>s %<weather>s\n",
        fonts: {
          text:   { name: "-lucy-tewi-medium-*-normal-*-11-*-*-*-*-*-*-*", offset: 0 },
          glyphs: { name: "-wuncon-siji-medium-r-normal-*-10-100-75-75-c-80-iso10646-1", offset: 0 }
        },
        snippets:   { sep: "%%{B-}%%{F%<ac_winbr>s}|%%{F-}" },
        extra_opts: ["| sh"]
      },
      "clock" => {
        "format" => "%%H%%{F%<in_text>s}:%%{F-}%%M %%{F%<in_text>s}%%Y%%{F%<mi_text>s}%%m%%{F-}%%d"
      },
      "wm"      => {
        "tag_icons" => {
          "mail"  => "", "work" => "", "web" => "",
          "im"    => "", "term" => "", "dev" => "",
          "files" => "", "doc" => "", "docs" => "",
          "misc"  => ""
        }
      },
      "battery" => { "icons" => { 'low'  => "", 'med' => "", 'high' => "", 'full' => "", 'charge' => "" } },
      "volume"  => { "icons" => { 'mute' => "", 'low' => "",  'med'  => "",  'max'  => "" } },
      "weather" => {
        "api_key" => "<YOUR API KEY HERE>", "location" => "London", "unit" => "c",
        "format"  => "%%{F%<ac_winbr>s}%<icon>s%%{F-} %<temp>s°"
      }
    }
  }
end

Public Instance Methods

colors() click to toggle source
# File lib/barabara/config.rb, line 20
def colors; @config['colors']; end
module_config(mod_name) click to toggle source
# File lib/barabara/config.rb, line 23
def module_config(mod_name)
  return {} unless module_options.key?(mod_name)

  module_options[mod_name]
end
module_options() click to toggle source
# File lib/barabara/config.rb, line 21
def module_options; @config['module_options']; end

Private Instance Methods

dump(default: false) click to toggle source
# File lib/barabara/config.rb, line 48
def dump(default: false)
  (default ? default_config : config).to_yaml
end
parse_module_list(list) click to toggle source
# File lib/barabara/config.rb, line 37
def parse_module_list(list)
  list.map do |mod|
    begin
      Object.const_get("Barabara::Modules::#{mod}")
    rescue NameError
      warn "Module \"#{mod}\" not found!"
      next
    end
  end
end