Closed terencode closed 2 years ago
Not sure I understand you. The definition of 'a Fmt.t
is:
type 'a t = Format.formatter -> 'a -> unit
Ok I might have wrongly understood how this works. How would I go about doing what I want in the example, that is, print to stdout a formatted string with a specific style ?
Something like that:
let pp_hello ppf n = Fmt.pf ppf "Hello %s" n
let pp_red_hello = Fmt.styled (`Fg `Red) pp_hello
let () =
let () = Fmt.set_style_renderer Fmt.stdout `Ansi_tty in
Fmt.pr "%a" pp_red_hello "World"
If you have further questions about using the library, please ask them on https://discuss.ocaml.org/ (you can log in with your github account).
Ok, thanks for your help. I will use discuss next time (I just created an account).
According to the documentation, applying
Fmt.styled
to a formatter returns one of the same type :but in practice, the
'a
is replaced by unit :becomes
and is thus only usable with simple strings.
Here is an example I would expect to work but doesn't :
I had the same behaviour on OCaml 4.08.1 & 4.14.0