From df89bcbe74abb9feb60636efc39c4d25b0234795 Mon Sep 17 00:00:00 2001 From: kmaasrud Date: Sun, 9 Apr 2023 10:45:17 +0200 Subject: [PATCH] refactor out color module --- src/color.rs | 13 +++++++++++++ src/main.rs | 17 +++++------------ 2 files changed, 18 insertions(+), 12 deletions(-) create mode 100644 src/color.rs diff --git a/src/color.rs b/src/color.rs new file mode 100644 index 0000000..1db69c3 --- /dev/null +++ b/src/color.rs @@ -0,0 +1,13 @@ +use std::io::{Error, Write}; + +pub fn faint(mut w: W) -> Result<(), Error> { + write!(w, "\x1b[2m") +} + +pub fn reset(mut w: W) -> Result<(), Error> { + write!(w, "\x1b[0m") +} + +pub fn red(mut w: W) -> Result<(), Error> { + write!(w, "\x1b[31m") +} diff --git a/src/main.rs b/src/main.rs index fb77d8f..5ac7459 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ #![feature(byte_slice_trim_ascii)] +mod color; mod cwd; mod git; mod icon; @@ -13,26 +14,18 @@ fn main() -> Result<(), Error> { #[cfg(target_family = "unix")] { - faint(&mut stdout)?; + color::faint(&mut stdout)?; nix::nix(&mut stdout)?; - reset(&mut stdout)?; + color::reset(&mut stdout)?; } cwd::cwd(&mut stdout)?; - faint(&mut stdout)?; + color::faint(&mut stdout)?; git::git(&mut stdout)?; - reset(&mut stdout)?; + color::reset(&mut stdout)?; icon::icon(&mut stdout)?; stdout.flush() } - -fn faint(mut w: W) -> Result<(), Error> { - write!(w, "\x1b[2m") -} - -fn reset(mut w: W) -> Result<(), Error> { - write!(w, "\x1b[0m") -} -- 2.45.2