Source file progress_engine.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
(*————————————————————————————————————————————————————————————————————————————
   Copyright (c) 2020–2021 Craig Ferguson <me@craigfe.io>
   Distributed under the MIT license. See terms at the end of this file.
  ————————————————————————————————————————————————————————————————————————————*)

open! Import
include Progress_engine_intf

module type Platform = Platform.S

module Make (Platform : Platform) = struct
  module Color = Terminal.Color
  module Duration = Duration
  module Multi = Multi
  module Printer = Printer
  module Units = Units

  module Internals = struct
    module Ansi = Terminal.Style
  end

  module Config = struct
    include Config

    type t = user_supplied
  end

  module Renderer = struct
    include Renderer.Make (Platform)
    include Renderer
  end

  module Line = struct
    include Line.Make (Platform)
    include Line
  end

  module Display = Renderer.Display
  module Reporter = Renderer.Reporter

  let counter ?(style = `ASCII) ?message ?pp total =
    let map_option ~f x = Option.fold ~none:(Line.noop ()) ~some:f x in
    let open Line.Using_int64 in
    list
      [ map_option message ~f:const
      ; map_option pp ~f:(fun pp -> sum ~pp ~width:(Printer.print_width pp) ())
      ; elapsed ()
      ; bar ~style total
      ; percentage_of total
      ]

  let interject_with = Renderer.interject_with
  let instrument_logs_reporter = Renderer.instrument_logs_reporter
  let logs_reporter = Renderer.logs_reporter
  let with_reporters = Renderer.with_reporters
  let with_reporter ?config b f = with_reporters ?config (Multi.line b) f
end

module Integer = Integer

module Exposed_for_testing = struct
  module Flow_meter = Flow_meter
end

(*————————————————————————————————————————————————————————————————————————————
   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.
  ————————————————————————————————————————————————————————————————————————————*)