Toqozz / wired-notify

Lightweight notification daemon with highly customizable layout blocks, written in Rust.
MIT License
608 stars 28 forks source link

Allow including configuration files or Block template Inheritance #81

Open lukelex opened 2 years ago

lukelex commented 2 years ago

I'm in the process of adding a third notification type, and in doing so, I've found myself duplicating a lot more code than ideal, and the file configuration is 300+ lines long. So it's getting a bit unwieldy.

Have you considered either one or both of the following?

mod SystemNotification();
mod AppNotification();
...
(
...
  layout_blocks: [
    SystemNotification(),
    AppNotification()
  ]
)
let GenericTextBlock = TextBlock((
  text: "%s",
  font: "Arial Bold 16",
  ellipsize: End,
  color: Color(hex: "#000000"),
  padding: Padding(left: 8, right: 8, top: 8, bottom: 8),
)),
...
(
  name: "status_notification",
  parent: "status_root",
  hook: Hook(parent_anchor: TL, self_anchor: TL),
  offset: Vec2(x: 0, y: 0),
  params: GenericTextBlock(
    dimensions: (width: (min: 400, max: 400), height: (min: 84, max: 0))
  )
),
Toqozz commented 2 years ago

I agree, the config can get pretty unwieldy. I like these ideas, thanks!

The config format we're using doesn't automagically support either of these, but:

layout_blocks: [ ... ( name: "summary", parent: "image", hook: Hook(parent_anchor: MR, self_anchor: BL), offset: Vec2(x: 0.0, y: 0.0), params: "normal_text", ), ]



Which isn't ideal, and doesn't solve the real problem where you want templates but want to be able to override some of the fields.

Being able to override fields would probably require some craziness to support ergonomically.

---

A cheap way to support "importing" may be for Wired to just additively pull in configs in the same directory with some prefix -- e.g. you'd have your "main" config `wired.ron` with the base settings and then `wired_*.ron` (like, `wired_system.ron` or `wired_app.ron`) would be your other layouts.  The only downside I see here is that maybe it's a bit confusing if someone has like `wired_bak.ron` and it's being loaded because of this system.
lukelex commented 2 years ago

We could probably add some kind of rudimentary "import" without that much trouble.

This would already go a long way tbh.

A cheap way to support "importing" may be for Wired to just additively pull in configs in the same directory with some prefix -- e.g. you'd have your "main" config wired.ron with the base settings and then wired_*.ron (like, wired_system.ron or wired_app.ron) would be your other layouts. The only downside I see here is that maybe it's a bit confusing if someone has like wired_bak.ron and it's being loaded because of this system.

What if wired only tried to load these files if they are specified somewhere in wired.ron?

Toqozz commented 2 years ago

What if wired only tried to load these files if they are specified somewhere in wired.ron?

That's an option, will have to thinkt further about details of implementing that.

Toqozz commented 2 years ago

I recently came across https://github.com/wez/wezterm, which does configuration in a lua file. Basically, you can run any lua code you like, then export the config in a return block, e.g.:

local wezterm = require 'wezterm'
local prog
local font

if wezterm.target_triple == 'x86_64-pc-windows-msvc' then
  prog = { 'pwsh.exe' }
  font = 'JetBrains Mono'
end
if wezterm.target_triple == 'x86_64-unknown-linux-gnu' then
  prog = { 'zsh' }
  font = 'JetBrains Mono'
end
return {
  enable_tab_bar = false,
  default_prog = prog,
  window_background_opacity = 1,
  tab_bar_at_bottom = true,
  font = wezterm.font_with_fallback {
    font,
  },
  font_size = 11.0,
  color_scheme = "Nord (base16)",
  keys = {
    {
      key = 'RightArrow', mods = 'CTRL',
      action = wezterm.action.SplitHorizontal { domain = 'CurrentPaneDomain' },
    },
    {
      key = 'DownArrow', mods = 'CTRL',
      action = wezterm.action.SplitVertical { domain = 'CurrentPaneDomain' },
    }
  },
}

I think this is pretty much the direction to go in. We may even be able to move the notification criteria stuff into that as well.

BeyondMagic commented 2 years ago

Hopefully you follow with it! Lua is a really good choice to make configurations!