lib/generators: toSwayConf init
This commit is contained in:
parent
9b53a10f4c
commit
dd65454324
|
@ -1,6 +1,35 @@
|
||||||
{ lib }:
|
{ lib }:
|
||||||
|
|
||||||
{
|
{
|
||||||
|
toSwayConf = { outerBlock ? true, indent ? "", indentSpace ? " " }@args:
|
||||||
|
v:
|
||||||
|
let
|
||||||
|
outroSpace = "\n" + lib.strings.removeSuffix indentSpace indent;
|
||||||
|
outro = outroSpace + lib.optionalString (!outerBlock) "}";
|
||||||
|
intro = lib.optionalString (!outerBlock) ''
|
||||||
|
{
|
||||||
|
'' + indent;
|
||||||
|
|
||||||
|
innerArgs = args // {
|
||||||
|
outerBlock = false;
|
||||||
|
indent = indent + indentSpace;
|
||||||
|
};
|
||||||
|
genInner = key: value:
|
||||||
|
builtins.toString key + indentSpace
|
||||||
|
+ lib.hm.generators.toSwayConf innerArgs value;
|
||||||
|
concatItems = lib.concatStringsSep ''
|
||||||
|
|
||||||
|
${indent}'';
|
||||||
|
in if lib.isInt v || lib.isFloat v || lib.isString v then
|
||||||
|
(builtins.toString v)
|
||||||
|
else if lib.isAttrs v then
|
||||||
|
(if v == { } then
|
||||||
|
abort "toSwayConfig: empty attribute set is unsupported"
|
||||||
|
else
|
||||||
|
intro + concatItems (lib.mapAttrsToList genInner v) + outro)
|
||||||
|
else
|
||||||
|
(abort "toSwayConfig: type ${builtins.typeOf v} is unsupported");
|
||||||
|
|
||||||
toHyprconf = { attrs, indentLevel ? 0, importantPrefixes ? [ "$" ], }:
|
toHyprconf = { attrs, indentLevel ? 0, importantPrefixes ? [ "$" ], }:
|
||||||
let
|
let
|
||||||
inherit (lib)
|
inherit (lib)
|
||||||
|
|
Loading…
Reference in a new issue