nix-super/src/libexpr
Rebecca Turner 0fa08b4516
Unify and refactor value printing
Previously, there were two mostly-identical value printers -- one in
`libexpr/eval.cc` (which didn't force values) and one in
`libcmd/repl.cc` (which did force values and also printed ANSI color
codes).

This PR unifies both of these printers into `print.cc` and provides a
`PrintOptions` struct for controlling the output, which allows for
toggling whether values are forced, whether repeated values are tracked,
and whether ANSI color codes are displayed.

Additionally, `PrintOptions` allows tuning the maximum number of
attributes, list items, and bytes in a string that will be displayed;
this makes it ideal for contexts where printing too much output (e.g.
all of Nixpkgs) is distracting. (As requested by @roberth in
https://github.com/NixOS/nix/pull/9554#issuecomment-1845095735)

Please read the tests for example output.

Future work:
- It would be nice to provide this function as a builtin, perhaps
  `builtins.toStringDebug` -- a printing function that never fails would
  be useful when debugging Nix code.
- It would be nice to support customizing `PrintOptions` members on the
  command line, e.g. `--option to-string-max-attrs 1000`.
2024-01-11 16:34:36 -08:00
..
flake getNameFromURL(): Support uppercase characters in attribute names 2023-12-22 16:35:58 +01:00
primops document fetchTree (#9258) 2023-12-10 05:16:32 +00:00
value Split up util.{hh,cc} 2023-11-05 12:20:02 -05:00
attr-path.cc Split up util.{hh,cc} 2023-11-05 12:20:02 -05:00
attr-path.hh Merge remote-tracking branch 'upstream/master' into source-path 2023-04-17 11:41:50 +02:00
attr-set.cc Don't pass Symbol by reference 2022-04-26 13:25:17 +02:00
attr-set.hh Finish converting existing comments for internal API docs (#8146) 2023-04-07 13:55:28 +00:00
eval-cache.cc Merge pull request #6236 from obsidiansystems/store-dir-config 2023-12-01 15:38:14 +01:00
eval-cache.hh Finish converting existing comments for internal API docs (#8146) 2023-04-07 13:55:28 +00:00
eval-inline.hh reduce the size of Env by one pointer 2023-12-30 18:55:13 +01:00
eval-settings.cc Add eval-system option 2023-12-14 19:04:00 -05:00
eval-settings.hh Fix segfault on infinite recursion in some cases 2023-12-29 22:16:44 -08:00
eval.cc Unify and refactor value printing 2024-01-11 16:34:36 -08:00
eval.hh Unify and refactor value printing 2024-01-11 16:34:36 -08:00
fetchurl.nix fetchurl.nix: change other use of __impure 2022-09-16 01:54:24 -07:00
function-trace.cc Revert the enum struct change 2020-06-18 22:11:26 +00:00
function-trace.hh Ensure all headers have #pragma once and are in API docs 2023-03-31 23:19:44 -04:00
gc-small-vector.hh Use boost::container::small_vector in place of VLAs 2023-11-21 20:52:27 +01:00
get-drvs.cc remove lazy-pos forceValue 2023-12-19 19:32:16 +01:00
get-drvs.hh Finish converting existing comments for internal API docs (#8146) 2023-04-07 13:55:28 +00:00
imported-drv-to-derivation.nix Move some corepkgs into the nix binary 2020-03-11 16:57:48 +01:00
json-to-value.cc return string_views from forceString* 2022-01-27 17:15:43 +01:00
json-to-value.hh Ensure all headers have #pragma once and are in API docs 2023-03-31 23:19:44 -04:00
lexer.l use custom location type in the parser 2023-12-19 19:32:16 +01:00
local.mk Only link with -pthread on Unix 2024-01-10 20:38:39 -05:00
nix-expr.pc.in Fix building with GCC 9 2023-02-10 18:38:57 +01:00
nixexpr.cc Combine AbstractPos, PosAdapter, and Pos 2024-01-08 10:59:41 -08:00
nixexpr.hh Combine AbstractPos, PosAdapter, and Pos 2024-01-08 10:59:41 -08:00
parser.y use custom location type in the parser 2023-12-19 19:32:16 +01:00
paths.cc Introduce FSInputAccessor and use it 2023-10-18 17:37:32 +02:00
primops.cc Combine AbstractPos, PosAdapter, and Pos 2024-01-08 10:59:41 -08:00
primops.hh libexpr: Reduce nonRecursiveStackReservation 2023-11-16 15:38:21 +01:00
print-options.hh Unify and refactor value printing 2024-01-11 16:34:36 -08:00
print.cc Unify and refactor value printing 2024-01-11 16:34:36 -08:00
print.hh Unify and refactor value printing 2024-01-11 16:34:36 -08:00
search-path.cc Split up util.{hh,cc} 2023-11-05 12:20:02 -05:00
search-path.hh Clean up SearchPath 2023-07-09 23:22:22 -04:00
symbol-table.hh Finish converting existing comments for internal API docs (#8146) 2023-04-07 13:55:28 +00:00
value-to-json.cc Split up util.{hh,cc} 2023-11-05 12:20:02 -05:00
value-to-json.hh Use std::set<StringContextElem> not PathSet for string contexts 2023-04-21 01:05:49 -04:00
value-to-xml.cc Split up util.{hh,cc} 2023-11-05 12:20:02 -05:00
value-to-xml.hh Use std::set<StringContextElem> not PathSet for string contexts 2023-04-21 01:05:49 -04:00
value.hh Unify and refactor value printing 2024-01-11 16:34:36 -08:00