summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2019-02-20 19:54:37 -0500
committerJiayi Zhao <jeff.no.zhao@gmail.com>2019-02-20 19:54:37 -0500
commitc7497dd187e9729aef2630f22b481d02864ad3bb (patch)
treed48a7034209d27c4e3d686764d431466044d5bc7
parentf75182734a5bec0987b424aff28e2ed0acf2fe38 (diff)
cargo fmt
-rw-r--r--src/commands/change_directory.rs6
-rw-r--r--src/commands/file_operations.rs2
-rw-r--r--src/commands/parent_directory.rs58
-rw-r--r--src/commands/reload_dir.rs6
-rw-r--r--src/commands/rename_file.rs6
-rw-r--r--src/history.rs6
-rw-r--r--src/preview.rs69
-rw-r--r--src/run.rs6
-rw-r--r--src/textfield.rs4
-rw-r--r--src/window/view.rs1
10 files changed, 91 insertions, 73 deletions
diff --git a/src/commands/change_directory.rs b/src/commands/change_directory.rs
index 4d2e722..bf29fe8 100644
--- a/src/commands/change_directory.rs
+++ b/src/commands/change_directory.rs
@@ -89,7 +89,11 @@ impl std::fmt::Display for ChangeDirectory {
impl JoshutoRunnable for ChangeDirectory {
fn execute(&self, context: &mut JoshutoContext) {
Self::change_directory(&self.path, context);
- preview::preview_file(&mut context.tabs[context.curr_tab_index], &context.views, &context.config_t);
+ preview::preview_file(
+ &mut context.tabs[context.curr_tab_index],
+ &context.views,
+ &context.config_t,
+ );
ncurses::doupdate();
}
}
diff --git a/src/commands/file_operations.rs b/src/commands/file_operations.rs
index 0c064b8..aee5232 100644
--- a/src/commands/file_operations.rs
+++ b/src/commands/file_operations.rs
@@ -1,6 +1,6 @@
use lazy_static::lazy_static;
use std::path;
-use std::sync::{mpsc, Mutex, atomic};
+use std::sync::{atomic, mpsc, Mutex};
use std::thread;
use std::time;
diff --git a/src/commands/parent_directory.rs b/src/commands/parent_directory.rs
index 82afe95..7dc2f1e 100644
--- a/src/commands/parent_directory.rs
+++ b/src/commands/parent_directory.rs
@@ -21,40 +21,38 @@ impl ParentDirectory {
match std::env::set_current_dir(&context.curr_tab_ref().curr_path) {
Ok(_) => {
- {
- let curr_tab = &mut context.tabs[context.curr_tab_index];
+ let curr_tab = &mut context.tabs[context.curr_tab_index];
- let curr_list = curr_tab.curr_list.take();
- curr_tab.history.put_back(curr_list);
- let parent_list = curr_tab.parent_list.take();
- curr_tab.curr_list = parent_list;
+ let curr_list = curr_tab.curr_list.take();
+ curr_tab.history.put_back(curr_list);
+ let parent_list = curr_tab.parent_list.take();
+ curr_tab.curr_list = parent_list;
- match curr_tab.curr_path.parent() {
- Some(parent) => {
- curr_tab.parent_list = match curr_tab
- .history
- .pop_or_create(&parent, &context.config_t.sort_type)
- {
- Ok(s) => Some(s),
- Err(e) => {
- ui::wprint_err(&context.views.left_win, e.to_string().as_str());
- None
- }
- };
- }
- None => {
- ncurses::werase(context.views.left_win.win);
- ncurses::wnoutrefresh(context.views.left_win.win);
- }
+ match curr_tab.curr_path.parent() {
+ Some(parent) => {
+ curr_tab.parent_list = match curr_tab
+ .history
+ .pop_or_create(&parent, &context.config_t.sort_type)
+ {
+ Ok(s) => Some(s),
+ Err(e) => {
+ ui::wprint_err(&context.views.left_win, e.to_string().as_str());
+ None
+ }
+ };
+ }
+ None => {
+ ncurses::werase(context.views.left_win.win);
+ ncurses::wnoutrefresh(context.views.left_win.win);
}
- curr_tab.refresh(
- &context.views,
- &context.config_t,
- &context.username,
- &context.hostname,
- );
- preview::preview_file(curr_tab, &context.views, &context.config_t);
}
+ curr_tab.refresh(
+ &context.views,
+ &context.config_t,
+ &context.username,
+ &context.hostname,
+ );
+ preview::preview_file(curr_tab, &context.views, &context.config_t);
}
Err(e) => {
ui::wprint_err(&context.views.bot_win, e.to_string().as_str());
diff --git a/src/commands/reload_dir.rs b/src/commands/reload_dir.rs
index 0eff65f..ba30c2c 100644
--- a/src/commands/reload_dir.rs
+++ b/src/commands/reload_dir.rs
@@ -36,7 +36,11 @@ impl std::fmt::Display for ReloadDirList {
impl JoshutoRunnable for ReloadDirList {
fn execute(&self, context: &mut JoshutoContext) {
Self::reload(context);
- preview::preview_file(&mut context.tabs[context.curr_tab_index], &context.views, &context.config_t);
+ preview::preview_file(
+ &mut context.tabs[context.curr_tab_index],
+ &context.views,
+ &context.config_t,
+ );
ncurses::doupdate();
}
}
diff --git a/src/commands/rename_file.rs b/src/commands/rename_file.rs
index 24b3e96..53fa983 100644
--- a/src/commands/rename_file.rs
+++ b/src/commands/rename_file.rs
@@ -107,7 +107,11 @@ impl JoshutoRunnable for RenameFile {
if let Some(file_name) = file_name {
if let Some(path) = path {
self.rename_file(&path, context, file_name);
- preview::preview_file(&mut context.tabs[context.curr_tab_index], &context.views, &context.config_t);
+ preview::preview_file(
+ &mut context.tabs[context.curr_tab_index],
+ &context.views,
+ &context.config_t,
+ );
ncurses::doupdate();
}
}
diff --git a/src/history.rs b/src/history.rs
index 78e3b64..dd1d939 100644
--- a/src/history.rs
+++ b/src/history.rs
@@ -76,9 +76,9 @@ impl DirHistory {
match self.map.get_mut(&pathbuf) {
Some(s) => Ok(s),
None => Err(std::io::Error::new(
- std::io::ErrorKind::NotFound,
- "Can't find file",
- )),
+ std::io::ErrorKind::NotFound,
+ "Can't find file",
+ )),
}
}
diff --git a/src/preview.rs b/src/preview.rs
index 6e88d32..bd093bd 100644
--- a/src/preview.rs
+++ b/src/preview.rs
@@ -10,9 +10,14 @@ pub fn preview_file(curr_tab: &mut JoshutoTab, views: &JoshutoView, config_t: &J
if let Some(ref curr_list) = curr_tab.curr_list {
if let Some(entry) = curr_list.get_curr_ref() {
if entry.path.is_dir() {
- match curr_tab.history.get_mut_or_create(&entry.path, &config_t.sort_type) {
+ match curr_tab
+ .history
+ .get_mut_or_create(&entry.path, &config_t.sort_type)
+ {
Ok(dirlist) => {
- views.right_win.display_contents(dirlist, config_t.scroll_offset);
+ views
+ .right_win
+ .display_contents(dirlist, config_t.scroll_offset);
views.right_win.queue_for_refresh();
}
Err(e) => {
@@ -23,44 +28,44 @@ pub fn preview_file(curr_tab: &mut JoshutoTab, views: &JoshutoView, config_t: &J
ncurses::werase(views.right_win.win);
ncurses::wnoutrefresh(views.right_win.win);
}
-/*
- else {
- ncurses::werase(views.right_win.win);
+ /*
+ else {
+ ncurses::werase(views.right_win.win);
- if let Some(file_ext) = entry.path.extension() {
- if let Some(file_ext) = file_ext.to_str() {
- match file_ext {
- "o" | "a" | "avi" | "mp3" | "mp4" | "wmv" | "wma" |
- "mkv" | "flv" | "vob" | "wav" | "mpc" | "flac" |
- "divx" | "xcf" | "pdf" | "torrent" | "class" | "so" |
- "img" | "pyc" | "dmg" | "png" | "jpg" | "jpeg" | "out" | "svg" => {
- ui::wprint_err(&context.views.right_win, "Binary File");
- },
- _ => {
- let detective = mime_detective::MimeDetective::new().unwrap();
- match detective.detect_filepath(&entry.path) {
- Ok(mime_type) => {
- match mime_type.type_() {
- mime::TEXT => {
- text_preview(&context.views.right_win, &entry.path);
+ if let Some(file_ext) = entry.path.extension() {
+ if let Some(file_ext) = file_ext.to_str() {
+ match file_ext {
+ "o" | "a" | "avi" | "mp3" | "mp4" | "wmv" | "wma" |
+ "mkv" | "flv" | "vob" | "wav" | "mpc" | "flac" |
+ "divx" | "xcf" | "pdf" | "torrent" | "class" | "so" |
+ "img" | "pyc" | "dmg" | "png" | "jpg" | "jpeg" | "out" | "svg" => {
+ ui::wprint_err(&context.views.right_win, "Binary File");
+ },
+ _ => {
+ let detective = mime_detective::MimeDetective::new().unwrap();
+ match detective.detect_filepath(&entry.path) {
+ Ok(mime_type) => {
+ match mime_type.type_() {
+ mime::TEXT => {
+ text_preview(&context.views.right_win, &entry.path);
+ },
+ _ => {
+ ui::wprint_err(&context.views.right_win, mime_type.type_().as_str());
+ },
+ }
},
- _ => {
- ui::wprint_err(&context.views.right_win, mime_type.type_().as_str());
+ Err(e) => {
+ ui::wprint_err(&context.views.right_win, e.to_string().as_str());
},
}
- },
- Err(e) => {
- ui::wprint_err(&context.views.right_win, e.to_string().as_str());
- },
+ }
}
}
}
- }
- }
- ncurses::wnoutrefresh(context.views.right_win.win);
- }
-*/
+ ncurses::wnoutrefresh(context.views.right_win.win);
+ }
+ */
} else {
ncurses::werase(views.right_win.win);
ncurses::wnoutrefresh(views.right_win.win);
diff --git a/src/run.rs b/src/run.rs
index ea772fa..7c86e0e 100644
--- a/src/run.rs
+++ b/src/run.rs
@@ -149,7 +149,11 @@ pub fn run(config_t: config::JoshutoConfig, keymap_t: config::JoshutoKeymap) {
let mut context = JoshutoContext::new(config_t);
commands::NewTab::new_tab(&mut context);
- preview::preview_file(&mut context.tabs[context.curr_tab_index], &context.views, &context.config_t);
+ preview::preview_file(
+ &mut context.tabs[context.curr_tab_index],
+ &context.views,
+ &context.config_t,
+ );
ncurses::doupdate();
while !context.exit {
diff --git a/src/textfield.rs b/src/textfield.rs
index e4cd8da..aba713e 100644
--- a/src/textfield.rs
+++ b/src/textfield.rs
@@ -81,8 +81,8 @@ impl JoshutoTextField {
let buffer_len = buffer.len();
if curr_index != buffer_len {
for i in curr_index..buffer_len {
- curs_x += unicode_width::UnicodeWidthChar::width(buffer[i])
- .unwrap_or(1) as i32;
+ curs_x +=
+ unicode_width::UnicodeWidthChar::width(buffer[i]).unwrap_or(1) as i32;
}
curr_index = buffer_len;
}
diff --git a/src/window/view.rs b/src/window/view.rs
index 66d2c3f..7eceb97 100644
--- a/src/window/view.rs
+++ b/src/window/view.rs
@@ -20,7 +20,6 @@ impl JoshutoView {
ncurses::getmaxyx(ncurses::stdscr(), &mut term_rows, &mut term_cols);
let term_divide: i32 = term_cols / sum_ratio as i32;
-
let win_xy: (i32, i32) = (1, 10);
let win_coord: (usize, usize) = (0, term_cols as usize - win_xy.1 as usize);
let tab_win = JoshutoPanel::new(win_xy.0, win_xy.1, win_coord);