Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow including configuration files or Block template Inheritance #81

Open
lukelex opened this issue Jul 14, 2022 · 5 comments
Open

Allow including configuration files or Block template Inheritance #81

lukelex opened this issue Jul 14, 2022 · 5 comments

Comments

@lukelex
Copy link

lukelex commented Jul 14, 2022

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?

  • Enable splitting the block configurations into multiple files so that one could optionally have a file per type of notification;
mod SystemNotification();
mod AppNotification();
...
(
...
  layout_blocks: [
    SystemNotification(),
    AppNotification()
  ]
)
  • Add Block templates or inheritance so that params can be reused.
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
Copy link
Owner

Toqozz commented Jul 15, 2022

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:

  • We could probably add some kind of rudimentary "import" without that much trouble.
  • We could implement basic templates by just having a key value pair:
templates = {
    (
        name: "normal_text",
        block: TextBlock((
        ...
        ))
    ),
}

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
Copy link
Author

lukelex commented Jul 15, 2022

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
Copy link
Owner

Toqozz commented Jul 16, 2022

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
Copy link
Owner

Toqozz commented Nov 29, 2022

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
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants