https://github.com/pqwy/notty
Declarative terminal graphics for OCaml
https://github.com/pqwy/notty
Last synced: 3 months ago
JSON representation
Declarative terminal graphics for OCaml
- Host: GitHub
- URL: https://github.com/pqwy/notty
- Owner: pqwy
- License: isc
- Created: 2015-10-05T18:20:36.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2024-04-06T08:09:43.000Z (almost 2 years ago)
- Last Synced: 2024-08-04T01:28:37.421Z (over 1 year ago)
- Language: OCaml
- Size: 374 KB
- Stars: 349
- Watchers: 17
- Forks: 31
- Open Issues: 19
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: LICENSE.md
- Support: support/gen_unicode_props.ml
Awesome Lists containing this project
- awesome-list - notty
- awesome-ocaml - Notty - Notty is a declarative terminal library for OCaml, structured around the notion of composable images. (User Interface)
README
# Notty — Declaring terminals
Notty is a declarative terminal library for OCaml structured around a notion
of composable images. It tries to abstract away the basic terminal programming
model, providing something simpler and more expressive.
The core layout engine and IO codecs are pure platform-independent OCaml.
Distribution includes modules with input and output facilities for Unix, and Lwt
on Unix.
As an attempt to redefine terminal programming, Notty has to be
_opinionated_. It assumes Unicode throughout, does not have universal support
for various terminals out there, and has a peculiar programming and rendering
model.
Notty's core API was heavily influenced by Haskell's [Vty][vty].
## Where to start
Check out the [documentation], [examples], or peek directly into the [interface]
file.
Building with `dune build @ex` will produce several little example programs that
also double as tests.
```OCaml
(* Game of Life with ZX Spectrum kitsch. *)
let dot : image = I.uchar A.(fg lightred) (Uchar.of_int 0x25cf) 1 1
let background step (n, m) =
let k = 24. *. sin (float (step + m + n) /. 10.) |> truncate in
if k > 0 then I.char A.(fg (gray k)) '.' 1 1 else I.void 1 1
let render (w, h) step life : image =
I.tabulate w (h - 1) @@ fun x y ->
let pt = (x, y) in
if CSet.mem pt life then dot else background step pt
```
[documentation]: https://pqwy.github.io/notty/doc
[examples]: http://pqwy.github.io/notty/doc/Notty.html#examples
[interface]: https://github.com/pqwy/notty/blob/master/src/notty.mli
[vty]: https://hackage.haskell.org/package/vty
## What?
- _Notty?_
Terminals are tedious to program for. Notty tries to abstract the tedium away,
leaving you with a more pleasant programming surface that's quite unlike a TTY.
Hence, _No-TTY_.
- A new kind of Rust terminal?
This Notty has no connection to any other body of code named Notty.
- Why make yet another terminal output library?
Because:
* It allows one to *describe* what should be seen, as opposed to *commanding*
a terminal.
* It's pretty compact. Both bells and whistles can be implemented separately.
* Core is easy to glue onto various IO backends.
* Pure platform-independent OCaml.



