Skip to content

[inspect] Right-align indices when rendering indexed collections #202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 27, 2023

Conversation

alexander-yakushev
Copy link
Member

When inspecting a linear collection, the indices cause an ugly indentation shift on digit promotions (9->10, 99->100). This PR fixes this. Here's now it looks currently:

image

Here's how it looks after the patch:
image

In the future, we might want to do the similar for associative collections, but I think it's a more contentious topic. Some people don't like their values aligned to keys if it causes a large gap on the other side (me included). But aligning indices shouldn't be controversial since most of the time it's gonna be 1 space, 2 spaces at the very most in the edge case.

@alexander-yakushev alexander-yakushev force-pushed the inspector-align branch 2 times, most recently from c1956ad to 5c2a1b0 Compare October 27, 2023 11:22
Copy link
Member

@vemv vemv left a comment

Choose a reason for hiding this comment

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

Looking good! Happy to get the Ins closer to pixel perfection

@@ -408,17 +408,31 @@
inspector
mappable))

(defn- left-pad
"TODO: should extract this into a library."
Copy link
Member

Choose a reason for hiding this comment

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

oh no! 😄

Looks like (String/format "%10s" (object-array ["foo"])) ensures a given string has N characters, left-padding with spaces otherwise.

Copy link
Member Author

Choose a reason for hiding this comment

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

Interesting, I've tried googling for it and found answers that String.format can only pad with zeros.

Still, I feel a bit reluctant to construct a format string and then use the slow formatting method for each iteration, seems a bit wasteful. Even though it will never be used for that many items anyway.

Yeah, it's probably nothing.

`chunk` must be finite."
([inspector chunk] (render-indexed-values inspector chunk 0))
([inspector chunk idx-starts-from]
(let [n (count chunk)
Copy link
Member

@vemv vemv Oct 27, 2023

Choose a reason for hiding this comment

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

May it make sense to use bounded-count, when available, for safety?

An alternative being asserting that the chunk is Counted

Copy link
Member Author

Choose a reason for hiding this comment

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

The current version of this function goes over the whole sequence non-conditionally anyway. Adding count doesn't really make it less safe. There is currently only one caller of this function that passes in a finite sequence. I renamed the argument to make this more apparent at least documentation-wise. Don't know if it needs any other guardrails.

'(:newline))
(render (inspect/start (inspect/fresh) (vec (range 11))))))

(let [rendered (-> (inspect/fresh)
Copy link
Member

Choose a reason for hiding this comment

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

I'd appreciate a testing here to understand how this test is different

@alexander-yakushev
Copy link
Member Author

Ready.

Copy link
Member

@vemv vemv left a comment

Choose a reason for hiding this comment

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

Feel free to merge after it's green

@alexander-yakushev alexander-yakushev merged commit 4d99bf7 into master Oct 27, 2023
@vemv vemv deleted the inspector-align branch October 27, 2023 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants