Skip to content

Conversation

@9999years
Copy link
Contributor

@9999years 9999years commented Feb 4, 2024

Motivation

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
  ];
}

Here's how the output looks (with #9928 and #9926 applied as well):
image

Context

@Qyriad's prototype pretty-printer in Xil gave me the inspiration to do this. It turns out the patch is pretty small, so here it is!

In the future, users should be able to customize how much is printed for large values. See #9942.

Priorities and Process

Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@9999years
Copy link
Contributor Author

9999years commented Feb 4, 2024

Needs tests & changelog entry.

@github-actions github-actions bot added the repl The Read Eval Print Loop, "nix repl" command and debugger label Feb 4, 2024
@github-actions github-actions bot added the with-tests Issues related to testing. PRs with tests have some priority label Feb 4, 2024
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
  ];
}
```
@9999years 9999years marked this pull request as ready for review February 5, 2024 21:35
@9999years 9999years requested a review from edolstra as a code owner February 5, 2024 21:35
Copy link
Member

@thufschmitt thufschmitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's great!

Left a few comments, and I'll leave a bit of time for others to chime in, but a bit 👍 overall

@9999years 9999years requested a review from thufschmitt February 8, 2024 18:30
@fricklerhandwerk
Copy link
Contributor

A conceptual question on the side: couldn't we instead allow plugging a formatter as developed by @piegames and @infinisil? Otherwise we'd be duplicating effort.

@thufschmitt
Copy link
Member

A conceptual question on the side: couldn't we instead allow plugging a formatter as developed by @piegames and @infinisil? Otherwise we'd be duplicating effort.

I briefly touched on that with @infinisil, but doing so would make the whole infra significantly more complex, and this formatting is only for values (and not arbitrary expressions), which makes it orders of magnitude simpler (the formatting change is around 60 extras loc)

@thufschmitt thufschmitt merged commit d857914 into NixOS:master Feb 14, 2024
@fricklerhandwerk
Copy link
Contributor

fricklerhandwerk commented Feb 14, 2024

This could have a release note though.

@9999years 9999years deleted the pretty-printer branch February 14, 2024 16:46
@9999years
Copy link
Contributor Author

@fricklerhandwerk Good point, I've added a release note in #9943.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

repl The Read Eval Print Loop, "nix repl" command and debugger with-tests Issues related to testing. PRs with tests have some priority

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants