use par_term_config::{Cell, color_u8x4_rgb_to_f32};
const POWERLINE_GLYPHS: &[&str] = &[
"\u{E0B0}", "\u{E0B1}", "\u{E0B2}", "\u{E0B3}", "\u{E0B4}", "\u{E0B5}", "\u{E0B6}", "\u{E0B7}",
];
const POWERLINE_RIGHT_POINTING: &[&str] = &["\u{E0B0}", "\u{E0B1}", "\u{E0B4}", "\u{E0B5}"];
pub(super) fn is_default_bg(bg: [u8; 4], background_color: [f32; 4]) -> bool {
let f = color_u8x4_rgb_to_f32(bg);
(f[0] - background_color[0]).abs() < 0.001
&& (f[1] - background_color[1]).abs() < 0.001
&& (f[2] - background_color[2]).abs() < 0.001
}
pub(super) struct PowerlineFringeParams<'a> {
pub row_cells: &'a [Cell],
pub start_col: usize,
pub col: usize,
pub x0: f32,
pub x1: f32,
pub skip_solid_background: bool,
pub is_default_bg: bool,
pub background_color: [f32; 4],
}
pub(super) fn extend_powerline_fringes(p: PowerlineFringeParams<'_>) -> (f32, f32) {
let PowerlineFringeParams {
row_cells,
start_col,
col,
x0,
x1,
skip_solid_background,
is_default_bg: run_is_default_bg,
background_color,
} = p;
let is_def = |bg: [u8; 4]| self::is_default_bg(bg, background_color);
let is_powerline = |g: &str| POWERLINE_GLYPHS.contains(&g);
let x1 = if col < row_cells.len()
&& is_powerline(row_cells[col].grapheme.as_str())
&& is_def(row_cells[col].bg_color)
{
x1 + 1.0
} else {
x1
};
let x0 = if start_col > 0
&& is_powerline(row_cells[start_col - 1].grapheme.as_str())
&& is_def(row_cells[start_col - 1].bg_color)
{
x0 - 1.0
} else {
x0
};
let x0 = if skip_solid_background
&& run_is_default_bg
&& POWERLINE_RIGHT_POINTING.contains(&row_cells[start_col].grapheme.as_str())
&& start_col > 0
&& !is_def(row_cells[start_col - 1].bg_color)
{
x0 + 1.0
} else {
x0
};
(x0, x1)
}