Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/NorfairKing/safe-coloured-text


https://github.com/NorfairKing/safe-coloured-text

Last synced: about 1 month ago
JSON representation

Awesome Lists containing this project

README

        

# Safe Coloured Text

## Requirements / Design goals

* Use `String`/`Text`/`ByteString` correctly: Some things are strings of characters, some things are text, some things are bytes. Those are not the same.
* No partial functions
* Represent chunks of coloured text purely
* Be able to print chunks of coloured text quickly
* Be able to turn chunks of coloured text into non-coloured text for when terminals don't support (certain) colours.
* (Ideally) output minimal amounts of overhead
* As few dependencies as possible.
* Well-tested
* British spelling (because I can)

## Few dependencies

Only `bytestring`, `text` and `terminfo` and the relevant `validity` library.

## Well-tested

The `safe-coloured-text` library already has over 10'000 tests.
Most of them are golden tests, and ensure that the output stays correct even if the library changes.

## Minimal output

These two strings look the same, but the second is almost twice as long:

`safe-coloured-text`:
```
\ESC[34mTests:\ESC[m

Passed: \ESC[32m0\ESC[m
Failed: \ESC[32m0\ESC[m
Test suite took \ESC[33m 0.00 seconds\ESC[m
```
`rainbow`:
```
\ESC[0m\ESC[38;5;4mTests:\ESC[0m
\ESC[0m\ESC[0m
\ESC[0m\ESC[0m
\ESC[0m\ESC[0m
\ESC[0m\ESC[0m
\ESC[0m \ESC[0m\ESC[0mPassed: \ESC[0m\ESC[0m\ESC[38;5;2m0\ESC[0m
\ESC[0m \ESC[0m\ESC[0mFailed: \ESC[0m\ESC[0m\ESC[38;5;2m0\ESC[0m
\ESC[0m \ESC[0m\ESC[0mTest suite took \ESC[0m\ESC[0m\ESC[38;5;3m 0.00 seconds\ESC[0m
\ESC[0m\ESC[0m
```

The `safe-coloured-text` does not emit sequences if a chunk is completely plain, but it does not deal with inter-chunk inefficiencies.

## Supports 24-bit colour

This library supports outputting sequences for 24-bit colours.
My `urxvt` terminal emulator doesn't even support that, so whatever, but at least it's possible.