summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2020-11-02 12:19:21 -0500
committerJiayi Zhao <jeff.no.zhao@gmail.com>2020-11-02 12:19:21 -0500
commit0cb2c16b4661762efbe3f8263ebb7837657cfb92 (patch)
treecfd70ab8c58d4d154dd8b152ac607c42a5f92eff
parent9b6aea79036c40885f352d26e8a2a4892da15306 (diff)
stop using debug print for termion key
- fix certain commands not showing options - fix typos
-rw-r--r--src/commands/file_ops.rs4
-rw-r--r--src/commands/key_command.rs25
-rw-r--r--src/io/io_worker.rs22
-rw-r--r--src/ui/widgets/tui_menu.rs30
-rw-r--r--src/util/sort.rs8
5 files changed, 68 insertions, 21 deletions
diff --git a/src/commands/file_ops.rs b/src/commands/file_ops.rs
index 5831890..8497d5b 100644
--- a/src/commands/file_ops.rs
+++ b/src/commands/file_ops.rs
@@ -34,9 +34,7 @@ pub fn paste(context: &mut JoshutoContext, options: IOWorkerOptions) -> JoshutoR
match context.take_local_state() {
Some(state) if !state.paths.is_empty() => {
let dest = context.tab_context_ref().curr_tab_ref().pwd().to_path_buf();
- let mut options = options;
- options.kind = state.file_op;
- let worker_thread = IOWorkerThread::new(options, state.paths, dest);
+ let worker_thread = IOWorkerThread::new(state.file_op, state.paths, dest, options);
context.add_worker(worker_thread);
Ok(())
}
diff --git a/src/commands/key_command.rs b/src/commands/key_command.rs
index aceb307..97e655b 100644
--- a/src/commands/key_command.rs
+++ b/src/commands/key_command.rs
@@ -63,7 +63,7 @@ impl KeyCommand {
pub fn command(&self) -> &'static str {
match self {
Self::BulkRename => "bulk_rename",
- Self::ChangeDirectory(_) => "change_directory",
+ Self::ChangeDirectory(_) => "cd",
Self::NewTab => "new_tab",
Self::CloseTab => "close_tab",
Self::CommandLine(_, _) => "console",
@@ -79,7 +79,7 @@ impl KeyCommand {
Self::CursorMovePageUp => "cursor_move_page_up",
Self::CursorMovePageDown => "cursor_move_page_down",
- Self::DeleteFiles => "cursor_move_delete",
+ Self::DeleteFiles => "delete_files",
Self::NewDirectory(_) => "new_directory",
Self::OpenFile => "open",
Self::OpenFileWith => "open_with",
@@ -103,7 +103,7 @@ impl KeyCommand {
Self::ToggleHiddenFiles => "toggle_hidden",
Self::Sort(_) => "sort",
- Self::SortReverse => "sort_reverse",
+ Self::SortReverse => "sort reverse",
Self::TabSwitch(_) => "tab_switch",
}
@@ -248,10 +248,6 @@ impl KeyCommand {
},
},
"tab_switch" => match arg {
- "" => Err(JoshutoError::new(
- JoshutoErrorKind::IOInvalidData,
- format!("{}: {}", command, "No option provided"),
- )),
arg => match arg.parse::<i32>() {
Ok(s) => Ok(Self::TabSwitch(s)),
Err(e) => Err(JoshutoError::new(
@@ -333,7 +329,20 @@ impl JoshutoRunnable for KeyCommand {
impl std::fmt::Display for KeyCommand {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match &*self {
- Self::ChangeDirectory(p) => write!(f, "{} {}", self.command(), p.to_str().unwrap()),
+ Self::ChangeDirectory(p) => write!(f, "{} {:?}", self.command(), p),
+ Self::CommandLine(s, p) => write!(f, "{} {} {}", self.command(), s, p),
+ Self::PasteFiles(options) => write!(f, "{} {}", self.command(), options),
+ Self::CursorMoveUp(i) => write!(f, "{} {}", self.command(), i),
+ Self::CursorMoveDown(i) => write!(f, "{} {}", self.command(), i),
+ Self::NewDirectory(d) => write!(f, "{} {:?}", self.command(), d),
+ Self::RenameFile(name) => write!(f, "{} {:?}", self.command(), name),
+
+ Self::Search(s) => write!(f, "{} {}", self.command(), s),
+ Self::SelectFiles { toggle, all } => write!(f, "{} toggle={} all={}",
+ self.command(), toggle, all),
+ Self::ShellCommand(c) => write!(f, "{} {:?}", self.command(), c),
+ Self::Sort(t) => write!(f, "{} {}", self.command(), t),
+ Self::TabSwitch(i) => write!(f, "{} {}", self.command(), i),
_ => write!(f, "{}", self.command()),
}
}
diff --git a/src/io/io_worker.rs b/src/io/io_worker.rs
index adb3b74..0ff9f43 100644
--- a/src/io/io_worker.rs
+++ b/src/io/io_worker.rs
@@ -12,7 +12,6 @@ pub enum FileOp {
#[derive(Clone, Debug)]
pub struct IOWorkerOptions {
- pub kind: FileOp,
pub overwrite: bool,
pub skip_exist: bool,
}
@@ -20,13 +19,18 @@ pub struct IOWorkerOptions {
impl std::default::Default for IOWorkerOptions {
fn default() -> Self {
Self {
- kind: FileOp::Copy,
overwrite: false,
skip_exist: false,
}
}
}
+impl std::fmt::Display for IOWorkerOptions {
+ fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
+ write!(f, "overwrite={} skip_exist={}", self.overwrite, self.skip_exist)
+ }
+}
+
#[derive(Clone, Debug)]
pub struct IOWorkerProgress {
pub kind: FileOp,
@@ -37,14 +41,16 @@ pub struct IOWorkerProgress {
#[derive(Debug)]
pub struct IOWorkerThread {
+ pub kind: FileOp,
pub options: IOWorkerOptions,
pub paths: Vec<path::PathBuf>,
pub dest: path::PathBuf,
}
impl IOWorkerThread {
- pub fn new(options: IOWorkerOptions, paths: Vec<path::PathBuf>, dest: path::PathBuf) -> Self {
+ pub fn new(kind: FileOp, paths: Vec<path::PathBuf>, dest: path::PathBuf, options: IOWorkerOptions) -> Self {
Self {
+ kind,
options,
paths,
dest,
@@ -52,7 +58,7 @@ impl IOWorkerThread {
}
pub fn start(&self, tx: mpsc::Sender<IOWorkerProgress>) -> std::io::Result<IOWorkerProgress> {
- match self.options.kind {
+ match self.kind {
FileOp::Cut => self.paste_cut(tx),
FileOp::Copy => self.paste_copy(tx),
}
@@ -60,7 +66,7 @@ impl IOWorkerThread {
fn paste_copy(&self, tx: mpsc::Sender<IOWorkerProgress>) -> std::io::Result<IOWorkerProgress> {
let mut progress = IOWorkerProgress {
- kind: FileOp::Copy,
+ kind: self.kind,
index: 0,
processed: 0,
len: self.paths.len(),
@@ -76,7 +82,7 @@ impl IOWorkerThread {
)?;
}
Ok(IOWorkerProgress {
- kind: FileOp::Copy,
+ kind: self.kind,
index: self.paths.len(),
processed: progress.processed,
len: self.paths.len(),
@@ -124,7 +130,7 @@ impl IOWorkerThread {
fn paste_cut(&self, tx: mpsc::Sender<IOWorkerProgress>) -> std::io::Result<IOWorkerProgress> {
let mut progress = IOWorkerProgress {
- kind: FileOp::Cut,
+ kind: self.kind,
index: 0,
processed: 0,
len: self.paths.len(),
@@ -140,7 +146,7 @@ impl IOWorkerThread {
)?;
}
Ok(IOWorkerProgress {
- kind: FileOp::Cut,
+ kind: self.kind,
index: self.paths.len(),
processed: progress.processed,
len: self.paths.len(),
diff --git a/src/ui/widgets/tui_menu.rs b/src/ui/widgets/tui_menu.rs
index 85b0a7a..aa5a0d0 100644
--- a/src/ui/widgets/tui_menu.rs
+++ b/src/ui/widgets/tui_menu.rs
@@ -20,6 +20,34 @@ const BOTTOM_MARGIN: usize = 1;
pub struct TuiCommandMenu;
+trait ToString {
+ fn to_string(&self) -> String;
+}
+
+impl ToString for Key {
+ fn to_string(&self) -> String {
+ match *self {
+ Key::Char(c) => format!("{}", c),
+ Key::Ctrl(c) => format!("ctrl+{}", c),
+ Key::Left => format!("arrow_left"),
+ Key::Right => format!("arrow_right"),
+ Key::Up => format!("arrow_up"),
+ Key::Down => format!("arrow_down"),
+ Key::Backspace => format!("backspace"),
+ Key::Home => format!("home"),
+ Key::End => format!("end"),
+ Key::PageUp => format!("page_up"),
+ Key::PageDown => format!("page_down"),
+ Key::BackTab => format!("backtab"),
+ Key::Insert => format!("insert"),
+ Key::Delete => format!("delete"),
+ Key::Esc => format!("escape"),
+ Key::F(i) => format!("f{}", i),
+ k => format!("{:?}", k),
+ }
+ }
+}
+
impl TuiCommandMenu {
pub fn new() -> Self {
Self {}
@@ -49,7 +77,7 @@ impl TuiCommandMenu {
let mut display_vec: Vec<String> = map
.as_ref()
.iter()
- .map(|(k, v)| format!(" {:?} {}", k, v))
+ .map(|(k, v)| format!(" {} {}", k.to_string(), v))
.collect();
display_vec.sort();
let display_str: Vec<&str> = display_vec.iter().map(|v| v.as_str()).collect();
diff --git a/src/util/sort.rs b/src/util/sort.rs
index d58c946..b4e916e 100644
--- a/src/util/sort.rs
+++ b/src/util/sort.rs
@@ -24,7 +24,7 @@ impl SortType {
_ => None,
}
}
- pub fn as_str(&self) -> &str {
+ pub const fn as_str(&self) -> &str {
match *self {
SortType::Lexical => "lexical",
SortType::Mtime => "mtime",
@@ -34,6 +34,12 @@ impl SortType {
}
}
+impl std::fmt::Display for SortType {
+ fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
+ write!(f, "{}", self.as_str())
+ }
+}
+
#[derive(Clone, Debug)]
pub struct SortOption {
pub show_icons: bool,