123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109(*————————————————————————————————————————————————————————————————————————————
Copyright (c) 2020–2021 Craig Ferguson <me@craigfe.io>
Distributed under the MIT license. See terms at the end of this file.
————————————————————————————————————————————————————————————————————————————*)open!Importtype'areporter='a->unitmoduletypeS=sigtype'alinetype'areportertype('a,'b)t(** The type of vertical {i sequences} of progress bars. The parameter ['a]
stores a list of the reporting functions associated with each bar,
terminating with ['b]. For example:
{[
(* Single progress bar, taking a [float] value. *)
(float reporter -> 'b, 'b) t
(* A two-bar layout, where the top bar takes [int64]s and the bottom one
takes [string * float] pairs. *)
(int64 reporter -> (string * float) reporter -> 'b, 'b) t
]}
These reporting functions are supplied when beginning the {{!rendering}
rendering} process. *)valline:'aline->('areporter->'b,'b)t(** Construct a multiple-line layout from a single progress bar line. *)vallines:'alinelist->('areporterlist->'b,'b)t(** Construct a multiple-line layout from a sequence of lines that all have
the same type of reported values. *)val(++):('a,'b)t->('b,'c)t->('a,'c)t(** Stack progress bars vertically. [a ++ b] is a set with [a] stacked on top
of [b]. The two sections have separate reporting functions, passed
consecutively to the {!with_reporters} continuation when rendering. *)valblank:('a,'a)t(** A blank line, for adding spacing between progress lines. *)endmoduleHlist(Elt:sigtype'atend)=structtype(_,_)t=|Zero:('a,'a)t|One:'aElt.t->('areporter->'b,'b)t|Many:'aElt.tlist->('areporterlist->'b,'b)t|Plus:(('a,'b)t*('b,'c)t)->('a,'c)ttype'bmapper={f:'a.int->'aElt.toption->'b}letmapi=letrecaux:typeabc.(a,b)t->int->f:cmapper->int*clist=funti~f->matchtwith|Zero->(succi,[f.fiNone])|Oneb->(succi,[f.fi(Someb)])|Manybs->(i+List.lengthbs,List.mapibs~f:(funi'x->f.f(i+i')(Somex)))|Plus(xs,ys)->leti,xs=auxxs~fiinleti,ys=auxys~fiin(i,xs@ys)infunt~f->snd(auxt0~f)letreclength:typeab.(a,b)t->int=function|Zero->1|One_->1|Manyxs->List.lengthxs|Plus(a,b)->lengtha+lengthblet(++)xsys=Plus(xs,ys)endmoduletypeMulti=sigmoduletypeS=SmoduleHlist=HlistincludeSwithtype'aline:='aLine.tandtype'areporter:='a->unitandtype('a,'b)t=('a,'b)Hlist(Line).tend(*————————————————————————————————————————————————————————————————————————————
Copyright (c) 2020–2021 Craig Ferguson <me@craigfe.io>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
————————————————————————————————————————————————————————————————————————————*)