mirror of
https://codeberg.org/unspeaker/perch.git
synced 2025-12-06 09:36:42 +01:00
stub help modal; cleanup
This commit is contained in:
parent
b157a87647
commit
4619d0ea76
9 changed files with 78 additions and 68 deletions
18
src/keys.rs
18
src/keys.rs
|
|
@ -20,9 +20,10 @@ macro_rules! press {
|
|||
};
|
||||
}
|
||||
|
||||
mod edit; pub use self::edit::*;
|
||||
mod save; pub use self::save::*;
|
||||
mod quit; pub use self::quit::*;
|
||||
mod edit;
|
||||
mod save;
|
||||
mod quit;
|
||||
mod help;
|
||||
|
||||
impl Handle<TuiIn> for Taggart {
|
||||
fn handle (&mut self, input: &TuiIn) -> Perhaps<bool> {
|
||||
|
|
@ -30,10 +31,12 @@ impl Handle<TuiIn> for Taggart {
|
|||
let max = self.offset + self.display.h().saturating_sub(1);
|
||||
let event = &*input.event();
|
||||
match &self.mode {
|
||||
Some(Mode::Edit { .. }) => self.mode_edit(event),
|
||||
Some(Mode::Save { value }) => self.mode_save(event, *value),
|
||||
Some(Mode::Quit { value }) => self.mode_quit(input, event, *value),
|
||||
Some(Mode::Edit { .. }) => self.handle_edit(event),
|
||||
Some(Mode::Help { page }) => self.handle_help(event, *page),
|
||||
Some(Mode::Save { choice }) => self.handle_save(event, *choice),
|
||||
Some(Mode::Quit { choice }) => self.handle_quit(input, *choice),
|
||||
None => match event {
|
||||
press!(F(1)) => { self.help_begin() },
|
||||
press!(Char('q')) => { self.quit_begin(&input) },
|
||||
press!(Char('w')) => { self.save_begin() },
|
||||
press!(Enter) => { self.edit_begin() },
|
||||
|
|
@ -48,8 +51,7 @@ impl Handle<TuiIn> for Taggart {
|
|||
press!(Char('[')) => { self.columns.0[self.column].width =
|
||||
self.columns.0[self.column].width.saturating_sub(1).max(5); }
|
||||
_ => {}
|
||||
}
|
||||
_ => todo!("{:?}", self.mode)
|
||||
},
|
||||
}
|
||||
self.clamp(min, max);
|
||||
Ok(None)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use crate::*;
|
||||
|
||||
impl Taggart {
|
||||
pub fn mode_edit (&mut self, event: &Event) {
|
||||
pub fn handle_edit (&mut self, event: &Event) {
|
||||
match event {
|
||||
press!(Char(c)) => self.edit_insert(*c),
|
||||
press!(Shift-Char(c)) => self.edit_insert(c.to_uppercase().next().unwrap()),
|
||||
|
|
|
|||
13
src/keys/help.rs
Normal file
13
src/keys/help.rs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
use crate::*;
|
||||
|
||||
impl Taggart {
|
||||
pub fn handle_help (&mut self, event: &Event, _page: u8) {
|
||||
match event {
|
||||
press!(Esc) => { self.mode = None },
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
pub fn help_begin (&mut self) {
|
||||
self.mode = Some(Mode::Help { page: 0 })
|
||||
}
|
||||
}
|
||||
|
|
@ -1,23 +1,16 @@
|
|||
use crate::*;
|
||||
|
||||
impl Taggart {
|
||||
pub fn quit_begin (&mut self, input: &TuiIn) {
|
||||
if self.tasks.len() == 0 {
|
||||
input.done()
|
||||
} else {
|
||||
self.mode = Some(Mode::Quit { value: 1 })
|
||||
}
|
||||
}
|
||||
pub fn mode_quit (&mut self, input: &TuiIn, event: &Event, value: u8) {
|
||||
match event {
|
||||
pub fn handle_quit (&mut self, input: &TuiIn, choice: u8) {
|
||||
match &*input.event() {
|
||||
press!(Esc) => { self.mode = None },
|
||||
press!(Left) => { self.mode = Some(Mode::Quit {
|
||||
value: value.overflowing_sub(1).0.min(2)
|
||||
choice: choice.overflowing_sub(1).0.min(2)
|
||||
}) },
|
||||
press!(Right) => { self.mode = Some(Mode::Quit {
|
||||
value: (value + 1) % 3
|
||||
choice: (choice + 1) % 3
|
||||
}) },
|
||||
press!(Enter) => match value {
|
||||
press!(Enter) => match choice {
|
||||
0 => { input.done() },
|
||||
1 => { self.mode = None },
|
||||
2 => todo!(),
|
||||
|
|
@ -26,4 +19,11 @@ impl Taggart {
|
|||
_ => {}
|
||||
}
|
||||
}
|
||||
pub fn quit_begin (&mut self, input: &TuiIn) {
|
||||
if self.tasks.len() == 0 {
|
||||
input.done()
|
||||
} else {
|
||||
self.mode = Some(Mode::Quit { choice: 1 })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,16 @@
|
|||
use crate::*;
|
||||
|
||||
impl Taggart {
|
||||
pub fn save_begin (&mut self) {
|
||||
if self.tasks.len() > 0 {
|
||||
self.mode = Some(Mode::Save { value: 1 })
|
||||
}
|
||||
}
|
||||
pub fn mode_save (&mut self, event: &Event, value: u8) {
|
||||
pub fn handle_save (&mut self, event: &Event, choice: u8) {
|
||||
match event {
|
||||
press!(Esc) => { self.mode = None }
|
||||
press!(Left) => { self.mode = Some(Mode::Save {
|
||||
value: value.overflowing_sub(1).0.min(2)
|
||||
choice: choice.overflowing_sub(1).0.min(2)
|
||||
}) },
|
||||
press!(Right) => { self.mode = Some(Mode::Save {
|
||||
value: (value + 1) % 3
|
||||
choice: (choice + 1) % 3
|
||||
}) },
|
||||
press!(Enter) => match value {
|
||||
press!(Enter) => match choice {
|
||||
0 => { self.tasks = vec![]; self.mode = None; },
|
||||
1 => { self.mode = None },
|
||||
2 => todo!(),
|
||||
|
|
@ -24,4 +19,9 @@ impl Taggart {
|
|||
_ => {}
|
||||
}
|
||||
}
|
||||
pub fn save_begin (&mut self) {
|
||||
if self.tasks.len() > 0 {
|
||||
self.mode = Some(Mode::Save { choice: 1 })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
15
src/model.rs
15
src/model.rs
|
|
@ -20,17 +20,10 @@ pub struct Taggart {
|
|||
|
||||
#[derive(Debug)]
|
||||
pub enum Mode {
|
||||
Help,
|
||||
Edit {
|
||||
value: Arc<str>,
|
||||
index: usize,
|
||||
},
|
||||
Save {
|
||||
value: u8,
|
||||
},
|
||||
Quit {
|
||||
value: u8,
|
||||
},
|
||||
Help { page: u8 },
|
||||
Edit { value: Arc<str>, index: usize, },
|
||||
Save { choice: u8, },
|
||||
Quit { choice: u8, },
|
||||
}
|
||||
|
||||
impl Taggart {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
use crate::*;
|
||||
use std::fs::File;
|
||||
use std::io::{BufReader, Read};
|
||||
use std::borrow::Borrow;
|
||||
use byte_unit::{Byte, Unit::MB};
|
||||
use lofty::{
|
||||
probe::Probe,
|
||||
file::TaggedFileExt,
|
||||
config::{ParseOptions, ParsingMode},
|
||||
tag::{Accessor, Tag, TagItem, ItemKey, ItemValue, TagType}
|
||||
tag::{Accessor, Tag, TagItem, TagType}
|
||||
};
|
||||
|
||||
pub enum Metadata {
|
||||
|
|
@ -139,7 +138,7 @@ macro_rules! music_tag_field {
|
|||
}
|
||||
pub fn $set (&mut self, value: &impl AsRef<str>) -> Option<TagItem> {
|
||||
let value = value.as_ref().trim();
|
||||
if let &mut Metadata::Music { ref original_tag, ref mut modified_tag, .. } = self {
|
||||
if let &mut Metadata::Music { ref mut modified_tag, .. } = self {
|
||||
match (value.len(), &modified_tag) {
|
||||
(0, Some(new_tag)) => {
|
||||
if new_tag.read().unwrap().item_count() <= 1 {
|
||||
|
|
@ -184,7 +183,7 @@ macro_rules! music_tag_field {
|
|||
}
|
||||
pub fn $set (&mut self, value: &impl AsRef<str>) -> Option<TagItem> {
|
||||
let value = value.as_ref().trim();
|
||||
if let &mut Metadata::Music { ref original_tag, ref mut modified_tag, .. } = self
|
||||
if let &mut Metadata::Music { ref mut modified_tag, .. } = self
|
||||
&& let Ok(numeric_value) = value.parse::<u32>()
|
||||
{
|
||||
match (value.len(), &modified_tag) {
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ pub(crate) use tengri::tui::ratatui::style::{Color, Modifier};
|
|||
pub(crate) use pad::PadStr;
|
||||
|
||||
mod table; pub use self::table::*;
|
||||
mod dialog; pub use self::dialog::*;
|
||||
mod status; pub use self::status::*;
|
||||
mod dialog;
|
||||
mod status;
|
||||
|
||||
impl Content<TuiOut> for Taggart {
|
||||
fn content (&self) -> impl Render<TuiOut> {
|
||||
|
|
|
|||
|
|
@ -10,40 +10,43 @@ impl Taggart {
|
|||
let bg = |x|Bsp::a(x, Repeat(" "));
|
||||
pos(style(border(bg(content))))
|
||||
}
|
||||
fn dialog_help (&self) {
|
||||
fn dialog_help (&self, _page: u8) -> impl Content<TuiOut> {
|
||||
Self::dialog(Bsp::s(
|
||||
"Help",
|
||||
"TODO",
|
||||
))
|
||||
}
|
||||
fn dialog_save (&self, value: u8) {
|
||||
fn dialog_save (&self, choice: u8) -> impl Content<TuiOut> {
|
||||
let choices = [
|
||||
if value == 0 { "[ Clear changes ]" } else { " Clear changes " },
|
||||
if value == 1 { "[ Continue editing ]" } else { " Continue editing " },
|
||||
if value == 2 { "[ Write and continue ]" } else { " Write and continue " },
|
||||
if choice == 0 { "[ Clear changes ]" } else { " Clear changes " },
|
||||
if choice == 1 { "[ Continue editing ]" } else { " Continue editing " },
|
||||
if choice == 2 { "[ Write and continue ]" } else { " Write and continue " },
|
||||
];
|
||||
Self::dialog(Bsp::s(
|
||||
format!("Save {} change(s)?", self.tasks.len()),
|
||||
Bsp::s("", Bsp::e(choices[0], Bsp::e(choices[1], choices[2])))));
|
||||
Bsp::s("", Bsp::e(choices[0], Bsp::e(choices[1], choices[2])))))
|
||||
}
|
||||
fn dialog_quit (&self, value: u8) {
|
||||
fn dialog_quit (&self, choice: u8) -> impl Content<TuiOut> {
|
||||
let choices = [
|
||||
if value == 0 { "[ Exit without saving ]" } else { " Exit without saving " },
|
||||
if value == 1 { "[ Cancel ]" } else { " Cancel " },
|
||||
if value == 2 { "[ Write and exit ]" } else { " Write and exit " },
|
||||
if choice == 0 { "[ Exit without saving ]" } else { " Exit without saving " },
|
||||
if choice == 1 { "[ Cancel ]" } else { " Cancel " },
|
||||
if choice == 2 { "[ Write and exit ]" } else { " Write and exit " },
|
||||
];
|
||||
Self::dialog(Bsp::s(
|
||||
format!("Save {} change(s) before exiting?", self.tasks.len()),
|
||||
Bsp::s("", Bsp::e(choices[0], Bsp::e(choices[1], choices[2])))));
|
||||
Bsp::s("", Bsp::e(choices[0], Bsp::e(choices[1], choices[2])))))
|
||||
}
|
||||
pub fn render_dialog (&self, to: &mut TuiOut) {
|
||||
match self.mode {
|
||||
Some(Mode::Save { value }) => {
|
||||
to.tint_all(Color::Rgb(96,96,96), Color::Rgb(48,48,48), Modifier::DIM);
|
||||
Content::render(&self.dialog_save(value), to)
|
||||
},
|
||||
Some(Mode::Quit { value }) => {
|
||||
to.tint_all(Color::Rgb(96,96,96), Color::Rgb(48,48,48), Modifier::DIM);
|
||||
Content::render(&self.dialog_quit(value), to)
|
||||
},
|
||||
Some(Mode::Help { .. }) => {
|
||||
},
|
||||
Some(Mode::Edit { .. }) => {},
|
||||
Some(_) => to.tint_all(Color::Rgb(96,96,96), Color::Rgb(48,48,48), Modifier::DIM),
|
||||
_ => {}
|
||||
}
|
||||
match self.mode {
|
||||
Some(Mode::Edit { .. }) => {},
|
||||
Some(Mode::Save { choice }) => Content::render(&self.dialog_save(choice), to),
|
||||
Some(Mode::Quit { choice }) => Content::render(&self.dialog_quit(choice), to),
|
||||
Some(Mode::Help { page }) => Content::render(&self.dialog_help(page), to),
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue