generators.toKDL: support repeated nodes, break JiK compat
Replaces the list attr -> KDL conversion logic with a more flexible approach, allowing for multiple nodes with the same name in a scope. This unfortunately also breaks the existing JSON-in-KDL semantics in favor of ergonomics. As far as I can tell though, zellij is the only program using it, and it doesn't accept JiK anyway. For example, the following KDL was previously impossible to generate, since nix attrs were mapped 1:1 to KDL nodes: ``` resize { bind "k" "Up" { Resize "Increase Up"; } bind "j" "Down" { Resize "Increase Down"; } } ``` Now, this can be achieved with the nix expression: ``` resize.bind = [ { _args = ["k" "Up"]; Resize = "Increase Up"; } { _args = ["j" "Down"]; Resize = "Increase Down"; } ]; ``` which would previously have generated the not-very-useful: ``` resize { bind { - "k" "Up" { Resize "Increase Up"; } - "j" "Down" { Resize "Increase Down"; } } } ``` which, in turn, can now be generated via: ``` resize.bind."-" = [ { _args = ["k" "Up"]; Resize = "Increase Up"; } { _args = ["j" "Down"]; Resize = "Increase Down"; } ]; ```
This commit is contained in:
parent
1c43dcfac4
commit
7c8bf29df3
|
@ -68,10 +68,8 @@
|
||||||
in "${name} ${concatStringsSep " " flatElements}";
|
in "${name} ${concatStringsSep " " flatElements}";
|
||||||
|
|
||||||
# String -> ListOf Anything -> String
|
# String -> ListOf Anything -> String
|
||||||
convertListOfNonFlatAttrsToKDL = name: list: ''
|
convertListOfNonFlatAttrsToKDL = name: list:
|
||||||
${name} {
|
"${concatStringsSep "\n" (map (x: convertAttributeToKDL name x) list)}";
|
||||||
${indentStrings (map (x: convertAttributeToKDL "-" x) list)}
|
|
||||||
}'';
|
|
||||||
|
|
||||||
# String -> ListOf Anything -> String
|
# String -> ListOf Anything -> String
|
||||||
convertListToKDL = name: list:
|
convertListToKDL = name: list:
|
||||||
|
|
|
@ -27,15 +27,11 @@ listInAttrsInList {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
list2 {
|
list2 {
|
||||||
- {
|
|
||||||
a 8
|
a 8
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
repeated 1 2
|
||||||
nested {
|
repeated true false
|
||||||
- 1 2
|
repeated
|
||||||
- true false
|
repeated null
|
||||||
-
|
|
||||||
- null
|
|
||||||
}
|
|
||||||
unsafeString " \" \n "
|
unsafeString " \" \n "
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
''
|
''
|
||||||
null
|
null
|
||||||
];
|
];
|
||||||
nested = [ [ 1 2 ] [ true false ] [ ] [ null ] ];
|
repeated = [ [ 1 2 ] [ true false ] [ ] [ null ] ];
|
||||||
extraAttrs = {
|
extraAttrs = {
|
||||||
_args = [ 2 true ];
|
_args = [ 2 true ];
|
||||||
_props = {
|
_props = {
|
||||||
|
@ -33,12 +33,12 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
listInAttrsInList = {
|
listInAttrsInList = {
|
||||||
list1 = [
|
list1."-" = [
|
||||||
{ a = 1; }
|
{ a = 1; }
|
||||||
{ b = true; }
|
{ b = true; }
|
||||||
{
|
{
|
||||||
c = null;
|
c = null;
|
||||||
d = [{ e = "asdfadfasdfasdf"; }];
|
d."-" = [{ e = "asdfadfasdfasdf"; }];
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
list2 = [{ a = 8; }];
|
list2 = [{ a = 8; }];
|
||||||
|
|
Loading…
Reference in a new issue