• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

A Nix-friendly SQLite-enhanced fork of Flitter, a speedrunning split timer for Unix-style terminals


Commit MetaInfo

Révision45b69bfe94bdf5aab1ac7eb28d2c1705d4d6f5c1 (tree)
l'heure2023-07-04 01:51:27
AuteurCorbin <cds@corb...>
CommiterCorbin

Message de Log

Duplicate and simplify row-displaying logic.

Change Summary

Modification

--- a/src/display.ml
+++ b/src/display.ml
@@ -112,7 +112,6 @@ let split_row timer width i =
112112 in
113113
114114 let plain_duration = uncolored_duration 1 in
115- let wr_duration = uncolored_duration 2 in
116115 let curr_split = get_curr_split timer.state in
117116 let show_comparison = i > curr_split in
118117
--- a/src/display.mli
+++ b/src/display.mli
@@ -1,5 +1,10 @@
11 type t
22
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+
38 val make : unit -> t
49 val draw : t -> Timer_types.timer -> unit
510 val close : t -> unit
--- a/src/gold.ml
+++ b/src/gold.ml
@@ -16,3 +16,51 @@ let sum_of_best =
1616 (fun sd (_, _, min) ->
1717 match (min, sd) with Some best, Some d -> Some (d + best) | _, _ -> None)
1818 (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)
--- a/src/gold.mli
+++ b/src/gold.mli
@@ -8,3 +8,5 @@ val standard_deviation : t -> Duration.t option
88 val is_gold : t -> Duration.t -> bool
99 val ahead_by : t -> Duration.t -> Duration.t option
1010 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