andyferris / Dictionaries.jl

An alternative interface for dictionaries in Julia, for improved productivity and performance
Other
282 stars 28 forks source link

Use _truncate_at_width_or_chars to avoid ANSI truncation #142

Closed theogf closed 5 months ago

theogf commented 6 months ago

The manual truncation of strings lead to the following problem:

using Random, Dictionaries
struct Foo end
Base.show(io::IO, ::Foo) = printstyled(io, "abc"^100; color = rand((:blue, :green, :red)))
Dictionary([randstring(5) for _ in 1:10], fill(Foo(), 10))

On main we get:

image

The issue is that the ANSI characters are truncated and the color bleeds to the next input.

Using the same function that Base use for show solve the issue:

image

I am not super sure how to test this though.

theogf commented 6 months ago

Looks like this function handles ANSI correctly only from 1.9... I added some version compat there.

codecov[bot] commented 6 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 80.42%. Comparing base (af1f512) to head (4eb30e4).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #142 +/- ## ========================================== - Coverage 80.52% 80.42% -0.10% ========================================== Files 21 21 Lines 2357 2345 -12 ========================================== - Hits 1898 1886 -12 Misses 459 459 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

theogf commented 6 months ago

Ah it looks like the signature changed again for 1.11... It was a type issue.