mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 15:21:12 +00:00
Very start of render color terminal
This commit is contained in:
parent
009e1fa176
commit
f8dd2fb9a1
1 changed files with 59 additions and 0 deletions
|
@ -11,6 +11,38 @@ pub struct Report {
|
|||
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 {
|
||||
let mut texts = Vec::new();
|
||||
|
||||
|
@ -77,6 +109,33 @@ fn newline() -> ReportText {
|
|||
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 {
|
||||
/// Render to CI console output, where no colors are available.
|
||||
pub fn render_ci(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue