mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-12 14:46:41 +01:00
wip: refactor pt.11, 154 errors
This commit is contained in:
parent
355b34c738
commit
47c9cd2fe8
3 changed files with 107 additions and 54 deletions
|
|
@ -2,6 +2,7 @@ use crate::*;
|
|||
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub enum PhrasePoolViewCommand {
|
||||
Select(usize),
|
||||
Edit(PhrasePoolCommand),
|
||||
Rename(PhraseRenameCommand),
|
||||
Length(PhraseLengthCommand),
|
||||
|
|
@ -20,10 +21,10 @@ impl InputToCommand<Tui, PhrasePoolView<Tui>> for PhrasePoolViewCommand {
|
|||
use PhraseRenameCommand as Rename;
|
||||
use PhraseLengthCommand as Length;
|
||||
match input.event() {
|
||||
key!(KeyCode::Up) => Some(Cmd::Edit(Edit::Select(0))),
|
||||
key!(KeyCode::Down) => Some(Cmd::Edit(Edit::Select(0))),
|
||||
key!(KeyCode::Char(',')) => Some(Cmd::Edit(Edit::Swap(0))),
|
||||
key!(KeyCode::Char('.')) => Some(Cmd::Edit(Edit::Swap(0))),
|
||||
key!(KeyCode::Up) => Some(Cmd::Select(0)),
|
||||
key!(KeyCode::Down) => Some(Cmd::Select(0)),
|
||||
key!(KeyCode::Char(',')) => Some(Cmd::Edit(Edit::Swap(0, 0))),
|
||||
key!(KeyCode::Char('.')) => Some(Cmd::Edit(Edit::Swap(0, 0))),
|
||||
key!(KeyCode::Delete) => Some(Cmd::Edit(Edit::Delete(0))),
|
||||
key!(KeyCode::Char('a')) => Some(Cmd::Edit(Edit::Add(0))),
|
||||
key!(KeyCode::Char('i')) => Some(Cmd::Edit(Edit::Add(0))),
|
||||
|
|
@ -45,23 +46,39 @@ impl InputToCommand<Tui, PhrasePoolView<Tui>> for PhrasePoolViewCommand {
|
|||
}
|
||||
|
||||
impl<E: Engine> Command<PhrasePoolView<E>> for PhrasePoolViewCommand {
|
||||
fn execute (self, state: &mut PhrasePoolView<E>) -> Perhaps<Self> {
|
||||
use PhrasePoolViewCommand::*;
|
||||
fn execute (self, view: &mut PhrasePoolView<E>) -> Perhaps<Self> {
|
||||
use PhraseRenameCommand as Rename;
|
||||
use PhraseLengthCommand as Length;
|
||||
match self {
|
||||
Rename(Rename::Begin) => { state.begin_rename() },
|
||||
Length(Length::Begin) => { state.begin_length() },
|
||||
Prev => { state.select_prev() },
|
||||
Next => { state.select_next() },
|
||||
Delete => { state.delete_selected() },
|
||||
Append => { state.append_new(None, None) },
|
||||
Insert => { state.insert_new(None, None) },
|
||||
Duplicate => { state.insert_dup() },
|
||||
RandomColor => { state.randomize_color() },
|
||||
MoveUp => { state.move_up() },
|
||||
MoveDown => { state.move_down() },
|
||||
_ => unreachable!(),
|
||||
Self::Select(phrase) => {
|
||||
view.phrase = phrase
|
||||
},
|
||||
Self::Edit(command) => {
|
||||
return Ok(command.execute(&mut view.state)?.map(Self::Edit))
|
||||
}
|
||||
Self::Rename(command) => match command {
|
||||
Rename::Begin => {
|
||||
view.mode = Some(PhrasePoolMode::Rename(
|
||||
view.phrase,
|
||||
view.state.phrases[view.phrase].read().unwrap().name.clone()
|
||||
))
|
||||
},
|
||||
_ => {
|
||||
return Ok(command.execute(view)?.map(Self::Rename))
|
||||
}
|
||||
},
|
||||
Self::Length(command) => match command {
|
||||
Length::Begin => {
|
||||
view.mode = Some(PhrasePoolMode::Length(
|
||||
view.phrase,
|
||||
view.state.phrases[view.phrase].read().unwrap().length,
|
||||
PhraseLengthFocus::Bar
|
||||
))
|
||||
},
|
||||
_ => {
|
||||
return Ok(command.execute(view)?.map(Self::Length))
|
||||
}
|
||||
},
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue