chore: Move the view from EventQueue
to Pager
Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
parent
2a97c89e54
commit
2866872265
5 changed files with 13 additions and 17 deletions
|
@ -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<W: Write> EventQueue<W> {
|
|||
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<W: Write> EventQueue<W> {
|
|||
(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<W: Write> EventQueue<W> {
|
|||
(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(())
|
||||
}
|
||||
|
|
|
@ -3,15 +3,15 @@
|
|||
|
||||
use std::io::Write;
|
||||
|
||||
use crate::controller::{mode::Mode, EventQueue};
|
||||
use crate::{controller::EventQueue, view::Mode};
|
||||
|
||||
impl<W: Write> EventQueue<W> {
|
||||
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(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<W: Write> {
|
|||
// TODO: should be part of the view?
|
||||
entries: Vec<Entrie>,
|
||||
command_to_run_on_exit: Option<String>,
|
||||
mode: Mode,
|
||||
}
|
||||
|
||||
impl<W: Write> EventQueue<W> {
|
||||
|
@ -77,9 +74,8 @@ impl<W: Write> EventQueue<W> {
|
|||
path_node_compare,
|
||||
queue_receiver,
|
||||
queue_sender,
|
||||
entries: entries,
|
||||
entries,
|
||||
command_to_run_on_exit,
|
||||
mode: Mode::Normal,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<W: Write> {
|
||||
config: Config,
|
||||
pub mode: Mode,
|
||||
pub cursor_row: i32,
|
||||
pub current_entry: PathBuf,
|
||||
out: W,
|
||||
|
@ -43,6 +46,7 @@ impl<W: Write> Pager<W> {
|
|||
terminal_cols: 0,
|
||||
terminal_rows: 0,
|
||||
text_row: 0,
|
||||
mode: Mode::Normal,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue