[ANN] layoutz 0.0.2 - a tiny DSL for beautiful CLI output in OCaml 🪶

Hello all! Been working on layoutz, a tiny, zero-dep combinator lib for making pretty, structured, terminal output: tables, trees, boxes, ANSI styled elements, etc.

Would love to hear how the API feels: Smooth? Any missing primitives you’d expect? Many thanks!

8 Likes

The API certainly looks straightforward enough, and it is nice that it is implemented in some other languages too. Thanks for sharing, I hope to have the chance to play with it later in the week.

1 Like

Any missing primitives you’d expect?

This looks pretty nice, and I’d have a use for it, except that there’s padding byString.length and I want to display a language with 2-byte graphemes.

Although since you provide a string, I can probably still use it. A funny thing I’m already doing with textwrap is to map my strings to ā€˜x’ and ā€˜ ā€˜, wrap that text, then map the ā€˜x’s back to the corresponding grapheme.

This isn’t at all an easy thing to get right in general, especially since rendering outside of your control can affect how things are actually displayed.

1 Like

Many thanks! Let me know if anything feels janky

Thanks for taking a peek!

Spot on… and thanks for putting textwrap on my radar

So the Haskell and Scala API’s already have (more or less) proper realLength handling for such multi-byte and combined graphemes… (cf. pandoc creator suggestion)

After some tinkering and mulling, suspect that the ocaml version will be quite similar to the Haskell realLength under the hood, but maybe with surface feel of textwrap (love how natural the API is btw!)

Not sure if relevant but we do something low-tech in printbox: looping over with Uucp.Break.tty_width_hint

PrintBox_text.ml#L102

1 Like

This looks really nice. Would you ever consider form elements as primitives, or would that be out of scope since it isn’t output?

1 Like

There is an output part to form primitive, I guess it could be just this.

1 Like

thanks for putting this on my radar … tangentially related, but love frame as a top-level widget in PrintBox (will link back if smth similar ends up being vendored into layoutz)

@roerick Thanks for taking a peek! :man_bowing: I guess a static form element would in a sense be ā€œneither input nor outputā€ at this stage … but what @EmileTrotignon said.

Currently tinkering on an Elm runtime to make your elements ā€œanimatableā€, and a form element will likely be part of the lib with that release. Until then though … nothing is stopping the user from making their own ā€œstaticā€ forms.

2 Likes