From 28668722654c0453cd3e3b88d5b0c25cc1ecd287 Mon Sep 17 00:00:00 2001
From: Awiteb
Date: Wed, 25 Dec 2024 10:36:01 +0000
Subject: [PATCH] chore: Move the view from `EventQueue` to `Pager`
Signed-off-by: Awiteb
---
src/controller/key_event_matcher/mod.rs | 14 +++++---------
src/controller/key_event_matcher/modes.rs | 6 +++---
src/controller/mod.rs | 6 +-----
src/view/mod.rs | 4 ++++
src/{controller => view}/mode.rs | 0
5 files changed, 13 insertions(+), 17 deletions(-)
rename src/{controller => view}/mode.rs (100%)
diff --git a/src/controller/key_event_matcher/mod.rs b/src/controller/key_event_matcher/mod.rs
index 7ce617f..ad1520b 100644
--- a/src/controller/key_event_matcher/mod.rs
+++ b/src/controller/key_event_matcher/mod.rs
@@ -4,11 +4,11 @@
use crate::controller::EventQueue;
use crate::model::event::Key;
+use crate::view::Mode;
+
use std::borrow::Cow;
use std::io::Write;
-use super::mode::Mode;
-
mod collapse_dir;
mod entry_down;
mod entry_up;
@@ -23,7 +23,7 @@ impl EventQueue {
pub fn match_key_event(&mut self, key: Key) -> Option<()> {
let ck = &self.config.keybinding;
- match (self.mode.clone(), key) {
+ match (self.pager.mode.clone(), key) {
(Mode::Normal, k) if k == Key::from(&ck.collapse_dir) => self.do_collapse_dir(),
(Mode::Normal, k) if k == Key::from(&ck.entry_down) => self.do_entry_down(),
(Mode::Normal, k) if k == Key::from(&ck.entry_up) => self.do_entry_up(),
@@ -32,11 +32,7 @@ impl EventQueue {
(Mode::Normal, k) if k == Key::from(&ck.quit) => self.do_quit(),
(Mode::Normal, k) if k == Key::from(&ck.reload) => self.do_reload(),
(Mode::Normal, k) if k == Key::from(&ck.rename_mode) => self.do_enter_rename_mode(),
- (Mode::Rename(..), k)
- if k == Key::from(&ck.rename_mode) || k == Key::from(&ck.quit) =>
- {
- self.do_enter_normal_mode()
- }
+ (Mode::Rename(..), k) if k == Key::from(&ck.quit) => self.do_enter_normal_mode(),
(Mode::Rename(new_name), k) if k == Key::from("return") => {
if new_name.is_empty() {
return self.do_enter_normal_mode();
@@ -48,7 +44,7 @@ impl EventQueue {
(Mode::Rename(new_name), k) => {
if let Cow::Owned(updated_name) = self.do_handle_rename_input(&new_name, k.inner())
{
- self.mode = Mode::Rename(updated_name);
+ self.pager.mode = Mode::Rename(updated_name);
}
Some(())
}
diff --git a/src/controller/key_event_matcher/modes.rs b/src/controller/key_event_matcher/modes.rs
index c7c9d26..a46c552 100644
--- a/src/controller/key_event_matcher/modes.rs
+++ b/src/controller/key_event_matcher/modes.rs
@@ -3,15 +3,15 @@
use std::io::Write;
-use crate::controller::{mode::Mode, EventQueue};
+use crate::{controller::EventQueue, view::Mode};
impl EventQueue {
pub fn do_enter_normal_mode(&mut self) -> Option<()> {
- self.mode = Mode::Normal;
+ self.pager.mode = Mode::Normal;
Some(())
}
pub fn do_enter_rename_mode(&mut self) -> Option<()> {
- self.mode = Mode::Rename(String::new());
+ self.pager.mode = Mode::Rename(String::new());
Some(())
}
}
diff --git a/src/controller/mod.rs b/src/controller/mod.rs
index b6f7ed2..551ce57 100644
--- a/src/controller/mod.rs
+++ b/src/controller/mod.rs
@@ -11,7 +11,6 @@ use crate::model::path_node::PathNode;
use crate::view::composer::Composer;
use crate::view::Pager;
use log::info;
-use mode::Mode;
use std::io::Write;
use std::path::Path;
use std::path::PathBuf;
@@ -22,7 +21,6 @@ use std::thread;
mod key_event_handler;
mod key_event_matcher;
-mod mode;
mod resize_event_handler;
/// TODO
@@ -43,7 +41,6 @@ pub struct EventQueue {
// TODO: should be part of the view?
entries: Vec,
command_to_run_on_exit: Option,
- mode: Mode,
}
impl EventQueue {
@@ -77,9 +74,8 @@ impl EventQueue {
path_node_compare,
queue_receiver,
queue_sender,
- entries: entries,
+ entries,
command_to_run_on_exit,
- mode: Mode::Normal,
}
}
diff --git a/src/view/mod.rs b/src/view/mod.rs
index 453ffc3..2c6a096 100644
--- a/src/view/mod.rs
+++ b/src/view/mod.rs
@@ -4,16 +4,19 @@
use crate::model::config::Config;
use crate::view::composer::Composer;
use log::info;
+pub use mode::Mode;
use std::io::Write;
use std::path::{Path, PathBuf};
pub mod composer;
+mod mode;
mod print;
mod scroll;
mod update;
pub struct Pager {
config: Config,
+ pub mode: Mode,
pub cursor_row: i32,
pub current_entry: PathBuf,
out: W,
@@ -43,6 +46,7 @@ impl Pager {
terminal_cols: 0,
terminal_rows: 0,
text_row: 0,
+ mode: Mode::Normal,
}
}
}
diff --git a/src/controller/mode.rs b/src/view/mode.rs
similarity index 100%
rename from src/controller/mode.rs
rename to src/view/mode.rs