AshlinHarris / Spinners.jl

Command line spinners in Julia with Unicode support
MIT License
13 stars 1 forks source link

Combined Unicode characters aren't properly erased #70

Closed AshlinHarris closed 1 year ago

AshlinHarris commented 1 year ago

Example: @spinner "क़ " sleep(4)

Not sure who would need this, but I'd like to find a robust way to erase any Unicode grapheme in general.

AshlinHarris commented 1 year ago
julia> f(s) = sizeof(s), length(transcode(UInt16, s))
f (generic function with 1 method)

julia> map(f, ["🎉","א","क़", "A", "\u3000"])
5-element Vector{Tuple{Int64, Int64}}:
 (4, 2)
 (2, 1)
 (6, 2)
 (1, 1)
 (3, 1)

For each character, sizeof is 4 ("क़" contains 2-byte characters.) Is there a way to calculate the number of backspaces \b needed? It often matches the transcode length, although exceptions include `\u3000' (requires 2) and "क़" (only requires 1). What function can calculate this value? Terminal emulators already seem to account for width.

AshlinHarris commented 1 year ago

Oh, it's textwidth!

julia> map(textwidth, ["🎉","א","क़", "A", "\u3000"])
5-element Vector{Int64}:
 2
 1
 1
 1
 2