Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bash/terminal-colorsaurus
A library for answering the question «Is this terminal dark or light?» 🦕
https://github.com/bash/terminal-colorsaurus
dark-mode terminal tty
Last synced: 5 days ago
JSON representation
A library for answering the question «Is this terminal dark or light?» 🦕
- Host: GitHub
- URL: https://github.com/bash/terminal-colorsaurus
- Owner: bash
- License: apache-2.0
- Created: 2024-01-16T15:40:32.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-09T07:25:19.000Z (27 days ago)
- Last Synced: 2025-01-23T19:13:12.729Z (13 days ago)
- Topics: dark-mode, terminal, tty
- Language: Rust
- Homepage:
- Size: 1.69 MB
- Stars: 45
- Watchers: 2
- Forks: 3
- Open Issues: 9
-
Metadata Files:
- Readme: readme.md
- Changelog: changelog.md
- License: license-apache.txt
Awesome Lists containing this project
README
# terminal-colorsaurus 🦕
[![Docs](https://img.shields.io/docsrs/terminal-colorsaurus/latest)](https://docs.rs/terminal-colorsaurus)
[![Crate Version](https://img.shields.io/crates/v/terminal-colorsaurus)](https://crates.io/crates/terminal-colorsaurus)A cross-platform library for determining the terminal's background and foreground color. \
It answers the question *«Is this terminal dark or light?»*.Works in all major terminals including Windows Terminal (starting with v1.22).
## Example
```rust,no_run
use terminal_colorsaurus::{color_scheme, QueryOptions, ColorScheme};match color_scheme(QueryOptions::default()).unwrap() {
ColorScheme::Dark => { /* ... */ },
ColorScheme::Light => { /* ... */ },
}
```## [Docs](https://docs.rs/terminal-colorsaurus)
## Inspiration
This crate borrows ideas from many other projects. This list is by no means exhaustive.* [xterm-query]: Use `mio` to wait for the terminal's response with a timeout.
* [termbg]: Lists a lot of terminals which served as a good starting point for me to test terminals as well.
* [macOS doesn't like polling /dev/tty][macos-dev-tty] by Nathan Craddock
* [This excellent answer on Stack Overflow][perceived-lightness] for determining the perceived lightness of a color.
* [This comment in the Terminal WG](https://gitlab.freedesktop.org/terminal-wg/specifications/-/issues/8#note_151381) for the `DA1` trick
to easily detect terminals that don't support querying the colors with `OSC 10` / `OSC 11`.## License
Licensed under either of* Apache License, Version 2.0
([license-apache.txt](license-apache.txt) or )
* MIT license
([license-mit.txt](license-mit.txt) or )at your option.
## Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
dual licensed as above, without any additional terms or conditions.[xterm-query]: https://github.com/Canop/xterm-query
[termbg]: https://github.com/dalance/termbg
[macos-dev-tty]: https://nathancraddock.com/blog/macos-dev-tty-polling/
[perceived-lightness]: https://stackoverflow.com/a/56678483