Skip to content

Commit

Permalink
print: accurately track (fractional) line width, and raise the max wi…
Browse files Browse the repository at this point in the history
…dth back to 120. (#37)

*Originally found/fixed during the #33/#34/#35/#36 series of
pretty-printing PRs.*

Before this PR, we were treating all text the same, regardless of style,
but this PR introduces the concept of "fractional columns" (integer
multiples of `0.1ch`, because our `font-size`s are always integer
multiples of `0.1em`).

The result is much more accurate, and so far appears to perfectly match
browser behavior (i.e. the transition of `MAX_LINE_WIDTH` from `N-1` to
`N`, where multi-line layout gets replaced with single-line layout,
results in a line that "tightly fits" in a `max-width: Nch` container,
with no spurious gaps or overflows).

Note however that the increased accuracy makes the layout favor HTML
over plaintext (and we don't have a plaintext-vs-HTML "simultaneous
layout", nor a way to hint what the output of pretty layout will be used
for), so the plaintext output may feel more inconsistent as a result
(but its aesthetics are of dubious value anyway).
  • Loading branch information
eddyb authored Jun 11, 2023
2 parents c32ae33 + 3c825a5 commit c11d384
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 54 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
example (which only dumped plaintext, not HTML) with a more useful `spv-lower-print` one

### Fixed 🩹
- [PR#37](https://github.com/EmbarkStudios/spirt/pull/37) fixed pretty-printing layout
accuracy regarding line widths (by tracking `font-size`-aware "fractional columns"),
and raised the maximum line width back up to `120` columns
- [PR#27](https://github.com/EmbarkStudios/spirt/pull/27) fixed some pretty-printing issues
in the initial `Attr::Diagnostics` implementation (`BUG` paths and `/* ... */` indentation)

Expand Down
2 changes: 1 addition & 1 deletion src/print/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ impl Visit for AllCxInterned {
}

// FIXME(eddyb) make max line width configurable.
const MAX_LINE_WIDTH: usize = 100;
const MAX_LINE_WIDTH: usize = 120;

impl Plan<'_> {
#[allow(rustdoc::private_intra_doc_links)]
Expand Down
12 changes: 12 additions & 0 deletions src/print/multiversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,19 @@ impl Versions<pretty::FragmentPostLayout> {
}
SCOPE>tbody>tr>td {
vertical-align: top;
}
SCOPE>tbody>tr>td>pre {
max-width: MAX_LINE_WIDTHch;
overflow-x: auto;
/* HACK(eddyb) this shouldn't be needed but `visible` will turn into
`auto` because `overflow-x` is `auto` (for cursed browser reasons),
and some table cells are always assumed to need vertical scroll,
e.g. because they have `<sub>` elements on the last line (which don't
contribute to the surrounding bounding box, due to `line-height: 0`)
*/
overflow-y: hidden;
}
</style>
"
Expand Down
Loading

0 comments on commit c11d384

Please sign in to comment.