mirror of
https://github.com/NixOS/nix
synced 2025-06-25 06:31:14 +02:00
Pretty-print values in the REPL
Pretty-print values in the REPL by printing each item in a list or attrset on a separate line. When possible, single-item lists and attrsets are printed on one line, as long as they don't contain a nested list, attrset, or thunk. Before: ``` { attrs = { a = { b = { c = { }; }; }; }; list = [ 1 ]; list' = [ 1 2 3 ]; } ``` After: ``` { attrs = { a = { b = { c = { }; }; }; }; list = [ 1 ]; list' = [ 1 2 3 ]; } ```
This commit is contained in:
parent
a31f2cb0cd
commit
c0a15fb7d0
6 changed files with 195 additions and 23 deletions
|
@ -146,29 +146,86 @@ echo "$replResult" | grepQuiet -s afterChange
|
|||
# Normal output should print attributes in lexicographical order non-recursively
|
||||
testReplResponseNoRegex '
|
||||
{ a = { b = 2; }; l = [ 1 2 3 ]; s = "string"; n = 1234; x = rec { y = { z = { inherit y; }; }; }; }
|
||||
' '{ a = { ... }; l = [ ... ]; n = 1234; s = "string"; x = { ... }; }'
|
||||
' \
|
||||
'{
|
||||
a = { ... };
|
||||
l = [ ... ];
|
||||
n = 1234;
|
||||
s = "string";
|
||||
x = { ... };
|
||||
}
|
||||
'
|
||||
|
||||
# Same for lists, but order is preserved
|
||||
testReplResponseNoRegex '
|
||||
[ 42 1 "thingy" ({ a = 1; }) ([ 1 2 3 ]) ]
|
||||
' '[ 42 1 "thingy" { ... } [ ... ] ]'
|
||||
' \
|
||||
'[
|
||||
42
|
||||
1
|
||||
"thingy"
|
||||
{ ... }
|
||||
[ ... ]
|
||||
]
|
||||
'
|
||||
|
||||
# Same for let expressions
|
||||
testReplResponseNoRegex '
|
||||
let x = { y = { a = 1; }; inherit x; }; in x
|
||||
' '{ x = «repeated»; y = { ... }; }'
|
||||
' \
|
||||
'{
|
||||
x = { ... };
|
||||
y = { ... };
|
||||
}
|
||||
'
|
||||
|
||||
# The :p command should recursively print sets, but prevent infinite recursion
|
||||
testReplResponseNoRegex '
|
||||
:p { a = { b = 2; }; s = "string"; n = 1234; x = rec { y = { z = { inherit y; }; }; }; }
|
||||
' '{ a = { b = 2; }; n = 1234; s = "string"; x = { y = { z = { y = «repeated»; }; }; }; }'
|
||||
' \
|
||||
'{
|
||||
a = { b = 2; };
|
||||
n = 1234;
|
||||
s = "string";
|
||||
x = {
|
||||
y = {
|
||||
z = {
|
||||
y = «repeated»;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
'
|
||||
|
||||
# Same for lists
|
||||
testReplResponseNoRegex '
|
||||
:p [ 42 1 "thingy" (rec { a = 1; b = { inherit a; inherit b; }; }) ([ 1 2 3 ]) ]
|
||||
' '[ 42 1 "thingy" { a = 1; b = { a = 1; b = «repeated»; }; } [ 1 2 3 ] ]'
|
||||
' \
|
||||
'[
|
||||
42
|
||||
1
|
||||
"thingy"
|
||||
{
|
||||
a = 1;
|
||||
b = {
|
||||
a = 1;
|
||||
b = «repeated»;
|
||||
};
|
||||
}
|
||||
[
|
||||
1
|
||||
2
|
||||
3
|
||||
]
|
||||
]
|
||||
'
|
||||
|
||||
# Same for let expressions
|
||||
testReplResponseNoRegex '
|
||||
:p let x = { y = { a = 1; }; inherit x; }; in x
|
||||
' '{ x = «repeated»; y = { a = 1; }; }'
|
||||
' \
|
||||
'{
|
||||
x = «repeated»;
|
||||
y = { a = 1 };
|
||||
}
|
||||
'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue