Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/norfairking/safe-coloured-text
https://github.com/norfairking/safe-coloured-text
Last synced: 5 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/norfairking/safe-coloured-text
- Owner: NorfairKing
- Created: 2021-03-02T15:36:21.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-10-12T23:01:50.000Z (2 months ago)
- Last Synced: 2024-12-06T10:46:08.659Z (18 days ago)
- Language: Haskell
- Homepage: https://cs-syd.eu/posts/2021-03-07-safe-coloured-text
- Size: 177 KB
- Stars: 17
- Watchers: 4
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
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[mPassed: \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.