A Nix-friendly SQLite-enhanced fork of Flitter, a speedrunning split timer for Unix-style terminals
Révision | 8aa997f0c15b38ce52569a1387afea104f4bcdb5 (tree) |
---|---|
l'heure | 2023-07-07 12:19:42 |
Auteur | Corbin <cds@corb...> |
Commiter | Corbin |
Make Gold.to_image foldable.
Okay! This was the missing piece. Now to restore the big patch...
@@ -1,10 +1,8 @@ | ||
1 | 1 | type t |
2 | 2 | |
3 | 3 | val time_col_width : int |
4 | - | |
5 | 4 | val left_pad : int -> Notty.image -> Notty.image |
6 | 5 | val join_pad : int -> Notty.image -> Notty.image -> Notty.image |
7 | - | |
8 | 6 | val make : unit -> t |
9 | 7 | val draw : t -> Timer_types.timer -> unit |
10 | 8 | val close : t -> unit |
@@ -17,7 +17,7 @@ let sum_of_best = | ||
17 | 17 | match (min, sd) with Some best, Some d -> Some (d + best) | _, _ -> None) |
18 | 18 | (Some 0) |
19 | 19 | |
20 | -let to_image (_, s) ((avg, stddev, min), md) ~width ~now = | |
20 | +let to_image s ((avg, stddev, min), md) ~width ~now = | |
21 | 21 | (* XXX should be Colors.selection_bg on the active split; |
22 | 22 | parameterize the color and add a zipper to Run.t? *) |
23 | 23 | let bg_attr = Colors.default_bg in |
@@ -48,19 +48,24 @@ let to_image (_, s) ((avg, stddev, min), md) ~width ~now = | ||
48 | 48 | |
49 | 49 | (* Compute the image of the split's segment time *) |
50 | 50 | let sgmt_image = plain_duration min in |
51 | + fun mcd -> | |
52 | + (* Compute the image of the split's absolute time *) | |
53 | + let time_image = plain_duration mcd in | |
51 | 54 | |
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 | + (* Combine the three time columns together with proper padding *) | |
56 | + let time_cells = [ delta_image; sgmt_image; time_image ] in | |
57 | + let time_cols_combined = | |
58 | + List.map (Display.left_pad Display.time_col_width) time_cells | |
59 | + |> Notty.I.hcat | |
60 | + in | |
55 | 61 | |
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) | |
62 | + (* Add the split title and background color to fill in the padding *) | |
63 | + let row_top = Display.join_pad width title time_cols_combined in | |
64 | + let row_bottom = Notty.I.char bg_attr ' ' width 1 in | |
65 | + let c = | |
66 | + match (mcd, md, min) with | |
67 | + | Some cd, Some d, _ -> Some (cd + d) | |
68 | + | Some cd, None, Some m -> Some (cd + m) | |
69 | + | _ -> None | |
70 | + in | |
71 | + (Notty.I.(row_top </> row_bottom), c) |
@@ -9,4 +9,10 @@ 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 | 11 | |
12 | -val to_image : string * string -> t * Duration.t option -> width:int -> now:float -> Notty.image | |
12 | +val to_image : | |
13 | + string -> | |
14 | + t * Duration.t option -> | |
15 | + width:int -> | |
16 | + now:float -> | |
17 | + Duration.t option -> | |
18 | + Notty.image * Duration.t option |
@@ -25,7 +25,7 @@ let from_db db game category = | ||
25 | 25 | Gold.of_stats |
26 | 26 | ( Some (int_of_float (Sqlite3.Data.to_float_exn row.(2))), |
27 | 27 | Some (int_of_float (Sqlite3.Data.to_float_exn row.(3))), |
28 | - Some (Sqlite3.Data.to_int_exn row.(4)))))) | |
28 | + Some (Sqlite3.Data.to_int_exn row.(4)) ) )) ) | |
29 | 29 | |
30 | 30 | let map f (i, l) = (i, List.map ~f:(fun (s, t, x) -> (s, t, f x)) l) |
31 | 31 | let iter f (_, l) = List.iter ~f:(fun (s, t, x) -> f x) l |