mirror of
https://github.com/NixOS/nix
synced 2025-06-28 09:31:16 +02:00
:print
strings directly in nix repl
Strings are now printed directly when evaluated by `:print`, rather than escaped. This makes it easier to debug multi-line strings or strings containing quotes, like the results of `builtins.readFile`, `lib.toShellArg`, and so on. ``` nix-repl> "cuppy\ndog\ncity" "cuppy\ndog\ncity" nix-repl> :p "cuppy\ndog\ncity" cuppy dog city ```
This commit is contained in:
parent
ac730622e8
commit
d859d6c434
1 changed files with 6 additions and 1 deletions
|
@ -542,6 +542,7 @@ ProcessLineResult NixRepl::processLine(std::string line)
|
||||||
<< " :l, :load <path> Load Nix expression and add it to scope\n"
|
<< " :l, :load <path> Load Nix expression and add it to scope\n"
|
||||||
<< " :lf, :load-flake <ref> Load Nix flake and add it to scope\n"
|
<< " :lf, :load-flake <ref> Load Nix flake and add it to scope\n"
|
||||||
<< " :p, :print <expr> Evaluate and print expression recursively\n"
|
<< " :p, :print <expr> Evaluate and print expression recursively\n"
|
||||||
|
<< " Strings are printed directly, without escaping.\n"
|
||||||
<< " :q, :quit Exit nix-repl\n"
|
<< " :q, :quit Exit nix-repl\n"
|
||||||
<< " :r, :reload Reload all files\n"
|
<< " :r, :reload Reload all files\n"
|
||||||
<< " :sh <expr> Build dependencies of derivation, then start\n"
|
<< " :sh <expr> Build dependencies of derivation, then start\n"
|
||||||
|
@ -749,7 +750,11 @@ ProcessLineResult NixRepl::processLine(std::string line)
|
||||||
else if (command == ":p" || command == ":print") {
|
else if (command == ":p" || command == ":print") {
|
||||||
Value v;
|
Value v;
|
||||||
evalString(arg, v);
|
evalString(arg, v);
|
||||||
printValue(std::cout, v);
|
if (v.type() == nString) {
|
||||||
|
std::cout << v.string_view();
|
||||||
|
} else {
|
||||||
|
printValue(std::cout, v);
|
||||||
|
}
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue