mirror of
https://codeberg.org/unspeaker/perch.git
synced 2025-12-06 09:36:42 +01:00
fix all warns, remove moku, bind edit keys
This commit is contained in:
parent
41c5686d67
commit
2903d58b2d
6 changed files with 39 additions and 81 deletions
35
src/view.rs
35
src/view.rs
|
|
@ -1,7 +1,6 @@
|
|||
use crate::*;
|
||||
use tek_tui::ratatui::{style::{Color, Style}, prelude::Stylize};
|
||||
use pad::PadStr;
|
||||
use std::fmt::Display;
|
||||
|
||||
pub struct Column<T> {
|
||||
title: Arc<str>,
|
||||
|
|
@ -37,7 +36,7 @@ impl Default for Columns<Entry> {
|
|||
impl<T> Columns<T> {
|
||||
pub fn header (&self) -> Arc<str> {
|
||||
let mut output = String::new();
|
||||
for Column { width, value, title } in self.0.iter() {
|
||||
for Column { width, title, .. } in self.0.iter() {
|
||||
let cell = title.pad_to_width(*width);
|
||||
output = format!("{output}{cell}│");
|
||||
}
|
||||
|
|
@ -51,6 +50,18 @@ impl<T> Columns<T> {
|
|||
}
|
||||
output.into()
|
||||
}
|
||||
pub fn xw (&self, column: usize) -> (u16, u16) {
|
||||
let mut x: u16 = 0;
|
||||
for (index, Column { width, .. }) in self.0.iter().enumerate() {
|
||||
let w = *width as u16 + 1;
|
||||
if index == column {
|
||||
return (x.saturating_sub(1), w + 1)
|
||||
} else {
|
||||
x += w;
|
||||
}
|
||||
}
|
||||
(0, 0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Content<TuiOut> for Taggart {
|
||||
|
|
@ -69,28 +80,22 @@ impl<'a> Content<TuiOut> for TreeTable<'a> {
|
|||
fn render (&self, to: &mut TuiOut) {
|
||||
let area = to.area();
|
||||
let Taggart { offset, paths, cursor, column, .. } = self.0;
|
||||
let mut x = 0;
|
||||
for (index, Column { width, .. }) in self.0.columns.0.iter().enumerate() {
|
||||
let w = *width as u16 + 1;
|
||||
if index == *column {
|
||||
to.fill_bg([area.x() + x, area.y(), w, area.h()], Color::Rgb(0, 0, 0));
|
||||
break
|
||||
} else {
|
||||
x += w;
|
||||
}
|
||||
}
|
||||
let (x, w) = self.0.columns.xw(*column);
|
||||
to.fill_bg([area.x() + x, area.y(), w, area.h()], Color::Rgb(0, 0, 0));
|
||||
for (i, y) in area.iter_y().enumerate() {
|
||||
let i_offset = i + offset;
|
||||
let selected = *cursor == i_offset;
|
||||
if let Some(entry) = paths.get(i_offset) {
|
||||
for (index, fragment) in entry.path.iter().enumerate() {
|
||||
for (index, _fragment) in entry.path.iter().enumerate() {
|
||||
if index == entry.depth - 1 {
|
||||
let cursor = if selected { ">" } else { " " };
|
||||
let label = self.0.columns.row(&entry);
|
||||
let _cursor = if selected { ">" } else { " " };
|
||||
let label = self.0.columns.row(&entry);
|
||||
to.blit(&label, area.x(), y, entry.style());
|
||||
if selected {
|
||||
let fill = [area.x(), y, area.w(), 1];
|
||||
to.fill_fg(fill, Color::Rgb(0, 0, 0));
|
||||
to.fill_bg(fill, Color::Rgb(192, 128, 0));
|
||||
let fill = [area.x() + x as u16, y, w, 1];
|
||||
to.fill_bg(fill, Color::Rgb(224, 192, 0));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue