Module: NA::Theme

Defined in:
lib/na/theme.rb

Class Method Summary collapse

Class Method Details

.load_theme(template: {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/na/theme.rb', line 25

def load_theme(template: {})
  # Default colorization, can be overridden with full or partial template variable
  default_template = {
    parent: '{c}',
    bracket: '{dc}',
    parent_divider: '{xw}/',
    action: '{bg}',
    project: '{xbk}',
    tags: '{m}',
    value_parens: '{m}',
    values: '{c}',
    search_highlight: '{y}',
    note: '{dw}',
    dirname: '{xdw}',
    filename: '{xb}{#eccc87}',
    prompt: '{m}',
    success: '{bg}',
    error: '{b}{#b61d2a}',
    warning: '{by}',
    debug: '{dw}',
    templates: {
      output: '%filename%parents| %action',
      default: '%parent%action',
      single_file: '%parent%action',
      multi_file: '%filename%parent%action',
      no_file: '%parent%action'
    }
  }

  # Load custom theme
  theme_file = NA.database_path(file: 'theme.yaml')
  theme = if File.exist?(theme_file)
            YAML.load(IO.read(theme_file)) || {}
          else
            {}
          end
  theme = default_template.deep_merge(theme)

  File.open(theme_file, 'w') do |f|
    f.puts template_help.comment
    f.puts YAML.dump(theme)
  end

  theme.merge(template)
end

.template_helpObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/na/theme.rb', line 6

def template_help
  <<~EOHELP
    Use {X} placeholders to apply colors. Available colors are:

    w: white, k: black, g: green, l: blue,
    y: yellow, c: cyan, m: magenta, r: red,
    W: bgwhite, K: bgblack, G: bggreen, L: bgblue,
    Y: bgyellow, C: bgcyan, M: bgmagenta, R: bgred,
    d: dark, b: bold, u: underline, i: italic, x: reset

    Multiple placeholders can be combined in a single {} pair.

    You can also use {#RGB} and {#RRGGBB} to specify hex colors.
    Add a b before the # to make the hex a background color ({b#fa0}).


  EOHELP
end