summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Zhao <jeff.no.zhao@gmail.com>2021-10-03 17:41:41 -0400
committerJeff Zhao <jeff.no.zhao@gmail.com>2021-10-03 17:41:41 -0400
commit1e18ad1b95397b18af801e5b72eba366abb92fd2 (patch)
tree29fed56bd33eae003aaffe6515227812b8b9d0be
parent112b912ec6a5070fc1e052f8cf1ab1b71459cfae (diff)
refactor some code
- rename stuff
-rw-r--r--src/commands/command_line.rs4
-rw-r--r--src/commands/help.rs16
-rw-r--r--src/commands/sort.rs2
-rw-r--r--src/config/general/config.rs (renamed from src/config/default/config.rs)8
-rw-r--r--src/config/general/display.rs (renamed from src/config/default/display.rs)2
-rw-r--r--src/config/general/mod.rs (renamed from src/config/default/mod.rs)0
-rw-r--r--src/config/general/preview.rs (renamed from src/config/default/preview.rs)0
-rw-r--r--src/config/general/sort.rs50
-rw-r--r--src/config/general/tab.rs (renamed from src/config/default/tab.rs)0
-rw-r--r--src/config/keymap/keymapping.rs88
-rw-r--r--src/config/mod.rs4
-rw-r--r--src/config/sort/mod.rs11
-rw-r--r--src/config/sort/sort.rs (renamed from src/config/default/sort.rs)0
-rw-r--r--src/fs/dirlist.rs2
-rw-r--r--src/fs/entry.rs2
-rw-r--r--src/history.rs2
-rw-r--r--src/key_command/command.rs (renamed from src/key_command/key_command.rs)4
-rw-r--r--src/key_command/command_keybind.rs4
-rw-r--r--src/key_command/impl_appcommand.rs4
-rw-r--r--src/key_command/impl_appexecute.rs4
-rw-r--r--src/key_command/impl_comment.rs6
-rw-r--r--src/key_command/impl_display.rs4
-rw-r--r--src/key_command/impl_from_str.rs6
-rw-r--r--src/key_command/mod.rs4
-rw-r--r--src/run.rs6
-rw-r--r--src/tab.rs2
-rw-r--r--src/ui/tui_backend.rs2
-rw-r--r--src/util/display_option.rs (renamed from src/util/display.rs)10
-rw-r--r--src/util/input.rs12
-rw-r--r--src/util/mod.rs5
-rw-r--r--src/util/sort_option.rs58
-rw-r--r--src/util/sort_type.rs (renamed from src/util/sort.rs)50
32 files changed, 222 insertions, 150 deletions
diff --git a/src/commands/command_line.rs b/src/commands/command_line.rs
index 5b8eb44..5848b6d 100644
--- a/src/commands/command_line.rs
+++ b/src/commands/command_line.rs
@@ -3,7 +3,7 @@ use std::str::FromStr;
use crate::config::AppKeyMapping;
use crate::context::AppContext;
use crate::error::JoshutoResult;
-use crate::key_command::{AppExecute, KeyCommand};
+use crate::key_command::{AppExecute, Command};
use crate::ui::views::TuiTextField;
use crate::ui::TuiBackend;
@@ -24,7 +24,7 @@ pub fn read_and_execute(
if let Some(s) = user_input {
let trimmed = s.trim_start();
context.commandline_context_mut().history_mut().add(trimmed);
- let command = KeyCommand::from_str(trimmed)?;
+ let command = Command::from_str(trimmed)?;
command.execute(context, backend, keymap_t)
} else {
Ok(())
diff --git a/src/commands/help.rs b/src/commands/help.rs
index 44bbeb8..a30235f 100644
--- a/src/commands/help.rs
+++ b/src/commands/help.rs
@@ -4,7 +4,7 @@ use crate::config::AppKeyMapping;
use crate::context::AppContext;
use crate::error::JoshutoResult;
use crate::event::AppEvent;
-use crate::key_command::{CommandKeybind, KeyCommand};
+use crate::key_command::{Command, CommandKeybind};
use crate::ui::widgets;
use crate::ui::widgets::TuiHelp;
use crate::ui::TuiBackend;
@@ -48,13 +48,13 @@ pub fn help_loop(
keymap_t.as_ref().get(&event)
{
match command {
- KeyCommand::CursorMoveUp(_) => move_offset(&mut offset, -1),
- KeyCommand::CursorMoveDown(_) => move_offset(&mut offset, 1),
- KeyCommand::CursorMoveHome => offset = 0,
- KeyCommand::CursorMoveEnd => offset = 255,
- KeyCommand::CursorMovePageUp => move_offset(&mut offset, -10),
- KeyCommand::CursorMovePageDown => move_offset(&mut offset, 10),
- KeyCommand::CloseTab | KeyCommand::Help => break,
+ Command::CursorMoveUp(_) => move_offset(&mut offset, -1),
+ Command::CursorMoveDown(_) => move_offset(&mut offset, 1),
+ Command::CursorMoveHome => offset = 0,
+ Command::CursorMoveEnd => offset = 255,
+ Command::CursorMovePageUp => move_offset(&mut offset, -10),
+ Command::CursorMovePageDown => move_offset(&mut offset, 10),
+ Command::CloseTab | Command::Help => break,
_ => (),
}
}
diff --git a/src/commands/sort.rs b/src/commands/sort.rs
index dfc86a2..7102fc3 100644
--- a/src/commands/sort.rs
+++ b/src/commands/sort.rs
@@ -1,7 +1,7 @@
use crate::context::AppContext;
use crate::error::JoshutoResult;
use crate::history::DirectoryHistory;
-use crate::util::sort::SortType;
+use crate::util::sort_type::SortType;
use super::reload;
diff --git a/src/config/default/config.rs b/src/config/general/config.rs
index 6559c48..dba8dcf 100644
--- a/src/config/default/config.rs
+++ b/src/config/general/config.rs
@@ -5,8 +5,8 @@ use super::tab::{TabOption, TabRawOption};
use super::DisplayRawOption;
use crate::config::{parse_to_config_file, ConfigStructure, Flattenable};
-use crate::util::display::DisplayOption;
-use crate::util::sort;
+use crate::util::display_option::DisplayOption;
+use crate::util::sort_option::SortOption;
const fn default_true() -> bool {
true
@@ -69,10 +69,10 @@ impl AppConfig {
&mut self._preview_options
}
- pub fn sort_options_ref(&self) -> &sort::SortOption {
+ pub fn sort_options_ref(&self) -> &SortOption {
self.display_options_ref().sort_options_ref()
}
- pub fn sort_options_mut(&mut self) -> &mut sort::SortOption {
+ pub fn sort_options_mut(&mut self) -> &mut SortOption {
self.display_options_mut().sort_options_mut()
}
diff --git a/src/config/default/display.rs b/src/config/general/display.rs
index 4663a4c..7ca6456 100644
--- a/src/config/default/display.rs
+++ b/src/config/general/display.rs
@@ -2,7 +2,7 @@ use serde_derive::Deserialize;
use tui::layout::Constraint;
use crate::config::Flattenable;
-use crate::util::display::{default_column_ratio, DisplayOption};
+use crate::util::display_option::{default_column_ratio, DisplayOption};
use super::SortRawOption;
diff --git a/src/config/default/mod.rs b/src/config/general/mod.rs
index dc8617c..dc8617c 100644
--- a/src/config/default/mod.rs
+++ b/src/config/general/mod.rs
diff --git a/src/config/default/preview.rs b/src/config/general/preview.rs
index 5d9436f..5d9436f 100644
--- a/src/config/default/preview.rs
+++ b/src/config/general/preview.rs
diff --git a/src/config/general/sort.rs b/src/config/general/sort.rs
new file mode 100644
index 0000000..fea3db2
--- /dev/null
+++ b/src/config/general/sort.rs
@@ -0,0 +1,50 @@
+use serde_derive::Deserialize;
+
+use crate::util::sort_option::SortOption;
+use crate::util::sort_type::{SortType, SortTypes};
+
+const fn default_true() -> bool {
+ true
+}
+
+#[derive(Clone, Debug, Deserialize)]
+pub struct SortRawOption {
+ #[serde(default = "default_true")]
+ pub directories_first: bool,
+ #[serde(default)]
+ pub case_sensitive: bool,
+ #[serde(default)]
+ pub reverse: bool,
+ #[serde(default)]
+ pub sort_method: Option<String>,
+}
+
+impl SortRawOption {
+ pub fn into(self) -> SortOption {
+ let sort_method = match self.sort_method.as_ref() {
+ Some(s) => SortType::parse(s).unwrap_or(SortType::Natural),
+ None => SortType::Natural,
+ };
+
+ let mut sort_methods = SortTypes::default();
+ sort_methods.reorganize(sort_method);
+
+ SortOption {
+ directories_first: self.directories_first,
+ case_sensitive: self.case_sensitive,
+ reverse: self.reverse,
+ sort_methods,
+ }
+ }
+}
+
+impl std::default::Default for SortRawOption {
+ fn default() -> Self {
+ Self {
+ directories_first: default_true(),
+ case_sensitive: bool::default(),
+ reverse: bool::default(),
+ sort_method: None,
+ }
+ }
+}
diff --git a/src/config/default/tab.rs b/src/config/general/tab.rs
index 1cd6a88..1cd6a88 100644
--- a/src/config/default/tab.rs
+++ b/src/config/general/tab.rs
diff --git a/src/config/keymap/keymapping.rs b/src/config/keymap/keymapping.rs
index 6cb682f..9250c28 100644
--- a/src/config/keymap/keymapping.rs
+++ b/src/config/keymap/keymapping.rs
@@ -9,7 +9,7 @@ use termion::event::{Event, Key};
use crate::config::{parse_to_config_file, ConfigStructure, Flattenable};
use crate::io::IoWorkerOptions;
-use crate::key_command::{CommandKeybind, KeyCommand};
+use crate::key_command::{Command, CommandKeybind};
use crate::util::keyparse::str_to_event;
#[derive(Debug, Deserialize)]
@@ -28,7 +28,7 @@ impl Flattenable<AppKeyMapping> for RawAppKeyMapping {
fn flatten(self) -> AppKeyMapping {
let mut keymaps = AppKeyMapping::new();
for m in self.mapcommand {
- match KeyCommand::from_str(m.command.as_str()) {
+ match Command::from_str(m.command.as_str()) {
Ok(command) => {
let events: Vec<Event> = m
.keys
@@ -81,162 +81,162 @@ impl AppKeyMapping {
pub fn default_res(&mut self) -> Result<(), String> {
let mut m = self;
- let cmd = KeyCommand::CursorMoveUp(1);
+ let cmd = Command::CursorMoveUp(1);
let keys = [Event::Key(Key::Up)];
insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = KeyCommand::CursorMoveDown(1);
+ let cmd = Command::CursorMoveDown(1);
let keys = [Event::Key(Key::Down)];
insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = KeyCommand::ParentDirectory;
+ let cmd = Command::ParentDirectory;
let keys = [Event::Key(Key::Left)];
insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = KeyCommand::OpenFile;
+ let cmd = Command::OpenFile;
let keys = [Event::Key(Key::Right)];
insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = KeyCommand::OpenFile;
+ let cmd = Command::OpenFile;
let keys = [Event::Key(Key::Char('\n'))];
insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = KeyCommand::CursorMoveHome;
+ let cmd = Command::CursorMoveHome;
let keys = [Event::Key(Key::Home)];
insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = KeyCommand::CursorMoveEnd;
+ let cmd = Command::CursorMoveEnd;
let keys = [Event::Key(Key::End)];
insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = KeyCommand::CursorMovePageUp;
+ let cmd = Command::CursorMovePageUp;
let keys = [Event::Key(Key::PageUp)];
insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = KeyCommand::CursorMovePageDown;
+ let cmd = Command::CursorMovePageDown;
let keys = [Event::Key(Key::PageDown)];
insert_keycommand(&mut m, cmd, &keys)?;
// vim keys
- let cmd = KeyCommand::CursorMoveUp(1);
+ let cmd = Command::CursorMoveUp(1);
let keys = [Event::Key(Key::Char('k'))];
insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = KeyCommand::CursorMoveDown(1);
+ let cmd = Command::CursorMoveDown(1);
let keys = [Event::Key(Key::Char('j'))];
insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = KeyCommand::ParentDirectory;
+ let cmd = Command::ParentDirectory;
let keys = [Event::Key(Key::Char('h'))];
insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = KeyCommand::OpenFile;
+ let cmd = Command::OpenFile;
let keys = [Event::Key(Key::Char('l'))];
insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = KeyCommand::NewTab;
+ let cmd = Command::NewTab;
let keys = [Event::Key(Key::Char('T'))];
insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = KeyCommand::NewTab;
+ let cmd = Command::NewTab;
let keys = [Event::Key(Key::Ctrl('t'))];
insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = KeyCommand::CloseTab;
+ let cmd = Command::CloseTab;
let keys = [Event::Key(Key::Char('W'))];
insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = KeyCommand::CloseTab;
+ let cmd = Command::CloseTab;
let keys = [Event::Key(Key::Ctrl('w'))];
insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = KeyCommand::CloseTab;
+ let cmd = Command::CloseTab;
let keys = [Event::Key(Key::Char('q'))];
insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = KeyCommand::ForceQuit;
+ let cmd = Command::ForceQuit;
let keys = [Event::Key(Key::Char('Q'))];
insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = KeyCommand::ReloadDirList;
+ let cmd = Command::ReloadDirList;
let keys = [Event::Key(Key::Char('R'))];
insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = KeyCommand::ToggleHiddenFiles;
+ let cmd = Command::ToggleHiddenFiles;
let keys = [Event::Key(Key::Char('z')), Event::Key(Key::Char('h'))];
insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = KeyCommand::TabSwitch(1);
+ let cmd = Command::TabSwitch(1);
let keys = [Event::Key(Key::Char('\t'))];
insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = KeyCommand::TabSwitch(-1);
+ let cmd = Command::TabSwitch(-1);
let keys = [Event::Key(Key::BackTab)];
insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = KeyCommand::OpenFileWith(None);
+ let cmd = Command::OpenFileWith(None);
let keys = [Event::Key(Key::Char('r'))];
insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = KeyCommand::CutFiles;
+ let cmd = Command::CutFiles;
let keys = [Event::Key(Key::Char('d')), Event::Key(Key::Char('d'))];
insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = KeyCommand::CopyFiles;
+ let cmd = Command::CopyFiles;
let keys = [Event::Key(Key::Char('y')), Event::Key(Key::Char('y'))];
insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = KeyCommand::PasteFiles(IoWorkerOptions::default());
+ let cmd = Command::PasteFiles(IoWorkerOptions::default());
let keys = [Event::Key(Key::Char('p')), Event::Key(Key::Char('p'))];
insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = KeyCommand::DeleteFiles;
+ let cmd = Command::DeleteFiles;
let keys = [Event::Key(Key::Delete)];
insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = KeyCommand::DeleteFiles;
+ let cmd = Command::DeleteFiles;
let keys = [Event::Key(Key::Char('D')), Event::Key(Key::Char('d'))];
insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = KeyCommand::RenameFileAppend;
+ let cmd = Command::RenameFileAppend;
let keys = [Event::Key(Key::Char('a'))];
insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = KeyCommand::RenameFilePrepend;
+ let cmd = Command::RenameFilePrepend;
let keys = [Event::Key(Key::Char('A'))];
insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = KeyCommand::CommandLine("search ".to_string(), "".to_string());
+ let cmd = Command::CommandLine("search ".to_string(), "".to_string());
let keys = [Event::Key(Key::Char('/'))];
insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = KeyCommand::SearchNext;
+ let cmd = Command::SearchNext;
let keys = [Event::Key(Key::Char('n'))];
insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = KeyCommand::SearchPrev;
+ let cmd = Command::SearchPrev;
let keys = [Event::Key(Key::Char('N'))];
insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = KeyCommand::BulkRename;
+ let cmd = Command::BulkRename;
let keys = [Event::Key(Key::Char('b')), Event::Key(Key::Char('b'))];
insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = KeyCommand::SetMode;
+ let cmd = Command::SetMode;
let keys = [Event::Key(Key::Char('='))];
insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = KeyCommand::CommandLine("".to_string(), "".to_string());
+ let cmd = Command::CommandLine("".to_string(), "".to_string());
let keys = [Event::Key(Key::Char(';'))];
insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = KeyCommand::CommandLine("".to_string(), "".to_string());
+ let cmd = Command::CommandLine("".to_string(), "".to_string());
let keys = [Event::Key(Key::Char(':'))];
insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = KeyCommand::CommandLine("mkdir ".to_string(), "".to_string());
+ let cmd = Command::CommandLine("mkdir ".to_string(), "".to_string());
let keys = [Event::Key(Key::Char('m')), Event::Key(Key::Char('k'))];
insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = KeyCommand::CommandLine("rename ".to_string(), "".to_string());
+ let cmd = Command::CommandLine("rename ".to_string(), "".to_string());
let keys = [Event::Key(Key::Char('c')), Event::Key(Key::Char('w'))];
insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = KeyCommand::Help;
+ let cmd = Command::Help;
let keys = [Event::Key(Key::Char('?'))];
insert_keycommand(&mut m, cmd, &keys)?;
@@ -263,7 +263,7 @@ impl ConfigStructure for AppKeyMapping {
fn insert_keycommand(
keymap: &mut AppKeyMapping,
- keycommand: KeyCommand,
+ keycommand: Command,
events: &[Event],
) -> Result<(), String> {
let num_events = events.len();
diff --git a/src/config/mod.rs b/src/config/mod.rs
index 6cc4386..23a3e7d 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -1,10 +1,10 @@
-pub mod default;
+pub mod general;
pub mod keymap;
pub mod mimetype;
pub mod preview;
pub mod theme;
-pub use self::default::AppConfig;
+pub use self::general::AppConfig;
pub use self::keymap::AppKeyMapping;
pub use self::mimetype::{AppMimetypeEntry, AppMimetypeRegistry};
pub use self::preview::{JoshutoPreview, JoshutoPreviewEntry};
diff --git a/src/config/sort/mod.rs b/src/config/sort/mod.rs
new file mode 100644
index 0000000..dc8617c
--- /dev/null
+++ b/src/config/sort/mod.rs
@@ -0,0 +1,11 @@
+pub mod config;
+pub mod display;
+pub mod preview;
+pub mod sort;
+pub mod tab;
+
+pub use self::config::AppConfig;
+pub use self::display::DisplayRawOption;
+pub use self::preview::{PreviewOption, PreviewRawOption};
+pub use self::sort::SortRawOption;
+pub use self::tab::{TabOption, TabRawOption};
diff --git a/src/config/default/sort.rs b/src/config/sort/sort.rs
index 0768c98..0768c98 100644
--- a/src/config/default/sort.rs
+++ b/src/config/sort/sort.rs
diff --git a/src/fs/dirlist.rs b/src/fs/dirlist.rs
index 0e48820..698e1ac 100644
--- a/src/fs/dirlist.rs
+++ b/src/fs/dirlist.rs
@@ -3,7 +3,7 @@ use std::slice::{Iter, IterMut};
use crate::fs::{JoshutoDirEntry, JoshutoMetadata};
use crate::history::read_directory;
-use crate::util::display::DisplayOption;
+use crate::util::display_option::DisplayOption;
#[derive(Clone, Debug)]
pub struct JoshutoDirList {
diff --git a/src/fs/entry.rs b/src/fs/entry.rs
index a36648b..fb62f2e 100644
--- a/src/fs/entry.rs
+++ b/src/fs/entry.rs
@@ -4,7 +4,7 @@ use crate::fs::{FileType, JoshutoMetadata};
#[cfg(feature = "devicons")]
use crate::util::devicons::*;
-use crate::util::display::DisplayOption;
+use crate::util::display_option::DisplayOption;
#[derive(Clone, Debug)]
pub struct JoshutoDirEntry {
diff --git a/src/history.rs b/src/history.rs
index c426f8f..90f7c92 100644
--- a/src/history.rs
+++ b/src/history.rs
@@ -4,7 +4,7 @@ use std::io;
use std::path::{Path, PathBuf};
use crate::fs::{JoshutoDirEntry, JoshutoDirList, JoshutoMetadata};
-use crate::util::display::DisplayOption;
+use crate::util::display_option::DisplayOption;
pub trait DirectoryHistory {
fn populate_to_root(&mut self, path: &Path, options: &DisplayOption) -> io::Result<()>;
diff --git a/src/key_command/key_command.rs b/src/key_command/command.rs
index e363e4b..34e8340 100644
--- a/src/key_command/key_command.rs
+++ b/src/key_command/command.rs
@@ -2,10 +2,10 @@ use std::path;
use crate::io::IoWorkerOptions;
use crate::util::select::SelectOption;
-use crate::util::sort::SortType;
+use crate::util::sort_type::SortType;
#[derive(Clone, Debug)]
-pub enum KeyCommand {
+pub enum Command {
BulkRename,
ChangeDirectory(path::PathBuf),
CommandLine(String, String),
diff --git a/src/key_command/command_keybind.rs b/src/key_command/command_keybind.rs
index 3a45fe6..e989644 100644
--- a/src/key_command/command_keybind.rs
+++ b/src/key_command/command_keybind.rs
@@ -1,10 +1,10 @@
use crate::config::AppKeyMapping;
-use super::KeyCommand;
+use super::Command;
#[derive(Debug)]
pub enum CommandKeybind {
- SimpleKeybind(KeyCommand),
+ SimpleKeybind(Command),
CompositeKeybind(AppKeyMapping),
}
diff --git a/src/key_command/impl_appcommand.rs b/src/key_command/impl_appcommand.rs
index 6a6d789..329f978 100644
--- a/src/key_command/impl_appcommand.rs
+++ b/src/key_command/impl_appcommand.rs
@@ -1,7 +1,7 @@
use super::constants::*;
-use super::{AppCommand, KeyCommand};
+use super::{AppCommand, Command};
-impl AppCommand for KeyCommand {
+impl AppCommand for Command {
fn command(&self) -> &'static str {
match self {
Self::Help => CMD_HELP,
diff --git a/src/key_command/impl_appexecute.rs b/src/key_command/impl_appexecute.rs
index 33c7693..d678192 100644
--- a/src/key_command/impl_appexecute.rs
+++ b/src/key_command/impl_appexecute.rs
@@ -4,9 +4,9 @@ use crate::context::AppContext;
use crate::error::JoshutoResult;
use crate::ui::TuiBackend;
-use super::{AppExecute, KeyCommand};
+use super::{AppExecute, Command};
-impl AppExecute for KeyCommand {
+impl AppExecute for Command {
fn execute(
&self,
context: &mut AppContext,
diff --git a/src/key_command/impl_comment.rs b/src/key_command/impl_comment.rs
index b3ceebf..830cd8c 100644
--- a/src/key_command/impl_comment.rs
+++ b/src/key_command/impl_comment.rs
@@ -1,9 +1,9 @@
use crate::io::IoWorkerOptions;
-use crate::util::sort::SortType;
+use crate::util::sort_type::SortType;
-use super::{CommandComment, KeyCommand};
+use super::{Command, CommandComment};
-impl CommandComment for KeyCommand {
+impl CommandComment for Command {
// These comments are displayed at the help page
fn comment(&self) -> &'static str {
match self {
diff --git a/src/key_command/impl_display.rs b/src/key_command/impl_display.rs
index 54fc362..151b464 100644
--- a/src/key_command/impl_display.rs
+++ b/src/key_command/impl_display.rs
@@ -1,6 +1,6 @@
-use super::{AppCommand, KeyCommand};
+use super::{AppCommand, Command};
-impl std::fmt::Display for KeyCommand {
+impl std::fmt::Display for Command {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match &*self {
Self::ChangeDirectory(p) => write!(f, "{} {:?}", self.command(), p),
diff --git a/src/key_command/impl_from_str.rs b/src/key_command/impl_from_str.rs
index 492d337..c679315 100644
--- a/src/key_command/impl_from_str.rs
+++ b/src/key_command/impl_from_str.rs
@@ -6,14 +6,14 @@ use shellexpand::tilde_with_context;
use crate::error::{JoshutoError, JoshutoErrorKind};
use crate::io::IoWorkerOptions;
use crate::util::select::SelectOption;
-use crate::util::sort::SortType;
+use crate::util::sort_type::SortType;
use crate::HOME_DIR;
use super::constants::*;
-use super::KeyCommand;
+use super::Command;
-impl std::str::FromStr for KeyCommand {
+impl std::str::FromStr for Command {
type Err = JoshutoError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
diff --git a/src/key_command/mod.rs b/src/key_command/mod.rs
index 4ce4b6e..6b96b59 100644
--- a/src/key_command/mod.rs
+++ b/src/key_command/mod.rs
@@ -1,6 +1,6 @@
+pub mod command;
pub mod command_keybind;
pub mod constants;
-pub mod key_command;
pub mod traits;
mod impl_appcommand;
@@ -9,7 +9,7 @@ mod impl_comment;
mod impl_display;
mod impl_from_str;
+pub use self::command::*;
pub use self::command_keybind::*;
pub use self::constants::*;
-pub use self::key_command::*;
pub use self::traits::*;
diff --git a/src/run.rs b/src/run.rs
index e8ba209..ced61dc 100644
--- a/src/run.rs
+++ b/src/run.rs
@@ -3,7 +3,7 @@ use termion::event::Event;
use crate::config::AppKeyMapping;
use crate::context::{AppContext, QuitType};
use crate::event::AppEvent;
-use crate::key_command::{AppExecute, CommandKeybind, KeyCommand};
+use crate::key_command::{AppExecute, Command, CommandKeybind};
use crate::preview::preview_default;
use crate::tab::JoshutoTab;
use crate::ui;
@@ -51,13 +51,13 @@ pub fn run(
// in the event where mouse input is not supported
// but we still want to register scroll
Event::Unsupported(s) if s.as_slice() == [27, 79, 65] => {
- let command = KeyCommand::CursorMoveUp(1);
+ let command = Command::CursorMoveUp(1);
if let Err(e) = command.execute(context, backend, &keymap_t) {
context.message_queue_mut().push_error(e.to_string());
}
}
Event::Unsupported(s) if s.as_slice() == [27, 79, 66] => {
- let command = KeyCommand::CursorMoveDown(1);
+ let command = Command::CursorMoveDown(1);
if let Err(e) = command.execute(context, backend, &keymap_t) {
context.message_queue_mut().push_error(e.to_string());
}
diff --git a/src/tab.rs b/src/tab.rs
index bcd97bb..fc76ef4 100644
--- a/src/tab.rs
+++ b/src/tab.rs
@@ -2,7 +2,7 @@ use std::path;
use crate::fs::JoshutoDirList;
use crate::history::{DirectoryHistory, JoshutoHistory};
-use crate::util::display::DisplayOption;
+use crate::util::display_option::DisplayOption;
#[derive(Clone, Copy, Debug)]
pub enum TabHomePage {
diff --git a/src/ui/tui_backend.rs b/src/ui/tui_backend.rs
index cf32c01..336226f 100644
--- a/src/ui/tui_backend.rs
+++ b/src/ui/tui_backend.rs
@@ -10,7 +10,7 @@ use tui::widgets::{Block, Borders, Widget};
#[cfg(feature = "mouse")]
use termion::input::MouseTerminal;
-use crate::util::display::DisplayOption;
+use crate::util::display_option::DisplayOption;
trait New {
fn new() -> std::io::Result<Self>
diff --git a/src/util/display.rs b/src/util/display_option.rs
index 913f063..bc2d247 100644
--- a/src/util/display.rs
+++ b/src/util/display_option.rs
@@ -2,7 +2,7 @@ use std::fs;
use tui::layout::Constraint;
-use crate::util::sort;
+use crate::util::sort_option::SortOption;
pub const fn default_column_ratio() -> (usize, usize, usize) {
(1, 3, 4)
@@ -17,7 +17,7 @@ pub struct DisplayOption {
pub _show_hidden: bool,
pub _show_icons: bool,
pub _show_preview: bool,
- pub _sort_options: sort::SortOption,
+ pub _sort_options: SortOption,
pub _tilde_in_titlebar: bool,
pub default_layout: [Constraint; 3],
pub no_preview_layout: [Constraint; 3],
@@ -53,11 +53,11 @@ impl DisplayOption {
self._show_hidden = show_hidden;
}
- pub fn sort_options_ref(&self) -> &sort::SortOption {
+ pub fn sort_options_ref(&self) -> &SortOption {
&self._sort_options
}
- pub fn sort_options_mut(&mut self) -> &mut sort::SortOption {
+ pub fn sort_options_mut(&mut self) -> &mut SortOption {
&mut self._sort_options
}