A Nix-friendly SQLite-enhanced fork of Flitter, a speedrunning split timer for Unix-style terminals
Révision | 45b69bfe94bdf5aab1ac7eb28d2c1705d4d6f5c1 (tree) |
---|---|
l'heure | 2023-07-04 01:51:27 |
Auteur | Corbin <cds@corb...> |
Commiter | Corbin |
Duplicate and simplify row-displaying logic.
@@ -112,7 +112,6 @@ let split_row timer width i = | ||
112 | 112 | in |
113 | 113 | |
114 | 114 | let plain_duration = uncolored_duration 1 in |
115 | - let wr_duration = uncolored_duration 2 in | |
116 | 115 | let curr_split = get_curr_split timer.state in |
117 | 116 | let show_comparison = i > curr_split in |
118 | 117 |
@@ -1,5 +1,10 @@ | ||
1 | 1 | type t |
2 | 2 | |
3 | +val time_col_width : int | |
4 | + | |
5 | +val left_pad : int -> Notty.image -> Notty.image | |
6 | +val join_pad : int -> Notty.image -> Notty.image -> Notty.image | |
7 | + | |
3 | 8 | val make : unit -> t |
4 | 9 | val draw : t -> Timer_types.timer -> unit |
5 | 10 | val close : t -> unit |
@@ -16,3 +16,51 @@ let sum_of_best = | ||
16 | 16 | (fun sd (_, _, min) -> |
17 | 17 | match (min, sd) with Some best, Some d -> Some (d + best) | _, _ -> None) |
18 | 18 | (Some 0) |
19 | + | |
20 | +let to_image (_, s) ((avg, stddev, min), md) ~width ~now = | |
21 | + (* XXX should be Colors.selection_bg on the active split; | |
22 | + parameterize the color and add a zipper to Run.t? *) | |
23 | + let bg_attr = Colors.default_bg in | |
24 | + let uncolored_attr = Notty.A.(Colors.text ++ bg_attr) in | |
25 | + let hyphen = Notty.I.string uncolored_attr "-" in | |
26 | + let title = Notty.I.string bg_attr s in | |
27 | + | |
28 | + (* Compute the split's ahead/behind time image *) | |
29 | + let delta_image = | |
30 | + match (md, min) with | |
31 | + | Some d, Some m -> | |
32 | + let diff = d - m in | |
33 | + let time_str = Duration.to_string_plus diff 1 in | |
34 | + (* XXX only supports two of five colors *) | |
35 | + let color = | |
36 | + if diff > 0 then Colors.behind_loss else Colors.ahead_gain | |
37 | + in | |
38 | + let color_attr = Notty.A.(color ++ bg_attr) in | |
39 | + Notty.I.string color_attr time_str | |
40 | + | _ -> hyphen | |
41 | + in | |
42 | + | |
43 | + let plain_duration d = | |
44 | + match d with | |
45 | + | None -> hyphen | |
46 | + | Some sgmt -> Notty.I.string uncolored_attr (Duration.to_string sgmt 1) | |
47 | + in | |
48 | + | |
49 | + (* Compute the image of the split's segment time *) | |
50 | + let sgmt_image = plain_duration min in | |
51 | + | |
52 | + (* Compute the image of the split's absolute time *) | |
53 | + (* XXX needs to fold and sum *) | |
54 | + let time_image = plain_duration None in | |
55 | + | |
56 | + (* Combine the three time columns together with proper padding *) | |
57 | + let time_cells = [ delta_image; sgmt_image; time_image ] in | |
58 | + let time_cols_combined = | |
59 | + List.map (Display.left_pad Display.time_col_width) time_cells | |
60 | + |> Notty.I.hcat | |
61 | + in | |
62 | + | |
63 | + (* Add the split title and background color to fill in the padding *) | |
64 | + let row_top = Display.join_pad width title time_cols_combined in | |
65 | + let row_bottom = Notty.I.char bg_attr ' ' width 1 in | |
66 | + Notty.I.(row_top </> row_bottom) |
@@ -8,3 +8,5 @@ val standard_deviation : t -> Duration.t option | ||
8 | 8 | val is_gold : t -> Duration.t -> bool |
9 | 9 | val ahead_by : t -> Duration.t -> Duration.t option |
10 | 10 | val sum_of_best : t list -> Duration.t option |
11 | + | |
12 | +val to_image : string * string -> t * Duration.t option -> width:int -> now:float -> Notty.image |