wip: p.57, e=81

This commit is contained in:
🪞👃🪞 2024-11-19 00:13:12 +01:00
parent 0964ad3be4
commit 0c94c2af8f
11 changed files with 672 additions and 667 deletions

View file

@ -251,19 +251,42 @@ where
impl<T: PhrasesControl> InputToCommand<Tui, T> for PhrasesCommand {
fn input_to_command (state: &T, input: &TuiInput) -> Option<Self> {
use PhrasePoolCommand as Edit;
use PhrasePoolCommand as Phrase;
use PhraseRenameCommand as Rename;
use PhraseLengthCommand as Length;
let index = state.phrase();
let count = state.phrases().len();
match input.event() {
key!(KeyCode::Up) => Some(Self::Select(0)),
key!(KeyCode::Down) => Some(Self::Select(0)),
key!(KeyCode::Char(',')) => Some(Self::Edit(Edit::Swap(0, 0))),
key!(KeyCode::Char('.')) => Some(Self::Edit(Edit::Swap(0, 0))),
key!(KeyCode::Delete) => Some(Self::Edit(Edit::Delete(0))),
key!(KeyCode::Char('a')) => Some(Self::Edit(Edit::Add(0))),
key!(KeyCode::Char('i')) => Some(Self::Edit(Edit::Add(0))),
key!(KeyCode::Char('d')) => Some(Self::Edit(Edit::Duplicate(0))),
key!(KeyCode::Char('c')) => Some(Self::Edit(Edit::RandomColor(0))),
key!(KeyCode::Char(',')) => {
if index > 1 {
Some(Self::Phrase(Phrase::Swap(index - 1, index)))
//index -= 1;
} else {
None
}
},
key!(KeyCode::Char('.')) => {
if index < count.saturating_sub(1) {
Some(Self::Phrase(Phrase::Swap(index + 1, index)))
//index += 1;
} else {
None
}
},
key!(KeyCode::Delete) => {
if index > 0 {
Some(Self::Delete(index))
//index = index.min(count.saturating_sub(1));
} else {
None
}
},
key!(KeyCode::Char('a')) => Some(Self::Phrase(Phrase::Add(count))),
key!(KeyCode::Char('i')) => Some(Self::Phrase(Phrase::Add(index + 1))),
key!(KeyCode::Char('d')) => Some(Self::Phrase(Phrase::Duplicate(index))),
key!(KeyCode::Char('c')) => Some(Self::Phrase(Phrase::RandomColor(index))),
key!(KeyCode::Char('n')) => Some(Self::Rename(Rename::Begin)),
key!(KeyCode::Char('t')) => Some(Self::Length(Length::Begin)),
_ => match state.phrases_mode() {