A Nix-friendly SQLite-enhanced fork of Flitter, a speedrunning split timer for Unix-style terminals
Revisão | 52844dd1ecaf4ce70b3aa6d51f11f43855269c16 (tree) |
---|---|
Hora | 2023-05-14 09:35:17 |
Autor | Corbin <cds@corb...> |
Commiter | Corbin |
Lift some constants.
@@ -1,3 +0,0 @@ | ||
1 | -(* An attempt, or "run", is a list of segments. It can be seen as an | |
2 | - association list from strings to relative durations. *) | |
3 | -type t = Split.t list |
@@ -1,52 +1,44 @@ | ||
1 | 1 | open Core |
2 | 2 | open Notty |
3 | 3 | |
4 | -let big_font_map = | |
5 | - let font = | |
6 | - [ | |
7 | - "00000111112222233333444445555566666777778888899999 !!::.."; | |
8 | - ".^^. .| .^^. .^^. . | |^^^ .^^ ^^^| .^^. .^^. | "; | |
9 | - "| | | .^ .^ |..| |.. |.. ][ ^..^ ^..| | ^ "; | |
10 | - "| | | .^ . | | | | | | | | | ^ ^ "; | |
11 | - " ^^ ^^^ ^^^^ ^^ ^ ^^^ ^^ ^ ^^ ^^ ^ ^ "; | |
12 | - ] | |
13 | - in | |
14 | - | |
15 | - let uchar_of_char = | |
16 | - let open Caml.Uchar in | |
17 | - function | |
18 | - | '[' -> of_int 0x258C | |
19 | - | ']' -> of_int 0x2590 | |
20 | - | '|' -> of_int 0x2588 | |
21 | - | '.' -> of_int 0x2584 | |
22 | - | '^' -> of_int 0x2580 | |
23 | - | ch -> of_char ch | |
24 | - in | |
25 | - | |
26 | - let fst_line = List.hd_exn font in | |
27 | - | |
28 | - let extract_char_at start_idx = | |
29 | - let ch = String.get fst_line start_idx in | |
30 | - let end_idx = String.rindex_exn fst_line ch + 1 in | |
31 | - let char_rows = | |
32 | - List.map (List.tl_exn font) ~f:(fun line -> | |
33 | - let row_str = String.(drop_prefix (prefix line end_idx) start_idx) in | |
34 | - let row_list = String.to_list row_str in | |
35 | - Array.of_list_map row_list ~f:uchar_of_char) | |
36 | - in | |
37 | - | |
38 | - (char_rows, end_idx) | |
39 | - in | |
40 | - | |
41 | - let rec map_chars_at map idx = | |
42 | - if idx >= String.length fst_line then map | |
43 | - else | |
44 | - let img, next_idx = extract_char_at idx in | |
45 | - let ch = String.get fst_line idx in | |
46 | - map_chars_at (Map.add_exn map ~key:ch ~data:img) next_idx | |
47 | - in | |
48 | - | |
49 | - map_chars_at (Map.empty (module Char)) 0 | |
4 | +let fst_line = "00000111112222233333444445555566666777778888899999 !!::.." | |
5 | + | |
6 | +let font = | |
7 | + [ | |
8 | + ".^^. .| .^^. .^^. . | |^^^ .^^ ^^^| .^^. .^^. | "; | |
9 | + "| | | .^ .^ |..| |.. |.. ][ ^..^ ^..| | ^ "; | |
10 | + "| | | .^ . | | | | | | | | | ^ ^ "; | |
11 | + " ^^ ^^^ ^^^^ ^^ ^ ^^^ ^^ ^ ^^ ^^ ^ ^ "; | |
12 | + ] | |
13 | + | |
14 | +let uchar_of_char = | |
15 | + let open Caml.Uchar in | |
16 | + function | |
17 | + | '[' -> of_int 0x258C | |
18 | + | ']' -> of_int 0x2590 | |
19 | + | '|' -> of_int 0x2588 | |
20 | + | '.' -> of_int 0x2584 | |
21 | + | '^' -> of_int 0x2580 | |
22 | + | ch -> of_char ch | |
23 | + | |
24 | +let extract_char_at start_idx = | |
25 | + let ch = String.get fst_line start_idx in | |
26 | + let end_idx = String.rindex_exn fst_line ch + 1 in | |
27 | + let char_rows = | |
28 | + List.map font ~f:(fun line -> | |
29 | + let row_str = String.(drop_prefix (prefix line end_idx) start_idx) in | |
30 | + let row_list = String.to_list row_str in | |
31 | + Array.of_list_map row_list ~f:uchar_of_char) | |
32 | + in (char_rows, end_idx) | |
33 | + | |
34 | +let rec map_chars_at map idx = | |
35 | + if idx >= String.length fst_line then map | |
36 | + else | |
37 | + let img, next_idx = extract_char_at idx in | |
38 | + let ch = String.get fst_line idx in | |
39 | + map_chars_at (Map.add_exn map ~key:ch ~data:img) next_idx | |
40 | + | |
41 | +let big_font_map = map_chars_at (Map.empty (module Char)) 0 | |
50 | 42 | |
51 | 43 | let image_of_string attr str = |
52 | 44 | List.map (String.to_list str) ~f:(fun ch -> |
@@ -3,7 +3,7 @@ | ||
3 | 3 | (wrapped false) |
4 | 4 | (libraries core core_kernel core_unix sexplib sqlite3 lwt.unix notty notty.unix re color sexp_pretty) |
5 | 5 | (preprocess (pps lwt_ppx ppx_sexp_conv)) |
6 | - (modules_without_implementation timer_types split attempt history route) | |
6 | + (modules_without_implementation timer_types route) | |
7 | 7 | ) |
8 | 8 | |
9 | 9 | ; vim:ft=scheme |
@@ -1,16 +0,0 @@ | ||
1 | -(* A history is a sequence of attempts. Relative to a history, some segments | |
2 | - are golden; a gold segment has the shortest relative duration compared to | |
3 | - any other attempt. | |
4 | - | |
5 | - Since every attempt has the same titles, we can perform a struct-of-arrays | |
6 | - transformation, and a history is represented by an array of titles and a | |
7 | - matrix of relative durations. In order to efficiently know about golden | |
8 | - splits, we also have an array of indices which indicate which attempt | |
9 | - contains which gold. | |
10 | - | |
11 | - The matrix is oriented so that each inner array represents a single attempt. *) | |
12 | -type t = { | |
13 | - titles : string array; | |
14 | - segments : Duration.t array array; | |
15 | - golds : int array; | |
16 | -} |
@@ -1,3 +0,0 @@ | ||
1 | -(* A split is a title and a duration. A split with relative duration is a | |
2 | - "segment", and a split with absolute duration is a "milestone". *) | |
3 | -type t = string * Duration.t |