From ca2ff278511585ec5e2b7713773f80078ca48e7c Mon Sep 17 00:00:00 2001 From: qkzk Date: Sat, 17 Dec 2022 21:25:58 +0100 Subject: create an enum for confirmed action --- src/mode.rs | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'src/mode.rs') 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 :"), -- cgit v1.2.3