Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add done! #12

Merged
merged 7 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
- '1.6'
- '1.7'
- '1.8'
- '1.9'
- 'nightly'
os:
- ubuntu-latest
Expand Down
19 changes: 0 additions & 19 deletions .github/workflows/add-participant-asana-task.yml

This file was deleted.

18 changes: 0 additions & 18 deletions .github/workflows/close-asana-task.yml

This file was deleted.

18 changes: 0 additions & 18 deletions .github/workflows/edit-asana-task.yml

This file was deleted.

18 changes: 0 additions & 18 deletions .github/workflows/open-asana-task.yml

This file was deleted.

3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name = "PSRProgressBar"
uuid = "e78ae4d9-7c0a-4397-83ad-465eb5391708"
version = "0.1.0"
version = "0.1.1"

[deps]

[compat]
Aqua = "0.6"
julia = "1.6"

[extras]
Expand Down
File renamed without changes.
6 changes: 6 additions & 0 deletions format/format.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Pkg
Pkg.instantiate()

using JuliaFormatter

format(dirname(@__DIR__))
9 changes: 0 additions & 9 deletions formatter/format.jl

This file was deleted.

2 changes: 1 addition & 1 deletion src/PSRProgressBar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ module PSRProgressBar
include("progress_bar.jl")
include("utils.jl")

end # module PSRProgressBar
end
15 changes: 8 additions & 7 deletions src/progress_bar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ abstract type AbstractProgressBar end
end

Base.@kwdef mutable struct ProgressBar <: AbstractProgressBar

maximum_steps::Int
current_length::Int = 0
current_steps::Int = 0
Expand Down Expand Up @@ -45,7 +44,6 @@ function _header(p::AbstractProgressBar)
return nothing
end


function _footer(p::AbstractProgressBar)
@assert p.has_finished
if p.maximum_length > 2
Expand All @@ -59,8 +57,8 @@ end

function _show_progress_bar(
p::AbstractProgressBar,
l_text::String = "",
r_text::String = "",
l_text::AbstractString = "",
r_text::AbstractString = "",
)
if isempty(l_text)
l_text = p.left_bar
Expand Down Expand Up @@ -110,9 +108,7 @@ function _show_progress_bar(
return nothing
end



function next!(p::AbstractProgressBar, steps::Int = 1)
function next!(p::AbstractProgressBar, steps::Integer = 1)
if p.current_steps == 0
p.start_time = time()
p.time = time()
Expand Down Expand Up @@ -149,3 +145,8 @@ function next!(p::AbstractProgressBar, steps::Int = 1)
p.time = time()
return nothing
end

function done!(p::AbstractProgressBar)
next!(p, p.maximum_steps - p.current_steps)
return nothing
end
10 changes: 4 additions & 6 deletions src/utils.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function _convert_time_unit(time::Float64)
function _convert_time_unit(time::Real)
t_unit = if time < 1.0
time = round(Int, time * 1000.0)
"ms"
Expand All @@ -15,13 +15,12 @@ function _convert_time_unit(time::Float64)
return "$(time)$(t_unit)"
end


function _eta_text(p::AbstractProgressBar, new_length::Float64)
function _eta_text(p::AbstractProgressBar, new_length::Real)
if !p.has_eta
return ""
end
if !p.eta_started
return " ETA: --"
return " ETA: --"
end

s2 = p.maximum_steps - p.current_steps # remaining length
Expand All @@ -41,12 +40,11 @@ function _elapsed_text(p::AbstractProgressBar)
return " Time: $(_convert_time_unit(elapsed))"
end

function _percentage_text(p::AbstractProgressBar, frac::Float64)
function _percentage_text(p::AbstractProgressBar, frac::Real)
percentage = floor(Int, frac * 100)
percentage_text = (" "^(4 - length("$percentage"))) * "$percentage" # percentage text should always have length 5 ( 1 for spacing + xxx%)
if p.has_percentage && p.display == ITERATIVE
return percentage_text * "%"
end
return " "^5
end

4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function test_length()
end
end
@test p_incremental.current_ticks == p_iterative.current_ticks
@test p_incremental.current_ticks == p_incremental.maximum_length-2
@test p_incremental.current_ticks == p_incremental.maximum_length - 2

last_stage = 104
first_stage = 1
Expand All @@ -75,7 +75,7 @@ function test_length()
end
end
@test p_incremental.current_ticks == p_iterative.current_ticks
@test p_incremental.current_ticks == p_incremental.maximum_length-2
@test p_incremental.current_ticks == p_incremental.maximum_length - 2

end

Expand Down