1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-30 23:19:47 +01:00

zellij: add '_name' meta-attr to KDL generator

This enables the KDL generator to serialize nodes with the same name, such as in
a Zellij config containing multiple keybindings.
This commit is contained in:
Daniel Flanagan 2023-11-09 14:49:44 -06:00
parent 6a8444467c
commit 6ba3a5ed66
No known key found for this signature in database
GPG key ID: 5B2020A0F9921EF4
4 changed files with 120 additions and 14 deletions

View file

@ -1,6 +1,4 @@
{ lib }:
{
{ lib, ... }: {
toKDL = { }:
let
inherit (lib) concatStringsSep splitString mapAttrsToList any;
@ -11,8 +9,8 @@
# Although the input of this function is a list of strings,
# the strings themselves *will* contain newlines, so you need
# to normalize the list by joining and resplitting them.
unlines = lib.splitString "\n";
lines = lib.concatStringsSep "\n";
unlines = splitString "\n";
lines = concatStringsSep "\n";
indentAll = lines: concatStringsSep "\n" (map (x: " " + x) lines);
in stringsWithNewlines: indentAll (unlines (lines stringsWithNewlines));
@ -54,10 +52,13 @@
(s: s + " ")
]);
nameString = if (attrs ? "_name") then attrs._name else name;
children =
lib.filterAttrs (name: _: !(elem name [ "_args" "_props" ])) attrs;
lib.filterAttrs (name: _: !(elem name [ "_args" "_props" "_name" ]))
attrs;
in ''
${name} ${optArgsString}${optPropsString}{
${nameString} ${optArgsString}${optPropsString}{
${indentStrings (mapAttrsToList convertAttributeToKDL children)}
}'';

View file

@ -1,12 +1,8 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.programs.zellij;
yamlFormat = pkgs.formats.yaml { };
in {
meta.maintainers = [ hm.maintainers.mainrs ];
@ -29,6 +25,17 @@ in {
{
theme = "custom";
themes.custom.fg = "#ffffff";
keybinds = {
_props = { clear-defaults = true; };
normal = [
{ _name = "bind"; _args = [ "Ctrl q" "Alt F4" ]; Quit = []; }
{ _name = "bind"; _args = [ "Alt l" ]; MoveFocusOrTab = "Right"; }
];
locked = [
{ _name = "bind"; _args = [ "Ctrl q" "Alt F4" ]; Quit = []; }
{ _name = "bind"; _args = [ "Alt l" ]; MoveFocusOrTab = "Right"; }
];
};
}
'';
description = ''

View file

@ -32,6 +32,20 @@ listInAttrsInList {
}
}
}
literalNodes {
node "arg1" "arg2" prop1=1 prop2=2 {
child1
child2
}
node "arg2" prop1=1 prop2=2 {
child1
child2
}
node "arg2" prop2=2 {
child1
child2
}
}
nested {
- 1 2
- true false
@ -39,3 +53,29 @@ nested {
- null
}
unsafeString " \" \n "
zellijExampleSettings {
keybinds clear-defaults=true {
locked {
bind "Ctrl q" "Alt F4" {
Quit
}
bind "Alt l" {
MoveFocusOrTab "Right"
}
}
normal {
bind "Ctrl q" "Alt F4" {
Quit
}
bind "Alt l" {
MoveFocusOrTab "Right"
}
}
}
theme "custom"
themes {
custom {
fg "#ffffff"
}
}
}

View file

@ -1,6 +1,4 @@
{ config, lib, ... }:
{
{ lib, ... }: {
home.file."result.txt".text = lib.hm.generators.toKDL { } {
a = 1;
b = "string";
@ -32,6 +30,35 @@
b = null;
};
};
literalNodes = [
{
_name = "node";
_args = [ "arg1" "arg2" ];
_props = {
prop1 = 1;
prop2 = 2;
};
child1 = [ ];
child2 = [ ];
}
{
_name = "node";
_args = [ "arg2" ];
_props = {
prop1 = 1;
prop2 = 2;
};
child1 = [ ];
child2 = [ ];
}
{
_name = "node";
_args = [ "arg2" ];
_props = { prop2 = 2; };
child1 = [ ];
child2 = [ ];
}
];
listInAttrsInList = {
list1 = [
{ a = 1; }
@ -43,6 +70,37 @@
];
list2 = [{ a = 8; }];
};
zellijExampleSettings = {
theme = "custom";
themes.custom.fg = "#ffffff";
keybinds = {
_props = { clear-defaults = true; };
normal = [
{
_name = "bind";
_args = [ "Ctrl q" "Alt F4" ];
Quit = [ ];
}
{
_name = "bind";
_args = [ "Alt l" ];
MoveFocusOrTab = "Right";
}
];
locked = [
{
_name = "bind";
_args = [ "Ctrl q" "Alt F4" ];
Quit = [ ];
}
{
_name = "bind";
_args = [ "Alt l" ];
MoveFocusOrTab = "Right";
}
];
};
};
};
nmt.script = ''