42 stable releases (8 major)

9.0.3 Jun 29, 2024
8.0.2 Jun 19, 2024
7.4.0 May 6, 2024
7.3.1 Dec 30, 2023
1.1.2 Oct 17, 2022

#310 in Command-line interface

Download history 25/week @ 2024-07-06 1/week @ 2024-07-13 87/week @ 2024-07-27 5/week @ 2024-08-10 2/week @ 2024-08-17 1/week @ 2024-08-24 6/week @ 2024-08-31 9/week @ 2024-09-07 6/week @ 2024-09-14 61/week @ 2024-09-21 19/week @ 2024-09-28 3/week @ 2024-10-05 16/week @ 2024-10-12 1/week @ 2024-10-19

60 downloads per month

MIT license

30KB
642 lines

Cod

Cod is a lightweight, (almost) zero-dependency command-line drawing utility. It works much like a basic C library, where you call functions to produce effects on the screen, rather than use a struct or some fancy macro syntax. However, it provides several conveniences above the ordinary C lib:

  • Namespacing, i.e. cod::style::bold() and cod::color::with()
    • A prelude, imports all submodules
  • Closure-based styling, i.e. style::with::bold(|| {...})
  • Basic input gathering, i.e. read::key() or read::line()
    • Optional, behind feature crossterm
    • Enables (and exposes) a dependency on crossterm
  • Basic terminal operations (cursor style, raw mode, terminal size)
    • Also behind feature crossterm

There are some examples in the examples directory, but as cod aims to be as simple to use as possible, they aren't prioritized. Moreover, everything in cod is well-documented, so it's arguably easier to just look through the docs!

Note: most cod functions don't flush stdout, so if you run into issues, try that!

Bold and faint

You may notice that while there are separate functions for enabling bold and faint, they both share de::weight. That's because, true to ANSI form, terminals and VTE's can't agree on it, so we're stuck with only one way to disable both. That goes for both with::bold and with::faint as well!

Additionally, on some terminals, bold and faint are mutually exclusive. On some, like Alacritty, they can coexist only if the text is uncolored. In general, be careful when using both at the same time. You can use the bold-faint example to test your terminal.

Dependencies

~0–5MB