Apply rustfmt to the crate
This commit is contained in:
+71
-10
@@ -16,7 +16,12 @@ pub(crate) struct Column {
|
||||
}
|
||||
|
||||
pub(crate) const fn col(title: &'static str, width: i32, right: bool, clip_left: bool) -> Column {
|
||||
Column { title, width, right, clip_left }
|
||||
Column {
|
||||
title,
|
||||
width,
|
||||
right,
|
||||
clip_left,
|
||||
}
|
||||
}
|
||||
|
||||
/// One rendered row: cell strings plus optional per-cell styles.
|
||||
@@ -69,7 +74,15 @@ impl Table {
|
||||
self.cursor.max(0) as usize
|
||||
}
|
||||
|
||||
pub fn paint(&mut self, m: &mut Model, cv: &mut Canvas, r: Rect, cols: &[Column], rows: &[TableRow], title: &str) {
|
||||
pub fn paint(
|
||||
&mut self,
|
||||
m: &mut Model,
|
||||
cv: &mut Canvas,
|
||||
r: Rect,
|
||||
cols: &[Column],
|
||||
rows: &[TableRow],
|
||||
title: &str,
|
||||
) {
|
||||
let t = m.theme.clone();
|
||||
cv.fill(r, " ", t.base());
|
||||
if r.h < 3 {
|
||||
@@ -77,7 +90,13 @@ impl Table {
|
||||
}
|
||||
let mut y = r.y;
|
||||
if !title.is_empty() {
|
||||
cv.text(r.x + 1, y, title, r.w - 2, Style::new(t.accent, t.bg).with(BOLD));
|
||||
cv.text(
|
||||
r.x + 1,
|
||||
y,
|
||||
title,
|
||||
r.w - 2,
|
||||
Style::new(t.accent, t.bg).with(BOLD),
|
||||
);
|
||||
y += 1;
|
||||
}
|
||||
// Resolve flexible width.
|
||||
@@ -88,7 +107,11 @@ impl Table {
|
||||
let hdr = Style::new(t.muted, t.bg).with(BOLD);
|
||||
for c in cols {
|
||||
let w = width(c);
|
||||
let s = if c.right { pad_left(c.title, w) } else { c.title.to_string() };
|
||||
let s = if c.right {
|
||||
pad_left(c.title, w)
|
||||
} else {
|
||||
c.title.to_string()
|
||||
};
|
||||
cv.text(x, y, &s, w, hdr);
|
||||
x += w + 1;
|
||||
}
|
||||
@@ -114,7 +137,16 @@ impl Table {
|
||||
let mut base = t.base();
|
||||
if sel {
|
||||
base = Style::new(t.text_on(t.sel), t.sel).with(BOLD | m.mono_rev());
|
||||
cv.fill(Rect { x: r.x, y, w: r.w, h: 1 }, " ", base);
|
||||
cv.fill(
|
||||
Rect {
|
||||
x: r.x,
|
||||
y,
|
||||
w: r.w,
|
||||
h: 1,
|
||||
},
|
||||
" ",
|
||||
base,
|
||||
);
|
||||
}
|
||||
let mut x = r.x + 1;
|
||||
for (ci, c) in cols.iter().enumerate() {
|
||||
@@ -135,7 +167,15 @@ impl Table {
|
||||
}
|
||||
x += w + 1;
|
||||
}
|
||||
m.hits.push(Hit { r: Rect { x: r.x, y, w: r.w, h: 1 }, act: HitAct::Row(i as usize) });
|
||||
m.hits.push(Hit {
|
||||
r: Rect {
|
||||
x: r.x,
|
||||
y,
|
||||
w: r.w,
|
||||
h: 1,
|
||||
},
|
||||
act: HitAct::Row(i as usize),
|
||||
});
|
||||
y += 1;
|
||||
i += 1;
|
||||
}
|
||||
@@ -143,7 +183,11 @@ impl Table {
|
||||
cv.text_centered(r.x, r.y + r.h / 2, r.w, "Nothing to show", t.muted());
|
||||
}
|
||||
if n > self.height && self.height > 0 {
|
||||
let pos = format!("{}/{}", textutil::count(self.cursor as i64 + 1), textutil::count(n as i64));
|
||||
let pos = format!(
|
||||
"{}/{}",
|
||||
textutil::count(self.cursor as i64 + 1),
|
||||
textutil::count(n as i64)
|
||||
);
|
||||
cv.text_right(r.x, r.y, r.w - 1, &pos, t.muted());
|
||||
}
|
||||
}
|
||||
@@ -152,10 +196,23 @@ impl Table {
|
||||
impl Model {
|
||||
/// Draws a proportional bar with eighth-block precision.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn paint_bar(&self, cv: &mut Canvas, x: i32, y: i32, w: i32, frac: f64, col: Color, sel: bool) {
|
||||
pub fn paint_bar(
|
||||
&self,
|
||||
cv: &mut Canvas,
|
||||
x: i32,
|
||||
y: i32,
|
||||
w: i32,
|
||||
frac: f64,
|
||||
col: Color,
|
||||
sel: bool,
|
||||
) {
|
||||
let t = &self.theme;
|
||||
let col = if col.is_default() { t.accent } else { col };
|
||||
let bg = if sel { t.sel.mix(rgb(0, 0, 0), 0.25) } else { t.bg.mix(t.fg, 0.08) };
|
||||
let bg = if sel {
|
||||
t.sel.mix(rgb(0, 0, 0), 0.25)
|
||||
} else {
|
||||
t.bg.mix(t.fg, 0.08)
|
||||
};
|
||||
let mut eighths = (frac * (w * 8) as f64 + 0.5) as i64;
|
||||
const PARTS: [&str; 8] = ["", "▏", "▎", "▍", "▌", "▋", "▊", "▉"];
|
||||
for i in 0..w {
|
||||
@@ -170,7 +227,11 @@ impl Model {
|
||||
ch = if eighths >= 4 { "#" } else { " " };
|
||||
}
|
||||
eighths -= 8;
|
||||
let st = if t.mono { Style::default() } else { Style::new(col, bg) };
|
||||
let st = if t.mono {
|
||||
Style::default()
|
||||
} else {
|
||||
Style::new(col, bg)
|
||||
};
|
||||
cv.text(x + i, y, ch, 1, st);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user