Very start of render color terminal

This commit is contained in:
Chad Stearns 2020-03-16 02:22:07 -04:00
parent 009e1fa176
commit f8dd2fb9a1

View file

@ -11,6 +11,38 @@ pub struct Report {
pub text: ReportText, pub text: ReportText,
} }
pub struct Palette {
pub primary: Color,
pub error: Color,
}
pub enum Color {
White,
Red,
}
pub const default_palette: Palette = Palette {
primary: Color::White,
error: Color::Red,
};
impl Color {
pub fn render(self, str: &str) -> String {
use Color::*;
match self {
Red => {
red(str)
}
White => {
white(str)
}
}
}
}
pub fn can_problem(filename: PathBuf, problem: Problem) -> Report { pub fn can_problem(filename: PathBuf, problem: Problem) -> Report {
let mut texts = Vec::new(); let mut texts = Vec::new();
@ -77,6 +109,33 @@ fn newline() -> ReportText {
plain_text("\n") plain_text("\n")
} }
fn red(str: &str) -> String {
use ReportText::*;
let mut buf = String::new();
buf.push_str("\u{001b}[31m");
buf.push_str(str);
buf.push_str("\u{001b}[0m");
buf
}
fn white(str: &str) -> String {
use ReportText::*;
let mut buf = String::new();
buf.push_str("\u{001b}[31m");
buf.push_str(str);
buf.push_str(reset);
buf
}
const reset: &str = "\u{001b}[0m";
impl ReportText { impl ReportText {
/// Render to CI console output, where no colors are available. /// Render to CI console output, where no colors are available.
pub fn render_ci( pub fn render_ci(