123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129(*————————————————————————————————————————————————————————————————————————————
Copyright (c) 2020–2021 Craig Ferguson <me@craigfe.io>
Distributed under the MIT license. See terms at the end of this file.
————————————————————————————————————————————————————————————————————————————*)open!ImportmoduletypeCounter=sigtypetvalcounter:unit->tvalcount:t->Mtime.spanendmoduleTypes=structtypeevent=[`report(* User has supplied a reported value. *)|`rerender(* Renderer wants a re-display. *)|`tick(* User has requested a "tick" (e.g. to update spinners). *)|`finish(* The bar or display has been finalised. *)]end(** The DSL of progress bar segments. *)moduletypeS=sigtype'at(** The type of segments of progress bars that display reported values of type
['a]. *)includemoduletypeofTypestypetheta:=Line_buffer.t->event->unittype'aalpha:=Line_buffer.t->event->'a->unitvalnoop:unit->_tvaltheta:width:int->theta->_tvalalpha:width:int->initial:[`ThetaofLine_buffer.t->unit|`Valof'a]->'aalpha->'atvalalpha_unsized:initial:[`Thetaofwidth:(unit->int)->Line_buffer.t->int|`Valof'a]->(width:(unit->int)->Line_buffer.t->event->'a->int)->'atvalarray:'atarray->'atvalpair:?sep:unitt->'at->'bt->('a*'b)tvalcontramap:f:('a->'b)->'bt->'atvalon_finalise:'a->'at->'atvalof_pp:width:int->initial:'a->(Format.formatter->event->'a->unit)->'at(** [of_pp ~width pp] is a segment that uses the supplied fixed-width
pretty-printer to render the value. The pretty-printer must never emit
newline characters. *)valconditional:('a->bool)->'at->'at(** [conditional pred s] has the same output format as [s], but is only passes
reported values down to [s] when they satisfy [pred]. *)(** {2:stateful Stateful segments} *)valperiodic:int->'at->'at(** [periodic n s] has the same output format as [s], but only passes reported
values down to [s] on every [n]-th call. This is useful when progress is
being reported from a hot-loop, where the cost of rendering is
non-negligible. *)valaccumulator:('a->'a->'a)->'a->'at->'at(** [accumulator combine zero s] has the same output format [s]. *)valstateful:(unit->'at)->'at(** [stateful f] is a segment that behaves as [f ()] for any given render,
allowing [f] to initialise any display state at the start of the rendering
process. *)(** {2:boxes Dynamically-sized segments} *)(** Certain segments can have their size determined dynamically by being
wrapped inside one of the following boxes: *)valbox_dynamic:?pad:[`left|`right|`none]->(unit->int)->'at->'at(** [box w] is a box that wraps a dynamically-sized segment and sets it to
have size [w ()] on each tick. *)valbox_fixed:?pad:[`left|`right|`none]->int->'at->'at(** [box-fixed n s] fixes the size of the dynamic segment [s] to be [n]. *)endmoduletypeLine_primitives=sigmoduletypeS=SincludeSmoduleCompiled:sigtype'atvalpp_dump:Format.formatter->'at->unitendvalcompile:'at->'aCompiled.tvalupdate:'aCompiled.t->(unconditional:bool->Line_buffer.t->int)Staged.tvalreport:'aCompiled.t->(Line_buffer.t->'a->int)Staged.tvaltick:'aCompiled.t->(Line_buffer.t->int)Staged.tvalfinalise:'aCompiled.t->(Line_buffer.t->int)Staged.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.
————————————————————————————————————————————————————————————————————————————*)