Skip to content
Closed
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
37 changes: 0 additions & 37 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,7 @@
(name progress)
(implicit_transitive_deps false)

(generate_opam_files true)
(source (github CraigFe/progress))
(license MIT)
(maintainers "Craig Ferguson <[email protected]>")
(authors "Craig Ferguson <[email protected]>")

(package
(name progress)
(synopsis "User-definable progress bars")
(description "\
A progress bar library for OCaml, featuring a DSL for declaratively specifying
progress bar formats. Supports rendering multiple progress bars simultaneously.\
")
(documentation https://CraigFe.github.io/progress/)
(depends
(ocaml (>= 4.08.0))
(terminal (= :version))
(fmt (>= 0.8.5))
(logs (>= 0.7.0))
(mtime (>= 2.0.0))
(uucp (>= 2.0.0))
(uutf (>= 1.0.0))
vector
(optint (>= 0.1.0))
(alcotest (and :with-test (>= 1.4.0)))
(astring :with-test)))

(package
(name terminal)
(synopsis "Basic utilities for interacting with terminals")
(description "Basic utilities for interacting with terminals")
(documentation https://CraigFe.github.io/progress/)
(depends
(ocaml (>= 4.03.0))
(uucp (>= 2.0.0))
(uutf (>= 1.0.0))
stdlib-shims
(alcotest (and :with-test (>= 1.4.0)))
(fmt :with-test)
(astring :with-test)
(mtime (and :with-test (>= 2.0.0)))))
12 changes: 7 additions & 5 deletions examples/cargo.ml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
open Utils

let packages =
[ ("0install-solver", "2.17")
; ("afl-persistent", "1.3")
Expand Down Expand Up @@ -31,7 +33,7 @@ let packages =
; ("yojson", "1.7.0")
; ("zarith", "1.9.1")
]
|> Vector.of_list ~dummy:("", "")
|> Dynlist.of_list

let setup_logs () =
let reporter = Progress.logs_reporter () in
Expand All @@ -41,7 +43,7 @@ let setup_logs () =

let bar =
let open Progress.Line in
let total = Vector.length packages in
let total = Dynlist.length packages in
list
[ constf " %a" Fmt.(styled `Cyan string) "Building"
; using fst
Expand All @@ -54,9 +56,9 @@ let bar =
]

let rec package_worker (active_packages, reporter) =
match Vector.pop packages with
| exception Vector.Empty -> ()
| package, version ->
match Dynlist.pop_opt packages with
| None -> ()
| Some (package, version) ->
active_packages := package :: !active_packages;
Logs.app (fun f ->
f " %a %s %s" Fmt.(styled `Green string) "Compiling" package version);
Expand Down
2 changes: 1 addition & 1 deletion examples/dune
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
(modules
(:standard \ main))
(libraries progress unix logs logs.fmt logs.threaded fmt fmt.tty mtime
mtime.clock.os vector threads.posix))
mtime.clock.os threads.posix))

(executable
(name main)
Expand Down
25 changes: 13 additions & 12 deletions examples/utils.ml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
let ( .%() ) v i = Vector.get v i
let ( .%()<- ) v i x = Vector.set v i x
module Dynlist = struct
type 'a t = 'a list ref

let shuffle_vector =
let shuffle_subvector rand_int v i j =
for k = j - 1 downto i + 1 do
let l = rand_int (k + 1) in
let tmp = v.%(l) in
v.%(l) <- v.%(k);
v.%(k) <- tmp
done
in
fun v -> shuffle_subvector Random.int v 0 (Vector.length v)
let of_list l = ref l

let pop_opt l =
match !l with
| [] -> None
| x :: xs ->
l := xs;
Some x

let length l = List.length !l
end

let colors =
(* import matplotlib.cm
Expand Down
9 changes: 8 additions & 1 deletion examples/utils.mli
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
val shuffle_vector : _ Vector.t -> unit
module Dynlist : sig
type 'a t

val of_list : 'a list -> 'a t
val length : 'a t -> int
val pop_opt : 'a t -> 'a option
end

val colour_picker : unit -> unit -> Progress.Color.t
3 changes: 1 addition & 2 deletions progress.opam
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
synopsis: "User-definable progress bars"
description: """
Expand All @@ -13,13 +12,13 @@ bug-reports: "https://github.com/CraigFe/progress/issues"
depends: [
"dune" {>= "2.7"}
"ocaml" {>= "4.08.0"}
("ocaml" {>= "5.2.0"} | ("ocaml" {< "5.2.0"} & "vector"))
"terminal" {= version}
"fmt" {>= "0.8.5"}
"logs" {>= "0.7.0"}
"mtime" {>= "2.0.0"}
"uucp" {>= "2.0.0"}
"uutf" {>= "1.0.0"}
"vector"
"optint" {>= "0.1.0"}
"alcotest" {with-test & >= "1.4.0"}
"astring" {with-test}
Expand Down
39 changes: 38 additions & 1 deletion src/progress/engine/dune
Original file line number Diff line number Diff line change
@@ -1,11 +1,48 @@
; We use two different implementations of vectors depending on the availability of Dynarray in the standard library (starting OCaml 5.2).
; This reduces dependencies fo users of the newer OCaml versions, and reduces clashes with the ecosystem (https://github.com/craigfe/progress/pull/50).

; Rules for OCaml 5.2 and later

(rule
(enabled_if
(>= %{ocaml_version} "5.2"))
(action
(copy# pvector.dynarray.ml pvector.ml)))

(library
(name pvector)
(public_name progress.vector)
(enabled_if
(>= %{ocaml_version} "5.2"))
(modules pvector))

; Rules for OCaml versions after 5.2

(rule
(enabled_if
(< %{ocaml_version} "5.2"))
(action
(copy# pvector.vector.ml pvector.ml)))

(library
(name pvector)
(public_name progress.vector)
(enabled_if
(< %{ocaml_version} "5.2"))
(modules pvector)
(libraries vector))

; Main library

(library
(name progress_engine)
(public_name progress.engine)
(modules :standard \ pvector)
(libraries
(re_export mtime)
(re_export optint)
fmt
logs
logs.fmt
terminal_ansi
vector))
progress.vector))
36 changes: 0 additions & 36 deletions src/progress/engine/import.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,6 @@ module Mtime = struct
let span_to_s span = Mtime.Span.to_float_ns span *. 1e-9
end

module Vector = struct
include Vector

let iter ~f t = iter f t

let iteri_from ~f i t =
for i = i to length t - 1 do
f i (unsafe_get t i)
done

let rec find_map_from i t ~f =
if i >= length t then None
else
let a = unsafe_get t i in
match f a with
| Some _ as some -> some
| None -> find_map_from (i + 1) t ~f

let find_map t ~f = find_map_from 0 t ~f

let insert t k v =
Vector.push t v (* Dummy insertion to expand *);
for i = Vector.length t - 1 downto k + 1 do
Vector.set t i (Vector.get t (pred i))
done;
Vector.set t k v

let remove (type a) (t : a t) k =
for i = k to Vector.length t - 2 do
Vector.set t i (Vector.get t (succ i))
done;
ignore (Vector.pop t : a)

let get_exn = get
let get = `shadowed
end
(*————————————————————————————————————————————————————————————————————————————
Copyright (c) 2020–2021 Craig Ferguson <[email protected]>

Expand Down
34 changes: 34 additions & 0 deletions src/progress/engine/pvector.dynarray.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
include Dynarray

let iter ~f t = iter f t

let iteri_from ~f i t =
for i = i to length t - 1 do
f i (get t i)
done

let of_list ~dummy:_ l = Dynarray.of_list l

let rec find_map_from i t ~f =
if i >= length t then None
else
let a = get t i in
match f a with Some _ as some -> some | None -> find_map_from (i + 1) t ~f

let find_map t ~f = find_map_from 0 t ~f

let insert t k v =
Dynarray.add_last t v (* Dummy insertion to expand *);
for i = Dynarray.length t - 1 downto k + 1 do
Dynarray.set t i (Dynarray.get t (pred i))
done;
Dynarray.set t k v

let remove (type a) (t : a t) k =
for i = k to Dynarray.length t - 2 do
Dynarray.set t i (Dynarray.get t (succ i))
done;
ignore (Dynarray.pop_last t : a)

let get_exn = get
let get = `shadowed
32 changes: 32 additions & 0 deletions src/progress/engine/pvector.vector.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
include Vector

let iter ~f t = iter f t

let iteri_from ~f i t =
for i = i to length t - 1 do
f i (unsafe_get t i)
done

let rec find_map_from i t ~f =
if i >= length t then None
else
let a = unsafe_get t i in
match f a with Some _ as some -> some | None -> find_map_from (i + 1) t ~f

let find_map t ~f = find_map_from 0 t ~f

let insert t k v =
Vector.push t v (* Dummy insertion to expand *);
for i = Vector.length t - 1 downto k + 1 do
Vector.set t i (Vector.get t (pred i))
done;
Vector.set t k v

let remove (type a) (t : a t) k =
for i = k to Vector.length t - 2 do
Vector.set t i (Vector.get t (succ i))
done;
ignore (Vector.pop t : a)

let get_exn = get
let get = `shadowed
Loading