summaryrefslogtreecommitdiffstats
path: root/vendor/anstyle-wincon/examples/set.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:41:35 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:41:35 +0000
commit7e5d7eea9c580ef4b41a765bde624af431942b96 (patch)
tree2c0d9ca12878fc4525650aa4e54d77a81a07cc09 /vendor/anstyle-wincon/examples/set.rs
parentAdding debian version 1.70.0+dfsg1-9. (diff)
downloadrustc-7e5d7eea9c580ef4b41a765bde624af431942b96.tar.xz
rustc-7e5d7eea9c580ef4b41a765bde624af431942b96.zip
Merging upstream version 1.70.0+dfsg2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/anstyle-wincon/examples/set.rs')
-rw-r--r--vendor/anstyle-wincon/examples/set.rs57
1 files changed, 0 insertions, 57 deletions
diff --git a/vendor/anstyle-wincon/examples/set.rs b/vendor/anstyle-wincon/examples/set.rs
deleted file mode 100644
index 3b9f9093a..000000000
--- a/vendor/anstyle-wincon/examples/set.rs
+++ /dev/null
@@ -1,57 +0,0 @@
-#![cfg_attr(not(windows), allow(dead_code))]
-
-#[cfg(not(windows))]
-fn main() {
- panic!("unsupported");
-}
-
-#[cfg(windows)]
-fn main() -> Result<(), lexopt::Error> {
- let args = Args::parse()?;
- let stdout = std::io::stdout();
- let mut stdout = anstyle_wincon::Console::new(stdout.lock())
- .map_err(|_err| lexopt::Error::from("could not open `stdout` for color control"))?;
-
- let fg = args.fg.and_then(|c| c.into_ansi());
- let bg = args.bg.and_then(|c| c.into_ansi());
-
- let _ = stdout.write(fg, bg, "".as_bytes());
-
- std::mem::forget(stdout);
-
- Ok(())
-}
-
-#[derive(Default)]
-struct Args {
- fg: Option<anstyle::Ansi256Color>,
- bg: Option<anstyle::Ansi256Color>,
-}
-
-impl Args {
- fn parse() -> Result<Self, lexopt::Error> {
- use lexopt::prelude::*;
-
- let mut res = Args::default();
-
- let mut args = lexopt::Parser::from_env();
- while let Some(arg) = args.next()? {
- match arg {
- Long("fg") => {
- res.fg = Some(
- args.value()?
- .parse_with(|s| s.parse::<u8>().map(anstyle::Ansi256Color))?,
- );
- }
- Long("bg") => {
- res.fg = Some(
- args.value()?
- .parse_with(|s| s.parse::<u8>().map(anstyle::Ansi256Color))?,
- );
- }
- _ => return Err(arg.unexpected()),
- }
- }
- Ok(res)
- }
-}