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

Replace yaml with KDL #771

Closed
imsnif opened this issue Oct 7, 2021 · 6 comments
Closed

Replace yaml with KDL #771

imsnif opened this issue Oct 7, 2021 · 6 comments
Labels
config Improvements to the configuration system discussion Conversation to figure out actionable steps. Most feature ideas start here. layout issues related to the layout system
Milestone

Comments

@imsnif
Copy link
Member

imsnif commented Oct 7, 2021

KDL is a new document language that supports nesting, custom type annotations and more. It is Human-readable, easy to pick up and is actively maintained through a living specification.

A Zellij layout KDL configuration might look something like this:

layout "template" {
  direction "Horizontal"
  parts {
    layout {
      direction "Vertical"
      borderless true
      split_size Fixed=1
      run plugin=true location="zellij:tab-bar"
    }
    layout "body" {
      direction "Vertical"
    }
    layout {
      direction "Vertical"
      borderless true
      split_size Fixed=2
      run plugin=true location="zellij:status-bar"
    }
  }
}

layout "tabs" {
  direction "Vertical"
}

A Zellij configuration might look something like this:

keybinds unbind=true {
  normal {
    action SwitchToMode="Locked" key {
       Ctrl "g"
    }
    action SwitchToMode="Pane" key {
      Ctrl "p"
    }
    action SwitchToMode="Resize" key {
      Ctrl "n"
    }
    action SwitchToMode="Tab" key {
      Ctrl "t"
    }
    action SwitchToMode="Scroll" key {
      Ctrl "s"
    }
    action SwitchToMode="Session" key {
      Ctrl "o"
    }
    action Quit key {
      Ctrl "q"
    }
    action NewPane key {
       Alt "n"
    }
    action MoveFocusOrTab="Left" key {
       Alt "h"
    }
    action MoveFocusOrTab="Right" key {
       Alt "l"
    }
    action MoveFocus="Down" key {
       Alt "j"
    }
    action MoveFocus="Up" key {
       Alt "k"
    }
    action FocusPreviousPane key {
       Alt "["
    }
    action FocusNextPane key {
       Alt "]"
    }
  }
  locked {
    action SwitchToMode="Normal" key {
      Ctrl "g"
    }
  }
  // ... (yes, it supports comments!!)
}

The only blocker I see right now is that there is no Serde support, but it looks like it's in the works: kdl-org/kdl-rs#17

Would love to hear thoughts on this. Pinging some people of interest (though I'd love to hear anyone's take on this!) @a-kenji , @TheLostLambda, @spacemaison

@imsnif imsnif added the discussion Conversation to figure out actionable steps. Most feature ideas start here. label Oct 7, 2021
@TheLostLambda
Copy link
Member

Whoa, in my email notifications I didn't see that you'd been the one to open this issue, @imsnif !

In short, I vastly, vastly prefer KDL to YAML and would be fully on board with changing to it. The serde support is a bit of a prerequisite, obviously, but once that's in place, I'm pretty happy never looking back <3

@a-kenji a-kenji added config Improvements to the configuration system layout issues related to the layout system labels Oct 16, 2021
@tailhook
Copy link

tailhook commented Oct 20, 2021

My 2cents, feel free to ignore:

  1. I think serde for KDL will have some uglier subset of the language, like one in JSON in KDL. And nice validation with line numbers is usually bad with serde. What to you think about custom derive approach instead?
  2. I think keybindings should be reversed:
    key "Ctrl+g" {
        switch-to-mode "locked"
    }
    key "Alt+n" {
        new-pane name="Pane #$num" location="right"
    }
    key "Ctrl+b" "n" {  // tmux-like sequences can be implemented in future
        new-pane
    }

This way:

  • actions can support more than one parameter, both positional and named (not sure about CamelCase vs kebab-case, feel free to change).
  • overriding keybindings doesn't require unbinding first, just set the new action

Also note that in action FocusNextPane key { two arguments must be quoted: action "FocusNextPane" "key" {, so this kind of DSL is a little big uglier than it is in your example (only bools/numbers, node names, and property names can be unquoted in KDL).

@TheLostLambda
Copy link
Member

I strongly agree with @tailhook 's flipping of the key and action nesting. I think it's much nicer and more natural to have key "..." {... actions ...} than the other way around. It should also allow for several actions per keypress more easily!

I'm also likely playing with KDL for another project soon, so I'll see how much of a pain-point no serde really is!

@har7an
Copy link
Contributor

har7an commented Oct 25, 2022

Hello,

this is now implemented in zellij 0.32.0 and up. Enjoy your new configs!

@har7an har7an closed this as completed Oct 25, 2022
@Lilja
Copy link

Lilja commented Oct 29, 2022

If i'm allowed to put on my product-manager hat for a bit:

Can someone bring more context as to why this change was introduced? What was the issue with YAML? Why would you not use a more established configuration language that has existed for longer?

I've never heard of KDL, looking into it it doesn't look very mature or established. No syntax highlighting support for vim, to name one example.
Is YAML support expected to be removed in a future release?

@imsnif
Copy link
Member Author

imsnif commented Oct 30, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
config Improvements to the configuration system discussion Conversation to figure out actionable steps. Most feature ideas start here. layout issues related to the layout system
Projects
None yet
Development

No branches or pull requests

6 participants