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;
4646mod error;
4747mod fmt;
4848
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+
4954cfg_if ! {
5055 if #[ cfg( all( any( unix, windows) , not( terminal_colorsaurus_test_unsupported) ) ) ] {
5156 mod io;
Original file line number Diff line number Diff line change 11use crate :: Color ;
22use std:: str:: from_utf8;
33
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.
76///
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 > {
1214 if let Some ( stripped) = input. strip_prefix ( b"#" ) {
1315 parse_sharp ( from_utf8 ( stripped) . ok ( ) ?)
1416 } else if let Some ( stripped) = input. strip_prefix ( b"rgb:" ) {
You can’t perform that action at this time.
0 commit comments