TerminalUserInterfaces.jl
TerminalUserInterfaces.jl copied to clipboard
Progress bars not visible.
I am using the master branch of TUI, on Arch Linux, Julia 1.6.1.
Only the percentage is visible, which I don't believe was intended.
Recording here.
The progress bar widget hard codes the background to be black: https://github.com/kdheepak/TerminalUserInterfaces.jl/blob/3e095ff933ddbfb70a6055e2b83b51447c587506/src/widgets/progressbar.jl#L17
I think that’s what is going on here.
I can confirm that changing my terminal background made a bar appear.
A proposed fix: The bar could have a black color, being replaced by a white as the progress goes on, with the text being bright white if the bar is not behind it and becoming black if the bar starts overlapping it. This should be visible as progress on any combination of terminal settings.
Can you try the most recent commit?
https://github.com/kdheepak/TerminalUserInterfaces.jl/blob/e1946a7e106dd4563e57e04a878c04909d96861a/src/widgets/progressbar.jl#L17
I seem to have changed it from using :white and :black to hardcoded values a while ago, but I can't remember why:
https://github.com/kdheepak/TerminalUserInterfaces.jl/commit/3e095ff933ddbfb70a6055e2b83b51447c587506#diff-d4c1b4784a623b4120fc107f6e6e18d0d7fe3149ed1494add012bce57463fa67
Anyway, let me know whether it works. I think this will use whatever :white and :black have been defined as by your terminal theme.
No change. My temporary purple background gets replaced by black as progress is made. I don't believe this was the intent behind the code. I would have expected the entire bar to be drawn, in white and black, not partially in my background purple.
Recording here
Can you run using Crayons; Crayons.test_system_colors()?
I've made a new change (see https://github.com/kdheepak/TerminalUserInterfaces.jl/commit/72c64dd074e7c833151e6607a00022e85ef5807f) where you can pass in the colors as a crayon to the ProgressBar struct. You can change the colors now from the user example code directly.
Here you go.

I used a red and green crayon for the bar. This is sufficient to let me make progress, but it was not an expected result.
I was expecting a red bar, slowly filling up with green as progress is being made. Instead, I got a black bar filling up with green. The text started as white, and turned red when the green bar made progress through it. I would suspect inv() not doing the proper job on the crayon and picking the default colors instead.
Would you like a video of what I currently have?
Either way, this solves my problem sufficiently. Thank you.
I do believe inv() fails on Crayons, or at least isn't the intended behavior:
julia> a = Crayon(; foreground=:white, background=:black)
\e[97;40m
julia> inv(a).bg
Crayons.ANSIColor(0x09, 0x00, 0x00, Crayons.COLORS_16, true)
julia> inv(a).fg
Crayons.ANSIColor(0x09, 0x00, 0x00, Crayons.COLORS_16, true)
julia> a.fg
Crayons.ANSIColor(0x43, 0x00, 0x00, Crayons.COLORS_16, true)
julia> a.bg
Crayons.ANSIColor(0x00, 0x00, 0x00, Crayons.COLORS_16, true)
You are right, Crayons inverse isn't doing what we expected.
You can create your own progress bar widget btw:
struct ProgressBar
block::Block
ratio::Float64
crayon::Crayon
function ProgressBar(block, ratio, crayon = Crayon(foreground = :white, background = :black))
( ratio < 0 || ratio > 1 ) && error("Got $ratio. ProgressBar ratio must be in [0, 1].")
new(block, ratio, crayon)
end
end
function draw(pg::ProgressBar, rect::Rect, buf::Buffer)
draw(pg.block, rect, buf)
inner_area = inner(pg.block, rect)
center = height(inner_area) ÷ 2 + top(inner_area)
for y in top(inner_area):bottom(inner_area)
for x in left(inner_area):right(inner_area)
if x <= pg.ratio * (right(inner_area) - left(inner_area) + 1)
set(buf, x, y, Crayon(foreground = :red, background = :green))
else
set(buf, x, y, Crayon(foreground = :green, background = :red))
end
end
end
label = "$(round(pg.ratio * 100))%"
middle = Int(round( (width(inner_area) - length(label)) / 2 + left(inner_area) ))
set(buf, middle, center, label, Crayon(foreground = :black, background = :default))
end
And use that instead of the built in one.
I've added a new ProgressBar that allows for more customization. That should help with this issue.