Skip to content

Commit a4da95d

Browse files
committed
Allow per-job column specification at addjob!() invocation
1 parent 692eb8e commit a4da95d

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/progress.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,8 @@ Base.show(io::IO, ::MIME"text/plain", pbar::ProgressBar) =
337337
N::Union{Int, Nothing}=nothing,
338338
start::Bool=true,
339339
transient::Bool=false,
340-
id=nothing
340+
id=nothing,
341+
columns::Vector{DataType} = pbar.columns
341342
)::ProgressJob
342343
343344
Add a new `ProgressJob` to a running `ProgressBar`
@@ -352,14 +353,15 @@ function addjob!(
352353
transient::Bool = false,
353354
id = nothing,
354355
columns_kwargs::Dict = Dict(),
356+
columns::Vector{DataType} = pbar.columns,
355357
)::ProgressJob
356358
pbar.running && print("\n")
357359

358360
# create Job
359361
pbar.paused = true
360362
id = isnothing(id) ? length(pbar.jobs) + 1 : id
361363
kwargs = merge(pbar.columns_kwargs, columns_kwargs)
362-
job = ProgressJob(id, N, description, pbar.columns, pbar.width, kwargs, transient)
364+
job = ProgressJob(id, N, description, columns, pbar.width, kwargs, transient)
363365

364366
# start job
365367
start && start!(job)

test/15_test_progress.jl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,32 @@ end
136136
IS_WIN || @compare_to_string render(pbar) "pbar_customization"
137137
end
138138

139+
@testset "\e[34mProgress per-job columns" begin
140+
@test_nowarn redirect_stdout(Base.DevNull()) do
141+
p = ProgressBar(; columns=:default)
142+
c0 = [DescriptionColumn, CompletedColumn, ProgressColumn, SpinnerColumn]
143+
c1 = [DescriptionColumn, CompletedColumn, ProgressColumn, SpinnerColumn]
144+
c2 = [CompletedColumn, ProgressColumn, SeparatorColumn, SpinnerColumn]
145+
j0 = addjob!(p; columns=c0, N=100)
146+
j1 = addjob!(p; columns=c1, N=100)
147+
j2 = addjob!(p; columns=c2, N=100)
148+
@test all(typeof.(j0.columns) .== c0)
149+
@test all(typeof.(j1.columns) .== c1)
150+
@test all(typeof.(j2.columns) .== c2)
151+
@test !all(typeof.(j2.columns) .== c0)
152+
@test !all(typeof.(j0.columns) .== c2)
153+
154+
with(p) do
155+
for _ in 1:100
156+
update!(j0)
157+
update!(j1)
158+
update!(j2)
159+
sleep(0.01)
160+
end
161+
end
162+
end
163+
end
164+
139165
@testset "\e[34mProgress foreachprogress" begin
140166
@test_nowarn redirect_stdout(Base.DevNull()) do
141167
Term.Progress.foreachprogress(1:10) do i

0 commit comments

Comments
 (0)