File tree Expand file tree Collapse file tree 2 files changed +14
-7
lines changed
crates/terminal-colorsaurus/src Expand file tree Collapse file tree 2 files changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,11 @@ mod color;
46
46
mod error;
47
47
mod fmt;
48
48
49
+ /// Low-level utilities for parsing responses to `OSC 10` / `OSC 11` queries.
50
+ pub mod parse {
51
+ pub use crate :: xparsecolor:: xparsecolor;
52
+ }
53
+
49
54
cfg_if ! {
50
55
if #[ cfg( all( any( unix, windows) , not( terminal_colorsaurus_test_unsupported) ) ) ] {
51
56
mod io;
Original file line number Diff line number Diff line change 1
1
use crate :: Color ;
2
2
use std:: str:: from_utf8;
3
3
4
- /// Parses a color value that follows the `XParseColor` format.
5
- /// See <https://www.x.org/releases/current/doc/libX11/libX11/libX11.html#Color_Strings>
6
- /// for a reference of what `XParseColor` supports.
4
+ /// Parses the subset of X11 [Color Strings](https://www.x.org/releases/current/doc/libX11/libX11/libX11.html#Color_Strings)
5
+ /// emitted by terminals in response to `OSC 10` / `OSC 11` queries.
7
6
///
8
- /// Not all formats are supported, just the ones that are returned
9
- /// by the tested terminals. Feel free to open a PR if you encounter
10
- /// a terminal that returns a different format.
11
- pub ( crate ) fn xparsecolor ( input : & [ u8 ] ) -> Option < Color > {
7
+ /// ## Accepted Formats
8
+ /// * `#<red><green><blue>`
9
+ /// * `rgb:<red>/<green>/<blue>`
10
+ /// * `rgba:<red>/<green>/<blue>/<alpha>` (rxvt-unicode extension)
11
+ ///
12
+ /// where `<red>`, `<green>` and `<blue` are hexadecimal numbers with 1-4 digits.
13
+ pub fn xparsecolor ( input : & [ u8 ] ) -> Option < Color > {
12
14
if let Some ( stripped) = input. strip_prefix ( b"#" ) {
13
15
parse_sharp ( from_utf8 ( stripped) . ok ( ) ?)
14
16
} else if let Some ( stripped) = input. strip_prefix ( b"rgb:" ) {
You can’t perform that action at this time.
0 commit comments