mirror of
https://codeberg.org/unspeaker/perch.git
synced 2025-12-08 18:46:43 +01:00
only enter edit mode for columns with setters
This commit is contained in:
parent
138bba99cb
commit
7c4451e46f
3 changed files with 33 additions and 30 deletions
33
src/keys.rs
33
src/keys.rs
|
|
@ -65,3 +65,36 @@ impl Handle<TuiIn> for Taggart {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Taggart {
|
||||||
|
pub fn edit_begin (&mut self) {
|
||||||
|
if let Some(column) = self.columns.0.get(self.column)
|
||||||
|
&& column.setter.is_some()
|
||||||
|
{
|
||||||
|
let value = (column.getter)(&self.paths[self.cursor]);
|
||||||
|
let value = format!("{}", value.unwrap_or_default());
|
||||||
|
self.editing = Some((value.len(), value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn edit_cancel (&mut self) {
|
||||||
|
self.editing = None;
|
||||||
|
}
|
||||||
|
pub fn edit_confirm (&mut self) {
|
||||||
|
self.editing = None;
|
||||||
|
}
|
||||||
|
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}")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn edit_delete (&mut self) {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
26
src/model.rs
26
src/model.rs
|
|
@ -74,32 +74,6 @@ impl Taggart {
|
||||||
paths,
|
paths,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
pub fn edit_begin (&mut self) {
|
|
||||||
let value = (self.columns.0[self.column].getter)(&self.paths[self.cursor]);
|
|
||||||
let value = format!("{}", value.unwrap_or_default());
|
|
||||||
self.editing = Some((value.len(), value));
|
|
||||||
}
|
|
||||||
pub fn edit_cancel (&mut self) {
|
|
||||||
self.editing = None;
|
|
||||||
}
|
|
||||||
pub fn edit_confirm (&mut self) {
|
|
||||||
self.editing = None;
|
|
||||||
}
|
|
||||||
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}")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn edit_delete (&mut self) {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Entry {
|
impl Entry {
|
||||||
|
|
|
||||||
|
|
@ -53,10 +53,6 @@ impl<'a> TreeTable<'a> {
|
||||||
fn cell_cursor (&self, to: &mut TuiOut, xa: u16, x0: u16, x: u16, y: u16, w: u16) {
|
fn cell_cursor (&self, to: &mut TuiOut, xa: u16, x0: u16, x: u16, y: u16, w: u16) {
|
||||||
let fill = [xa + x0, y, w, 1];
|
let fill = [xa + x0, y, w, 1];
|
||||||
to.fill_bg(fill, Self::BG_CELL);
|
to.fill_bg(fill, Self::BG_CELL);
|
||||||
//if let Some((_index, value)) = &self.0.editing {
|
|
||||||
//let x = xa + if x > 0 { x + 1 } else { x } as u16;
|
|
||||||
//to.blit(&value, x, y, None)
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
fn row_data (&self, to: &mut TuiOut, entry: &Entry, row: usize, x: &mut u16) {
|
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() {
|
for (column_index, Column { width, getter, .. }) in self.0.columns.0.iter().enumerate() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue