Skip to content

Commit

Permalink
Merge pull request #40 from gvolpe/fix/negative-number-in-tuple
Browse files Browse the repository at this point in the history
Tuples: Wrap negative number (Double) in parens
  • Loading branch information
gvolpe authored Jun 14, 2021
2 parents ddf7fe2 + f03f12f commit 4e97a05
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
2 changes: 2 additions & 0 deletions data/negative.settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[org/gnome/settings-daemon/plugins/color]
night-light-last-coordinates=(43.684199280057591, -79.347200000000001)
14 changes: 14 additions & 0 deletions output/negative.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Generated via dconf2nix: https://github.com/gvolpe/dconf2nix
{ lib, ... }:

let
mkTuple = lib.hm.gvariant.mkTuple;
in
{
dconf.settings = {
"org/gnome/settings-daemon/plugins/color" = {
night-light-last-coordinates = mkTuple [ 43.68419928005759 (-79.3472) ];
};

};
}
9 changes: 5 additions & 4 deletions src/Nix.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@ renderValue raw = Nix $ renderValue' raw <> ";"
renderValue' (I32 v) = "\"uint32 " <> T.pack (show v) <> "\""
renderValue' (I64 v) = "\"int64 " <> T.pack (show v) <> "\""
renderValue' (T x y) =
let wrapInt x | x < 0 = "(" <> T.pack (show x) <> ")"
| otherwise = T.pack $ show x
let wrapNegNumber x | x < 0 = "(" <> T.pack (show x) <> ")"
| otherwise = T.pack $ show x
mkTuple x' y' = "mkTuple [ " <> wrapNegNumber x' <> " " <> wrapNegNumber y' <> " ]"
in case (x, y) of
(I x', I y') ->
"mkTuple [ " <> wrapInt x' <> " " <> wrapInt y' <> " ]"
(I x', I y') -> mkTuple x' y'
(D x', D y') -> mkTuple x' y'
_ -> "mkTuple [ " <> renderValue' x <> " " <> renderValue' y <> " ]"
renderValue' (TL x y) = "(" <> renderValue' (T x y) <> ")"
renderValue' (L xs) =
Expand Down

0 comments on commit 4e97a05

Please sign in to comment.