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
f8dd2fb9a1
commit
9cdd7988fc
2 changed files with 60 additions and 23 deletions
|
@ -21,24 +21,18 @@ pub enum Color {
|
|||
Red,
|
||||
}
|
||||
|
||||
|
||||
pub const default_palette: Palette = Palette {
|
||||
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)
|
||||
}
|
||||
Red => red(str),
|
||||
White => white(str),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -110,8 +104,6 @@ fn newline() -> ReportText {
|
|||
}
|
||||
|
||||
fn red(str: &str) -> String {
|
||||
use ReportText::*;
|
||||
|
||||
let mut buf = String::new();
|
||||
|
||||
buf.push_str("\u{001b}[31m");
|
||||
|
@ -122,19 +114,16 @@ fn red(str: &str) -> String {
|
|||
}
|
||||
|
||||
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.push_str(RESET);
|
||||
|
||||
buf
|
||||
}
|
||||
|
||||
|
||||
const reset: &str = "\u{001b}[0m";
|
||||
const RESET: &str = "\u{001b}[0m";
|
||||
|
||||
impl ReportText {
|
||||
/// Render to CI console output, where no colors are available.
|
||||
|
@ -203,13 +192,21 @@ impl ReportText {
|
|||
/// Render to a color terminal using ANSI escape sequences
|
||||
pub fn render_color_terminal(
|
||||
&self,
|
||||
_buf: &mut String,
|
||||
buf: &mut String,
|
||||
_subs: &mut Subs,
|
||||
_home: ModuleId,
|
||||
_src_lines: &[&str],
|
||||
_interns: &Interns,
|
||||
palette: Palette,
|
||||
) {
|
||||
// TODO do the same stuff as render_ci, but with colors via ANSI terminal escape codes!
|
||||
// Examples of how to do this are in the source code of https://github.com/rtfeldman/console-print
|
||||
use ReportText::*;
|
||||
|
||||
match self {
|
||||
Plain(string) => {
|
||||
buf.push_str(&palette.primary.render(string));
|
||||
}
|
||||
|
||||
_ => panic!("TODO implement more ReportTexts in render color terminal"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue