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.

ocaml-tty: enable MDX on lib/tty.mli

Run mdx on lib/tty.mli so the four {[ ... ]} odoc blocks (Styled
Text, Tables, Trees, Panels) now type-check.

Each block was a `let () = ...` toplevel-effect snippet that would
print to stdout at mdx test time. Renamed each to a `demo_X`
function (`demo_styled`, `demo_table`, `demo_tree`, `demo_panel`)
so the example shows the rendering wiring without flooding stderr.

Two API drift fixes:
- The Tree node constructor needed `Tree.Node` (not bare `Node` after
`open Tty`).
- `Panel.create` is named `Panel.v`.

Switched the printers to `Fmt.pr "%a@."` instead of passing
`Format.std_formatter` directly, matching the repo's Fmt convention.

+14 -13
+2 -2
lib/dune
··· 7 7 (names winsize))) 8 8 9 9 (mdx 10 - (files tree.mli progress.mli) 11 - (libraries nox-tty logs logs.fmt eio eio.core eio.unix)) 10 + (files tree.mli progress.mli tty.mli) 11 + (libraries nox-tty fmt logs logs.fmt eio eio.core eio.unix))
+12 -11
lib/tty.mli
··· 15 15 {[ 16 16 open Tty 17 17 18 - let () = 18 + let demo_styled () = 19 19 let style = Style.(bold + fg Color.green) in 20 20 Fmt.pr "%a@." (Style.styled style Fmt.string) "Success!" 21 21 ]} ··· 25 25 {[ 26 26 open Tty 27 27 28 - let () = 28 + let demo_table () = 29 29 let table = 30 30 Table.( 31 31 of_rows ~border:Border.rounded ··· 35 35 [ Span.text "Bob"; Span.text "25" ]; 36 36 ]) 37 37 in 38 - Table.pp Format.std_formatter table 38 + Fmt.pr "%a@." Table.pp table 39 39 ]} 40 40 41 41 {2 Trees} ··· 43 43 {[ 44 44 open Tty 45 45 46 - let () = 46 + let demo_tree () = 47 47 let tree = 48 48 Tree.of_tree 49 - (Node 49 + (Tree.Node 50 50 ( Span.text "src", 51 51 [ 52 - Node (Span.text "lib", [ Node (Span.text "tty.ml", []) ]); 53 - Node (Span.text "test", []); 52 + Tree.Node 53 + (Span.text "lib", [ Tree.Node (Span.text "tty.ml", []) ]); 54 + Tree.Node (Span.text "test", []); 54 55 ] )) 55 56 in 56 - Tree.pp Format.std_formatter tree 57 + Fmt.pr "%a@." Tree.pp tree 57 58 ]} 58 59 59 60 {2 Panels} ··· 61 62 {[ 62 63 open Tty 63 64 64 - let () = 65 + let demo_panel () = 65 66 let panel = 66 - Panel.create ~title:(Span.text "Status") 67 + Panel.v ~title:(Span.text "Status") 67 68 (Span.text "All systems operational") 68 69 in 69 - Panel.pp Format.std_formatter panel 70 + Fmt.pr "%a@." Panel.pp panel 70 71 ]} *) 71 72 72 73 (** {1 Terminal Queries} *)