diff options
author | qkzk <qu3nt1n@gmail.com> | 2022-12-17 21:25:58 +0100 |
---|---|---|
committer | qkzk <qu3nt1n@gmail.com> | 2022-12-17 21:25:58 +0100 |
commit | ca2ff278511585ec5e2b7713773f80078ca48e7c (patch) | |
tree | e55295025799ebc2b676f44ed220064b9cfeafc4 /src/mode.rs | |
parent | 445a0fd923bb806e787892fc195a0674f8e0d2c4 (diff) |
create an enum for confirmed action
Diffstat (limited to 'src/mode.rs')
-rw-r--r-- | src/mode.rs | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/src/mode.rs b/src/mode.rs index f652a57..cf12918 100644 --- a/src/mode.rs +++ b/src/mode.rs @@ -6,6 +6,36 @@ pub enum MarkAction { New, } +#[derive(Clone, Copy)] +pub enum ConfirmedAction { + Copy, + Delete, + Move, +} + +impl ConfirmedAction { + /// Offset before the cursor. + /// Since we ask the user confirmation, we need to know how much space + /// is needed. + pub fn cursor_offset(&self) -> usize { + match *self { + Self::Copy => 37, + Self::Delete => 31, + Self::Move => 29, + } + } +} + +impl std::fmt::Display for ConfirmedAction { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match *self { + Self::Delete => write!(f, "Delete files :"), + Self::Move => write!(f, "Move files :"), + Self::Copy => write!(f, "Copy & Paste files :"), + } + } +} + /// Different mode in which the application can be. /// It dictates the reaction to event and what to display. #[derive(Clone)] @@ -34,7 +64,7 @@ pub enum Mode { Jump, /// Confirmation is required before modification is made to files : /// delete, move, copy - NeedConfirmation, + NeedConfirmation(ConfirmedAction), /// Change the type of sort Sort, /// Preview a file content @@ -64,7 +94,7 @@ impl fmt::Debug for Mode { Mode::RegexMatch => write!(f, "Regex : "), Mode::Jump => write!(f, "Jump : "), Mode::History => write!(f, "History :"), - Mode::NeedConfirmation => write!(f, "Y/N :"), + Mode::NeedConfirmation(_) => write!(f, "Y/N :"), Mode::Sort => write!(f, "Sort: Kind Name Modif Size Ext Rev :"), Mode::Preview => write!(f, "Preview : "), Mode::Shortcut => write!(f, "Shortcut :"), |