diff options
author | alois31 <alois1@gmx-topmail.de> | 2024-07-19 06:40:13 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@localhost> | 2024-07-19 06:40:13 +0000 |
commit | aba5f19680b2f4c29d7ce2ff5e2a89128c1cb26d (patch) | |
tree | c1c3ce68cd7aab98167a394e11934ebcaed27ade /src/libexpr | |
parent | 5ee1e6ea9887a54f0af3a66528abc04b17611516 (diff) | |
parent | 768d1f29a2dcd9ed9552fafb4ab836ea2e400738 (diff) |
Merge changes I829581a3,I0016970d,I5dac8e77,Ib7560fe5 into main
* changes:
doc/release-notes: add for pretty printing improvements
libexpr/print: do not show elided nested items when there are none
libexpr/print: never show empty attrsets or derivations as «repeated»
libexpr/print: pretty-print idempotently
Diffstat (limited to 'src/libexpr')
-rw-r--r-- | src/libexpr/print.cc | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/src/libexpr/print.cc b/src/libexpr/print.cc index 87db004b2..b7ff50f48 100644 --- a/src/libexpr/print.cc +++ b/src/libexpr/print.cc @@ -264,22 +264,24 @@ private: return true; } + if (options.force) { + // The item is going to be forced during printing anyway, but we need its type now. + state.forceValue(*item, item->determinePos(noPos)); + } + // Pretty-print single-item attrsets only if they contain nested // structures. auto itemType = item->type(); - return itemType == nList || itemType == nAttrs || itemType == nThunk; + return itemType == nList || itemType == nAttrs; } void printAttrs(Value & v, size_t depth) { - if (seen && !seen->insert(v.attrs).second) { - printRepeated(); - return; - } - if (options.force && options.derivationPaths && state.isDerivation(v)) { printDerivation(v); - } else if (depth < options.maxDepth) { + } else if (seen && !v.attrs->empty() && !seen->insert(v.attrs).second) { + printRepeated(); + } else if (depth < options.maxDepth || v.attrs->empty()) { increaseIndent(); output << "{"; @@ -335,10 +337,15 @@ private: return true; } + if (options.force) { + // The item is going to be forced during printing anyway, but we need its type now. + state.forceValue(*item, item->determinePos(noPos)); + } + // Pretty-print single-item lists only if they contain nested // structures. auto itemType = item->type(); - return itemType == nList || itemType == nAttrs || itemType == nThunk; + return itemType == nList || itemType == nAttrs; } void printList(Value & v, size_t depth) @@ -348,7 +355,7 @@ private: return; } - if (depth < options.maxDepth) { + if (depth < options.maxDepth || v.listSize() == 0) { increaseIndent(); output << "["; auto listItems = v.listItems(); |