mirror of
https://codeberg.org/unspeaker/perch.git
synced 2025-12-06 09:36:42 +01:00
fix off-by-1 column widths; add edit cursor
This commit is contained in:
parent
59918491f6
commit
4bfdd28638
7 changed files with 57 additions and 59 deletions
|
|
@ -92,14 +92,14 @@ impl Taggart {
|
|||
}
|
||||
pub fn edit_insert (&mut self, c: char) {
|
||||
if let Some((edit_index, value)) = &mut self.editing {
|
||||
self.editing = Some((*edit_index, format!("{value}{c}")));
|
||||
self.editing = Some((*edit_index + 1, format!("{value}{c}")));
|
||||
}
|
||||
}
|
||||
pub fn edit_backspace (&mut self) {
|
||||
if let Some((edit_index, value)) = &mut self.editing {
|
||||
let mut chars = value.chars();
|
||||
chars.next_back();
|
||||
self.editing = Some((*edit_index, chars.as_str().into()));
|
||||
self.editing = Some((edit_index.saturating_sub(1), chars.as_str().into()));
|
||||
}
|
||||
}
|
||||
pub fn edit_delete (&mut self) {
|
||||
|
|
|
|||
|
|
@ -34,13 +34,13 @@ impl Default for Columns<Entry, fn(&Entry)->Option<Arc<str>>, fn(&mut [Entry], u
|
|||
fn default () -> Self {
|
||||
Self(vec![
|
||||
|
||||
Column::new(&"HASH", 16, |entry: &Entry|entry.hash()),
|
||||
Column::new(&"HASH", 8, |entry: &Entry|entry.hash()),
|
||||
|
||||
Column::new(&"SIZE", 8, |entry: &Entry|entry.size()),
|
||||
Column::new(&"SIZE", 8, |entry: &Entry|entry.size()),
|
||||
|
||||
Column::new(&"FILE", 80, |entry: &Entry|entry.name()),
|
||||
Column::new(&"FILE", 80, |entry: &Entry|entry.name()),
|
||||
|
||||
Column::new(&"ARTIST", 30, |entry: &Entry|entry.artist())
|
||||
Column::new(&"ARTIST", 30, |entry: &Entry|entry.artist())
|
||||
.setter(|entries: &mut [Entry], index: usize, value: &str|{
|
||||
if let Some(entries) = paths_under(entries, index) {
|
||||
for entry in entries.iter() {
|
||||
|
|
|
|||
11
src/view.rs
11
src/view.rs
|
|
@ -21,12 +21,12 @@ impl Content<TuiOut> for Taggart {
|
|||
Fill::x(Align::w(Tui::bold(true, if self.editing.is_some() {
|
||||
Bsp::e(
|
||||
Tui::bg(Self::BG_EDIT, Tui::fg(Self::FG_EDIT, " EDIT ")),
|
||||
" Esc to cancel, Enter to save"
|
||||
" Esc: cancel, Enter: set value"
|
||||
)
|
||||
} else {
|
||||
Bsp::e(
|
||||
Tui::bg(Self::BG_BROWSE, Tui::fg(Self::FG_BROWSE, " BROWSE ")),
|
||||
" Q to exit, Arrows to select, Enter to edit"
|
||||
" Q: exit, Arrows: select, Enter: edit"
|
||||
)
|
||||
}))),
|
||||
Fill::x(Align::e(size)),
|
||||
|
|
@ -58,11 +58,4 @@ impl Entry {
|
|||
Self::ICON_UNKNOWN
|
||||
}
|
||||
}
|
||||
//fn style (&self) -> Option<Style> {
|
||||
//if self.is_dir() {
|
||||
//None
|
||||
//} else {
|
||||
//Some(Style::default().bold())
|
||||
//}
|
||||
//}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,19 +55,26 @@ impl<'a> TreeTable<'a> {
|
|||
to.fill_bg(fill, Self::BG_CELL);
|
||||
}
|
||||
fn row_data (&self, to: &mut TuiOut, entry: &Entry, row: usize, x: &mut u16) {
|
||||
for (column_index, Column { width, getter, .. }) in self.0.columns.0.iter().enumerate() {
|
||||
let y = to.area().y();
|
||||
for (column_index, Column {
|
||||
width,
|
||||
getter,
|
||||
..
|
||||
}) in self.0.columns.0.iter().enumerate() {
|
||||
to.area[0] = *x;
|
||||
if let Some((_edit_index, value)) = self.0.editing.as_ref()
|
||||
if let Some((edit_index, value)) = self.0.editing.as_ref()
|
||||
&& self.0.column == column_index
|
||||
&& self.0.cursor == row
|
||||
{
|
||||
to.fill_bg([*x, to.area().y(), *width as u16, 1], Self::BG_EDIT);
|
||||
to.fill_fg([*x, to.area().y(), *width as u16, 1], Self::FG_EDIT);
|
||||
to.fill_bg([*x, y, *width as u16, 1], Self::BG_EDIT);
|
||||
to.fill_fg([*x, y, *width as u16, 1], Self::FG_EDIT);
|
||||
to.fill_reversed([*x + *edit_index as u16, y, 1, 1], true);
|
||||
Content::render(&TrimStringRef(*width as u16, &value), to);
|
||||
} else if let Some(value) = getter(entry) {
|
||||
Content::render(&TrimStringRef(*width as u16, &value), to);
|
||||
}
|
||||
*x += *width as u16 + 1;
|
||||
to.blit(&"│", *x - 1, y, None);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -86,11 +93,7 @@ impl<T, G, S> Columns<T, G, S> {
|
|||
for (index, Column { width, .. }) in self.0.iter().enumerate() {
|
||||
let w = *width as u16 + 1;
|
||||
if index == column {
|
||||
if x > 0 {
|
||||
return (x - 1, w + 1)
|
||||
} else {
|
||||
return (x, w)
|
||||
}
|
||||
return (x, w)
|
||||
} else {
|
||||
x += w;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue