Terminal styling and layout widgets for OCaml (tables, trees, panels, colors)
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Upgrade to ocamlformat 0.29.0; fix csvt/sexpt streaming; reformat

- Update .ocamlformat to 0.29.0 across all 591 files
- csvt: reuse single Buffer.t for field reads (no alloc per field)
- sexpt: Obj members decoded from stream into Dict, typed Variant GADT
- Reformat all source files for 0.29.0

+62 -62
+1 -1
.ocamlformat
··· 1 - version=0.28.1 1 + version = 0.29.0
+6 -6
lib/progress.ml
··· 251 251 t.s <- with_current t.s.total t.s; 252 252 display t; 253 253 t.finished <- true; 254 - if t.enabled then begin 255 - if t.cfg.ppf == Format.std_formatter then begin 254 + if t.enabled then 255 + begin if t.cfg.ppf == Format.std_formatter then begin 256 256 cursor_hidden := false; 257 257 output_string stdout show_cursor; 258 258 output_char stdout '\n'; ··· 262 262 Format.pp_print_newline t.cfg.ppf (); 263 263 Format.pp_print_flush t.cfg.ppf () 264 264 end 265 - end 265 + end 266 266 end 267 267 268 268 let clear t = 269 269 if not t.finished then begin 270 270 t.finished <- true; 271 - if t.enabled then begin 272 - if t.cfg.ppf == Format.std_formatter then begin 271 + if t.enabled then 272 + begin if t.cfg.ppf == Format.std_formatter then begin 273 273 cursor_hidden := false; 274 274 output_string stdout "\r\027[K"; 275 275 output_string stdout show_cursor; ··· 279 279 Fmt.string t.cfg.ppf "\r\027[K"; 280 280 Format.pp_print_flush t.cfg.ppf () 281 281 end 282 - end 282 + end 283 283 end
+14 -14
lib/progress.mli
··· 14 14 full control or integration with an existing render loop. 15 15 16 16 {[ 17 - let cfg = Progress.config () in 18 - let s = Progress.state ~total:100 "Downloading" in 19 - let s = Progress.incr s in 20 - let line = Progress.render ~frame:0 cfg s in 21 - print_string ("\r" ^ line) 17 + let cfg = Progress.config () in 18 + let s = Progress.state ~total:100 "Downloading" in 19 + let s = Progress.incr s in 20 + let line = Progress.render ~frame:0 cfg s in 21 + print_string ("\r" ^ line) 22 22 ]} 23 23 24 24 {2 Imperative Wrapper} ··· 26 26 Convenient mutable wrapper that handles rendering automatically. 27 27 28 28 {[ 29 - let bar = Progress.v ~total:100 "Downloading" in 30 - for _ = 1 to 100 do 31 - Progress.tick bar 32 - done; 33 - Progress.finish bar 29 + let bar = Progress.v ~total:100 "Downloading" in 30 + for _ = 1 to 100 do 31 + Progress.tick bar 32 + done; 33 + Progress.finish bar 34 34 ]} 35 35 36 36 {2 Multi-phase Operations} 37 37 38 38 {[ 39 - let bar = Progress.v ~total:10 "Working" in 40 - Progress.update bar ~phase:"Fetch" ~msg:"file1.txt"; 41 - Progress.update bar ~phase:"Build" ~msg:"compiling"; 42 - Progress.finish bar 39 + let bar = Progress.v ~total:10 "Working" in 40 + Progress.update bar ~phase:"Fetch" ~msg:"file1.txt"; 41 + Progress.update bar ~phase:"Build" ~msg:"compiling"; 42 + Progress.finish bar 43 43 ]} *) 44 44 45 45 (** {1 Functional Core} *)
+6 -6
lib/tree.mli
··· 45 45 46 46 Example: 47 47 {[ 48 - type dir = { name : string; children : dir list } 48 + type dir = { name : string; children : dir list } 49 49 50 - let tree = 51 - Tree.v 52 - (fun render dir -> 53 - Node (Span.text dir.name, List.map render dir.children)) 54 - root_dir 50 + let tree = 51 + Tree.v 52 + (fun render dir -> 53 + Node (Span.text dir.name, List.map render dir.children)) 54 + root_dir 55 55 ]} *) 56 56 57 57 (** {1 Rendering} *)
+35 -35
lib/tty.mli
··· 13 13 {2 Styled Text} 14 14 15 15 {[ 16 - open Tty 16 + open Tty 17 17 18 - let () = 19 - let style = Style.(bold + fg Color.green) in 20 - Fmt.pr "%a@." (Style.styled style Fmt.string) "Success!" 18 + let () = 19 + let style = Style.(bold + fg Color.green) in 20 + Fmt.pr "%a@." (Style.styled style Fmt.string) "Success!" 21 21 ]} 22 22 23 23 {2 Tables} 24 24 25 25 {[ 26 - open Tty 26 + open Tty 27 27 28 - let () = 29 - let table = 30 - Table.( 31 - of_rows ~border:Border.rounded 32 - [ column "Name"; column ~align:`Right "Age" ] 33 - [ 34 - [ Span.text "Alice"; Span.text "30" ]; 35 - [ Span.text "Bob"; Span.text "25" ]; 36 - ]) 37 - in 38 - Table.pp Format.std_formatter table 28 + let () = 29 + let table = 30 + Table.( 31 + of_rows ~border:Border.rounded 32 + [ column "Name"; column ~align:`Right "Age" ] 33 + [ 34 + [ Span.text "Alice"; Span.text "30" ]; 35 + [ Span.text "Bob"; Span.text "25" ]; 36 + ]) 37 + in 38 + Table.pp Format.std_formatter table 39 39 ]} 40 40 41 41 {2 Trees} 42 42 43 43 {[ 44 - open Tty 44 + open Tty 45 45 46 - let () = 47 - let tree = 48 - Tree.of_tree 49 - (Node 50 - ( Span.text "src", 51 - [ 52 - Node (Span.text "lib", [ Node (Span.text "tty.ml", []) ]); 53 - Node (Span.text "test", []); 54 - ] )) 55 - in 56 - Tree.pp Format.std_formatter tree 46 + let () = 47 + let tree = 48 + Tree.of_tree 49 + (Node 50 + ( Span.text "src", 51 + [ 52 + Node (Span.text "lib", [ Node (Span.text "tty.ml", []) ]); 53 + Node (Span.text "test", []); 54 + ] )) 55 + in 56 + Tree.pp Format.std_formatter tree 57 57 ]} 58 58 59 59 {2 Panels} 60 60 61 61 {[ 62 - open Tty 62 + open Tty 63 63 64 - let () = 65 - let panel = 66 - Panel.create ~title:(Span.text "Status") 67 - (Span.text "All systems operational") 68 - in 69 - Panel.pp Format.std_formatter panel 64 + let () = 65 + let panel = 66 + Panel.create ~title:(Span.text "Status") 67 + (Span.text "All systems operational") 68 + in 69 + Panel.pp Format.std_formatter panel 70 70 ]} *) 71 71 72 72 (** {1 Terminal Queries} *)