Closed TRex22 closed 5 years ago
This change I'm less excited about. It seems like a fairly complicated feature and I'd much prefer keep this gem as light as possible. I might be open to having a separate "theme" accessor, that's either a hash or a ProgressBar::Theme struct, which contains colors and delimiters (from your previous PR).
It might work something like this:
MY_BAR_THEME = {
foreground: :green # or 32
background: :black # or a number
bar_character: "#",
delimiter: "[]"
}
bar = ProgressBar.new(100, theme: MY_BAR_THEME)
big_list.each do |item|
do_stuff
rescue
bar.theme[:foreground] = :red
# or bar.theme = MY_ERROR_THEME
ensure
bar.increment!
end
Alternatively, instead of ProgressBar having to know anything about color, there could just be :prefix
and :suffix
attributes on the theme, and you could set them to \e[32m
or whatever other terminal colors you want. The same could be done with the delimiters, like delimiters: ["\e[36m[\e[38;5;240m", "\e36m]\e0m"]
, which would give even more control over how to make the bar look.
WDYT?
I initially didnt like the second idea but its growing on me. It would allow anyone using this gem to decide and use their own modifiers. It would also mean a hardcoded set of styles based on the limited default console set wouldnt be needed.
I wouldnt go for the first idea because I feel its even more restrictive than the first. I would rather leave style decisions to whomever is using the library.
I will update this to use the prefix
suffix
idea but have a bit more of an extensive readme section to help anyone get started. Such as including the screenshot above.
Im going to close this PR and re-do it using the prefix
and suffix
ideas
What does this PR do?
Available Styles