~kmaasrud/prompt

df89bcbe74abb9feb60636efc39c4d25b0234795 — kmaasrud 1 year, 5 months ago 238d13f
refactor out color module
2 files changed, 18 insertions(+), 12 deletions(-)

A src/color.rs
M src/main.rs
A src/color.rs => src/color.rs +13 -0
@@ 0,0 1,13 @@
use std::io::{Error, Write};

pub fn faint<W: Write>(mut w: W) -> Result<(), Error> {
    write!(w, "\x1b[2m")
}

pub fn reset<W: Write>(mut w: W) -> Result<(), Error> {
    write!(w, "\x1b[0m")
}

pub fn red<W: Write>(mut w: W) -> Result<(), Error> {
    write!(w, "\x1b[31m")
}

M src/main.rs => src/main.rs +5 -12
@@ 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<W: Write>(mut w: W) -> Result<(), Error> {
    write!(w, "\x1b[2m")
}

fn reset<W: Write>(mut w: W) -> Result<(), Error> {
    write!(w, "\x1b[0m")
}