summaryrefslogtreecommitdiffstats
path: root/src/draw.rs
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2020-04-15 16:40:34 -0400
committerDan Davison <dandavison7@gmail.com>2020-04-15 16:40:34 -0400
commit55703edbd385d36e7b6eb978a047bae91fd19516 (patch)
treeefb5c901618776c23b4393d51c7c90945fd6450d /src/draw.rs
parentb9ed24d34fa7d69abcc8169441c5649463915013 (diff)
parent714f97398eab62a85dc60aa6b02648431567071f (diff)
Merge branch 'master' into width-calc-fix
Diffstat (limited to 'src/draw.rs')
-rw-r--r--src/draw.rs64
1 files changed, 43 insertions, 21 deletions
diff --git a/src/draw.rs b/src/draw.rs
index e89c9388..c6a6b84c 100644
--- a/src/draw.rs
+++ b/src/draw.rs
@@ -1,18 +1,21 @@
use std::io::Write;
-use ansi_term::Style;
use box_drawing;
use console::strip_ansi_codes;
+use syntect::highlighting::Color;
use unicode_width::UnicodeWidthStr;
+use crate::paint;
+
/// Write text to stream, surrounded by a box, leaving the cursor just
/// beyond the bottom right corner.
pub fn write_boxed(
writer: &mut dyn Write,
text: &str,
_line_width: usize, // ignored
- line_style: Style,
+ color: Color,
heavy: bool,
+ true_color: bool,
) -> std::io::Result<()> {
let up_left = if heavy {
box_drawing::heavy::UP_LEFT
@@ -20,8 +23,12 @@ pub fn write_boxed(
box_drawing::light::UP_LEFT
};
let box_width = UnicodeWidthStr::width(strip_ansi_codes(text).as_ref()) + 1;
- write_boxed_partial(writer, text, box_width, line_style, heavy)?;
- write!(writer, "{}", line_style.paint(up_left))?;
+ write_boxed_partial(writer, text, box_width, color, heavy, true_color)?;
+ write!(
+ writer,
+ "{}",
+ paint::paint_text_foreground(up_left, color, true_color)
+ )?;
Ok(())
}
@@ -31,11 +38,12 @@ pub fn write_boxed_with_line(
writer: &mut dyn Write,
text: &str,
line_width: usize,
- line_style: Style,
+ color: Color,
heavy: bool,
+ true_color: bool,
) -> std::io::Result<()> {
let box_width = UnicodeWidthStr::width(strip_ansi_codes(text).as_ref()) + 1;
- write_boxed_with_horizontal_whisker(writer, text, box_width, line_style, heavy)?;
+ write_boxed_with_horizontal_whisker(writer, text, box_width, color, heavy, true_color)?;
write_horizontal_line(
writer,
if line_width > box_width {
@@ -43,9 +51,11 @@ pub fn write_boxed_with_line(
} else {
0
},
- line_style,
+ color,
heavy,
+ true_color,
)?;
+ write!(writer, "\n")?;
Ok(())
}
@@ -53,11 +63,16 @@ pub fn write_underlined(
writer: &mut dyn Write,
text: &str,
line_width: usize,
- line_style: Style,
+ color: Color,
heavy: bool,
+ true_color: bool,
) -> std::io::Result<()> {
- writeln!(writer, "{}", line_style.paint(text))?;
- write_horizontal_line(writer, line_width - 1, line_style, heavy)?;
+ writeln!(
+ writer,
+ "{}",
+ paint::paint_text_foreground(text, color, true_color)
+ )?;
+ write_horizontal_line(writer, line_width - 1, color, heavy, true_color)?;
write!(writer, "\n")?;
Ok(())
}
@@ -65,8 +80,9 @@ pub fn write_underlined(
fn write_horizontal_line(
writer: &mut dyn Write,
line_width: usize,
- line_style: Style,
+ color: Color,
heavy: bool,
+ true_color: bool,
) -> std::io::Result<()> {
let horizontal = if heavy {
box_drawing::heavy::HORIZONTAL
@@ -76,7 +92,7 @@ fn write_horizontal_line(
write!(
writer,
"{}",
- line_style.paint(horizontal.repeat(line_width),)
+ paint::paint_text_foreground(&horizontal.repeat(line_width), color, true_color)
)
}
@@ -84,16 +100,21 @@ pub fn write_boxed_with_horizontal_whisker(
writer: &mut dyn Write,
text: &str,
box_width: usize,
- line_style: Style,
+ color: Color,
heavy: bool,
+ true_color: bool,
) -> std::io::Result<()> {
let up_horizontal = if heavy {
box_drawing::heavy::UP_HORIZONTAL
} else {
box_drawing::light::UP_HORIZONTAL
};
- write_boxed_partial(writer, text, box_width, line_style, heavy)?;
- write!(writer, "{}", line_style.paint(up_horizontal))?;
+ write_boxed_partial(writer, text, box_width, color, heavy, true_color)?;
+ write!(
+ writer,
+ "{}",
+ paint::paint_text_foreground(up_horizontal, color, true_color)
+ )?;
Ok(())
}
@@ -101,8 +122,9 @@ fn write_boxed_partial(
writer: &mut dyn Write,
text: &str,
box_width: usize,
- line_style: Style,
+ color: Color,
heavy: bool,
+ true_color: bool,
) -> std::io::Result<()> {
let horizontal = if heavy {
box_drawing::heavy::HORIZONTAL
@@ -124,10 +146,10 @@ fn write_boxed_partial(
write!(
writer,
"{}{}\n{} {}\n{}",
- line_style.paint(&horizontal_edge),
- line_style.paint(down_left),
- line_style.paint(text),
- line_style.paint(vertical),
- line_style.paint(&horizontal_edge),
+ paint::paint_text_foreground(&horizontal_edge, color, true_color),
+ paint::paint_text_foreground(down_left, color, true_color),
+ paint::paint_text_foreground(text, color, true_color),
+ paint::paint_text_foreground(vertical, color, true_color),
+ paint::paint_text_foreground(&horizontal_edge, color, true_color),
)
}