summaryrefslogtreecommitdiffstats
path: root/src/joshuto.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/joshuto.rs')
-rw-r--r--src/joshuto.rs81
1 files changed, 35 insertions, 46 deletions
diff --git a/src/joshuto.rs b/src/joshuto.rs
index fb1f504..007362e 100644
--- a/src/joshuto.rs
+++ b/src/joshuto.rs
@@ -1,9 +1,5 @@
extern crate ncurses;
-use std;
-use std::collections::HashMap;
-use std::time;
-
pub mod config;
mod command;
@@ -18,12 +14,12 @@ mod ui;
mod unix;
mod window;
-use self::config::JoshutoTheme;
-use self::config::JoshutoMimetype;
-use self::config::JoshutoPreview;
+use std::collections::HashMap;
+use std::time;
+
+use self::command::{CommandKeybind, JoshutoCommand};
+use self::config::{JoshutoMimetype, JoshutoPreview, JoshutoTheme};
use self::context::JoshutoContext;
-use self::command::CommandKeybind;
-use self::command::JoshutoCommand;
lazy_static! {
static ref theme_t: JoshutoTheme = JoshutoTheme::get_config();
@@ -31,17 +27,20 @@ lazy_static! {
static ref preview_t: JoshutoPreview = JoshutoPreview::get_config();
}
-fn recurse_get_keycommand<'a>(keymap: &'a HashMap<i32, CommandKeybind>)
- -> Option<&Box<dyn JoshutoCommand>>
-{
+fn recurse_get_keycommand<'a>(
+ keymap: &'a HashMap<i32, CommandKeybind>,
+) -> Option<&Box<dyn JoshutoCommand>> {
let (term_rows, term_cols) = ui::getmaxyx();
ncurses::timeout(-1);
let ch: i32;
{
let keymap_len = keymap.len();
- let win = window::JoshutoPanel::new(keymap_len as i32 + 1, term_cols,
- ((term_rows - keymap_len as i32 - 2) as usize, 0));
+ let win = window::JoshutoPanel::new(
+ keymap_len as i32 + 1,
+ term_cols,
+ ((term_rows - keymap_len as i32 - 2) as usize, 0),
+ );
let mut display_vec: Vec<String> = Vec::with_capacity(keymap_len);
for (key, val) in keymap {
@@ -62,20 +61,13 @@ fn recurse_get_keycommand<'a>(keymap: &'a HashMap<i32, CommandKeybind>)
}
match keymap.get(&ch) {
- Some(CommandKeybind::CompositeKeybind(m)) => {
- recurse_get_keycommand(&m)
- },
- Some(CommandKeybind::SimpleKeybind(s)) => {
- Some(s)
- },
- _ => {
- None
- }
+ Some(CommandKeybind::CompositeKeybind(m)) => recurse_get_keycommand(&m),
+ Some(CommandKeybind::SimpleKeybind(s)) => Some(s),
+ _ => None,
}
}
-fn process_threads(context: &mut JoshutoContext)
-{
+fn process_threads(context: &mut JoshutoContext) {
let wait_duration: time::Duration = time::Duration::from_millis(100);
let mut something_finished = false;
for i in 0..context.threads.len() {
@@ -87,8 +79,8 @@ fn process_threads(context: &mut JoshutoContext)
something_finished = true;
break;
} else {
- let percent = (progress_info.bytes_finished as f64 /
- progress_info.total_bytes as f64) as f32;
+ let percent =
+ (progress_info.bytes_finished as f64 / progress_info.total_bytes as f64) as f32;
ui::draw_progress_bar(&context.views.bot_win, percent);
ncurses::wnoutrefresh(context.views.bot_win.win);
ncurses::doupdate();
@@ -101,20 +93,22 @@ fn process_threads(context: &mut JoshutoContext)
}
}
-fn resize_handler(context: &mut JoshutoContext)
-{
+fn resize_handler(context: &mut JoshutoContext) {
ui::redraw_tab_view(&context.views.tab_win, &context);
{
let curr_tab = &mut context.tabs[context.curr_tab_index];
- curr_tab.refresh(&context.views, &context.config_t,
- &context.username, &context.hostname);
+ curr_tab.refresh(
+ &context.views,
+ &context.config_t,
+ &context.username,
+ &context.hostname,
+ );
}
preview::preview_file(context);
ncurses::doupdate();
}
-pub fn run(config_t: config::JoshutoConfig, keymap_t: config::JoshutoKeymap)
-{
+pub fn run(config_t: config::JoshutoConfig, keymap_t: config::JoshutoKeymap) {
ui::init_ncurses();
ncurses::doupdate();
@@ -124,9 +118,9 @@ pub fn run(config_t: config::JoshutoConfig, keymap_t: config::JoshutoKeymap)
while let Some(ch) = ncurses::get_wch() {
let ch = match ch {
- ncurses::WchResult::Char(s) => s as i32,
- ncurses::WchResult::KeyCode(s) => s,
- };
+ ncurses::WchResult::Char(s) => s as i32,
+ ncurses::WchResult::KeyCode(s) => s,
+ };
if ch == ncurses::KEY_RESIZE {
context.views.resize_views();
@@ -144,20 +138,15 @@ pub fn run(config_t: config::JoshutoConfig, keymap_t: config::JoshutoKeymap)
let keycommand: &std::boxed::Box<dyn JoshutoCommand>;
match keymap_t.keymaps.get(&ch) {
- Some(CommandKeybind::CompositeKeybind(m)) => {
- match recurse_get_keycommand(&m) {
- Some(s) => {
- keycommand = s;
- }
- None => {
- continue
- },
+ Some(CommandKeybind::CompositeKeybind(m)) => match recurse_get_keycommand(&m) {
+ Some(s) => {
+ keycommand = s;
}
-
+ None => continue,
},
Some(CommandKeybind::SimpleKeybind(s)) => {
keycommand = s;
- },
+ }
None => {
continue;
}