Luigit
repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by admin

nugu/hypr.nu

Raw
use nugu.nu

export def json [] {
  {
    dark: (nugu dark | get palette)
    light: (nugu light | get palette)
  } | to json --indent 2
}

def q [s: string] { $'"($s)"' }

def lua-palette [p: record] {
$'    debug = (q $p.debug),
    error = (q $p.error),
    warning = (q $p.warning),
    info = (q $p.info),
    content = {
      normal = (q $p.content.normal),
      backdrop = (q $p.content.backdrop),
      accent = (q $p.content.accent),
      minor = (q $p.content.minor),
      focus = (q $p.content.focus),
      unfocus = (q $p.content.unfocus),
      important_local = (q $p.content.important_local),
      important_global = (q $p.content.important_global),
    },
    ui = {
      normal = (q $p.ui.normal),
      backdrop = (q $p.ui.backdrop),
      accent = (q $p.ui.accent),
      minor = (q $p.ui.minor),
      focus = (q $p.ui.focus),
      unfocus = (q $p.ui.unfocus),
      important_local = (q $p.ui.important_local),
      important_global = (q $p.ui.important_global),
    },'
}

export def lua [] {
  let dark = (nugu dark | get palette)
  let light = (nugu light | get palette)
  [
    'local palette = {'
    '  dark = {'
    (lua-palette $dark)
    '  },'
    '  light = {'
    (lua-palette $light)
    '  },'
    '}'
    ''
    'local M = {}'
    ''
    'function M.mode()'
    '  local path = os.getenv("HOME") .. "/.cache/nugu/mode"'
    '  local file = io.open(path, "r")'
    '  if not file then return "dark" end'
    '  local mode = file:read("*l") or "dark"'
    '  file:close()'
    '  if mode == "light" then return "light" end'
    '  return "dark"'
    'end'
    ''
    'function M.current()'
    '  return palette[M.mode()]'
    'end'
    ''
    'function M.get(mode)'
    '  return palette[mode]'
    'end'
    ''
    'function M.hex(color)'
    '  return color:gsub("#", "")'
    'end'
    ''
    'function M.rgba(color, alpha)'
    '  return "rgba(" .. M.hex(color) .. (alpha or "ff") .. ")"'
    'end'
    ''
    'function M.rgb(color)'
    '  return "rgb(" .. M.hex(color) .. ")"'
    'end'
    ''
    'return M'
    ''
  ] | str join "\n"
}