summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Zhao <jeff.no.zhao@gmail.com>2022-06-29 11:18:20 -0400
committerJeff Zhao <jeff.no.zhao@gmail.com>2022-06-29 11:19:16 -0400
commit022eb53457560e54dea5654a7e54d594392c92af (patch)
tree599be28f78e67e99590e95b4a23af96e7c618749
parent02e03b02c9a95c39ed9ad6d0c717fb7e5ab7b17a (diff)
rename TuiBackend to AppBackend
- fix initial view not correctly offset
-rw-r--r--src/commands/bulk_rename.rs4
-rw-r--r--src/commands/command_line.rs4
-rw-r--r--src/commands/cursor_move.rs14
-rw-r--r--src/commands/delete_files.rs8
-rw-r--r--src/commands/numbered_command.rs4
-rw-r--r--src/commands/open_file.rs140
-rw-r--r--src/commands/rename_file.rs10
-rw-r--r--src/commands/search_fzf.rs4
-rw-r--r--src/commands/set_mode.rs4
-rw-r--r--src/commands/show_help.rs4
-rw-r--r--src/commands/show_tasks.rs4
-rw-r--r--src/commands/sub_process.rs4
-rw-r--r--src/commands/subdir_fzf.rs4
-rw-r--r--src/commands/zoxide.rs4
-rw-r--r--src/event/process_event.rs6
-rw-r--r--src/key_command/impl_appexecute.rs4
-rw-r--r--src/key_command/impl_numbered.rs4
-rw-r--r--src/key_command/traits.rs6
-rw-r--r--src/main.rs2
-rw-r--r--src/run.rs8
-rw-r--r--src/ui/backend.rs (renamed from src/ui/tui_backend.rs)24
-rw-r--r--src/ui/mod.rs4
-rw-r--r--src/ui/views/tui_folder_view.rs8
-rw-r--r--src/ui/views/tui_textfield.rs4
-rw-r--r--src/ui/widgets/tui_prompt.rs4
25 files changed, 147 insertions, 139 deletions
diff --git a/src/commands/bulk_rename.rs b/src/commands/bulk_rename.rs
index 540036b..3a94f11 100644
--- a/src/commands/bulk_rename.rs
+++ b/src/commands/bulk_rename.rs
@@ -8,7 +8,7 @@ use rand::Rng;
use crate::context::AppContext;
use crate::error::{JoshutoError, JoshutoErrorKind, JoshutoResult};
-use crate::ui::TuiBackend;
+use crate::ui::AppBackend;
use crate::util::process::wait_for_enter;
use super::reload;
@@ -122,7 +122,7 @@ pub fn _bulk_rename(context: &mut AppContext) -> JoshutoResult {
Ok(())
}
-pub fn bulk_rename(context: &mut AppContext, backend: &mut TuiBackend) -> JoshutoResult {
+pub fn bulk_rename(context: &mut AppContext, backend: &mut AppBackend) -> JoshutoResult {
context.remove_external_preview();
backend.terminal_drop();
let res = _bulk_rename(context);
diff --git a/src/commands/command_line.rs b/src/commands/command_line.rs
index 887ea32..9c5aa70 100644
--- a/src/commands/command_line.rs
+++ b/src/commands/command_line.rs
@@ -5,11 +5,11 @@ use crate::context::AppContext;
use crate::error::JoshutoResult;
use crate::key_command::{AppExecute, Command};
use crate::ui::views::TuiTextField;
-use crate::ui::TuiBackend;
+use crate::ui::AppBackend;
pub fn read_and_execute(
context: &mut AppContext,
- backend: &mut TuiBackend,
+ backend: &mut AppBackend,
keymap_t: &AppKeyMapping,
prefix: &str,
suffix: &str,
diff --git a/src/commands/cursor_move.rs b/src/commands/cursor_move.rs
index 64809c5..ccb8d98 100644
--- a/src/commands/cursor_move.rs
+++ b/src/commands/cursor_move.rs
@@ -1,6 +1,6 @@
use crate::context::AppContext;
use crate::error::JoshutoResult;
-use crate::ui::TuiBackend;
+use crate::ui::AppBackend;
pub fn lazy_load_directory_size(context: &mut AppContext) {
let directory_size = match context
@@ -120,7 +120,7 @@ pub fn end(context: &mut AppContext) -> JoshutoResult {
Ok(())
}
-fn get_page_size(context: &AppContext, backend: &TuiBackend) -> Option<usize> {
+fn get_page_size(context: &AppContext, backend: &AppBackend) -> Option<usize> {
let config = context.config_ref();
let rect = backend.terminal.as_ref().map(|t| t.size())?.ok()?;
@@ -140,7 +140,7 @@ fn get_page_size(context: &AppContext, backend: &TuiBackend) -> Option<usize> {
pub fn page_up(
context: &mut AppContext,
- backend: &mut TuiBackend,
+ backend: &mut AppBackend,
proportion: f64,
) -> JoshutoResult {
let page_size = get_page_size(context, backend).unwrap_or(10) as f64 * proportion;
@@ -160,7 +160,7 @@ pub fn page_up(
pub fn page_down(
context: &mut AppContext,
- backend: &mut TuiBackend,
+ backend: &mut AppBackend,
proportion: f64,
) -> JoshutoResult {
let page_size = get_page_size(context, backend).unwrap_or(10) as f64 * proportion;
@@ -178,7 +178,7 @@ pub fn page_down(
Ok(())
}
-pub fn page_home(context: &mut AppContext, _: &mut TuiBackend) -> JoshutoResult {
+pub fn page_home(context: &mut AppContext, _: &mut AppBackend) -> JoshutoResult {
let new_index = context
.tab_context_ref()
.curr_tab_ref()
@@ -190,7 +190,7 @@ pub fn page_home(context: &mut AppContext, _: &mut TuiBackend) -> JoshutoResult
Ok(())
}
-pub fn page_middle(context: &mut AppContext, backend: &mut TuiBackend) -> JoshutoResult {
+pub fn page_middle(context: &mut AppContext, backend: &mut AppBackend) -> JoshutoResult {
let movement = get_page_size(context, backend).unwrap_or(10) / 2;
let new_index = context
@@ -204,7 +204,7 @@ pub fn page_middle(context: &mut AppContext, backend: &mut TuiBackend) -> Joshut
Ok(())
}
-pub fn page_end(context: &mut AppContext, backend: &mut TuiBackend) -> JoshutoResult {
+pub fn page_end(context: &mut AppContext, backend: &mut AppBackend) -> JoshutoResult {
let movement = get_page_size(context, backend).unwrap_or(10) - 1;
let new_index = context
diff --git a/src/commands/delete_files.rs b/src/commands/delete_files.rs
index 126346f..b702771 100644
--- a/src/commands/delete_files.rs
+++ b/src/commands/delete_files.rs
@@ -6,7 +6,7 @@ use termion::event::Key;
use crate::context::AppContext;
use crate::history::DirectoryHistory;
use crate::ui::widgets::TuiPrompt;
-use crate::ui::TuiBackend;
+use crate::ui::AppBackend;
use super::reload;
@@ -50,7 +50,7 @@ where
Ok(())
}
-fn delete_files(context: &mut AppContext, backend: &mut TuiBackend) -> std::io::Result<()> {
+fn delete_files(context: &mut AppContext, backend: &mut AppBackend) -> std::io::Result<()> {
let delete_func = if context.config_ref().use_trash {
trash_files
} else {
@@ -79,7 +79,7 @@ fn delete_files(context: &mut AppContext, backend: &mut TuiBackend) -> std::io::
};
match ch {
- Key::Char('y') | Key::Char('\n') => {
+ Key::Char('Y') | Key::Char('y') | Key::Char('\n') => {
let confirm_delete = if paths_len > 1 {
// prompt user again for deleting multiple files
let ch = {
@@ -112,7 +112,7 @@ fn delete_files(context: &mut AppContext, backend: &mut TuiBackend) -> std::io::
pub fn delete_selected_files(
context: &mut AppContext,
- backend: &mut TuiBackend,
+ backend: &mut AppBackend,
) -> std::io::Result<()> {
let _ = delete_files(context, backend)?;
diff --git a/src/commands/numbered_command.rs b/src/commands/numbered_command.rs
index c35205b..c1331da 100644
--- a/src/commands/numbered_command.rs
+++ b/src/commands/numbered_command.rs
@@ -8,12 +8,12 @@ use crate::event::process_event;
use crate::event::AppEvent;
use crate::key_command::{CommandKeybind, NumberedExecute};
use crate::ui::views::TuiView;
-use crate::ui::TuiBackend;
+use crate::ui::AppBackend;
pub fn numbered_command(
first_char: char,
context: &mut AppContext,
- backend: &mut TuiBackend,
+ backend: &mut AppBackend,
keymap: &AppKeyMapping,
) -> JoshutoResult {
context.flush_event();
diff --git a/src/commands/open_file.rs b/src/commands/open_file.rs
index a2b157e..ad90a91 100644
--- a/src/commands/open_file.rs
+++ b/src/commands/open_file.rs
@@ -6,14 +6,14 @@ use crate::config::AppMimetypeEntry;
use crate::context::AppContext;
use crate::error::{JoshutoError, JoshutoErrorKind, JoshutoResult};
use crate::ui::views::TuiTextField;
-use crate::ui::TuiBackend;
+use crate::ui::AppBackend;
use crate::util::process::{execute_and_wait, fork_execute};
use super::change_directory;
use crate::MIMETYPE_T;
-pub fn get_options<'a>(path: &path::Path) -> Vec<&'a AppMimetypeEntry> {
+fn _get_options<'a>(path: &path::Path) -> Vec<&'a AppMimetypeEntry> {
let mut options: Vec<&AppMimetypeEntry> = Vec::new();
if let Some(file_ext) = path.extension() {
if let Some(file_ext) = file_ext.to_str() {
@@ -24,47 +24,9 @@ pub fn get_options<'a>(path: &path::Path) -> Vec<&'a AppMimetypeEntry> {
options
}
-pub fn open(context: &mut AppContext, backend: &mut TuiBackend) -> JoshutoResult {
- let curr_list = context.tab_context_ref().curr_tab_ref().curr_list_ref();
- let entry = curr_list.and_then(|s| s.curr_entry_ref().cloned());
-
- match entry {
- None => (),
- Some(entry) if entry.file_path().is_dir() => {
- let path = entry.file_path().to_path_buf();
- change_directory::cd(path.as_path(), context)?;
- reload::soft_reload(context.tab_context_ref().index, context)?;
- }
- Some(entry) => {
- let paths = curr_list.map_or_else(Vec::new, |s| s.iter_selected().cloned().collect());
- let (path, files) = if paths.is_empty() {
- (entry.file_path(), vec![entry.file_name()])
- } else {
- (
- paths.get(0).unwrap().file_path(),
- paths.iter().map(|e| e.file_name()).collect(),
- )
- };
- let options = get_options(path);
- let option = options.iter().find(|option| option.program_exists());
-
- let config = context.config_ref();
-
- if let Some(option) = option {
- open_with_entry(context, backend, option, &files)?;
- } else if config.xdg_open {
- open_with_xdg(context, backend, path)?;
- } else {
- open_with_helper(context, backend, options, &files)?;
- }
- }
- }
- Ok(())
-}
-
-pub fn open_with_entry<S>(
+fn _open_with_entry<S>(
context: &mut AppContext,
- backend: &mut TuiBackend,
+ backend: &mut AppBackend,
option: &AppMimetypeEntry,
files: &[S],
) -> std::io::Result<()>
@@ -82,9 +44,9 @@ where
Ok(())
}
-pub fn open_with_xdg(
+fn _open_with_xdg(
context: &mut AppContext,
- backend: &mut TuiBackend,
+ backend: &mut AppBackend,
path: &path::Path,
) -> std::io::Result<()> {
let config = context.config_ref();
@@ -100,9 +62,9 @@ pub fn open_with_xdg(
Ok(())
}
-pub fn open_with_helper<S>(
+fn _open_with_helper<S>(
context: &mut AppContext,
- backend: &mut TuiBackend,
+ backend: &mut AppBackend,
options: Vec<&AppMimetypeEntry>,
files: &[S],
) -> std::io::Result<()>
@@ -139,7 +101,7 @@ where
}
Ok(n) => {
let option = &options[n];
- open_with_entry(context, backend, option, files)?;
+ _open_with_entry(context, backend, option, files)?;
}
Err(_) => {
let mut args_iter = user_input.split_whitespace();
@@ -159,34 +121,47 @@ where
Ok(())
}
-pub fn open_with_interactive(context: &mut AppContext, backend: &mut TuiBackend) -> JoshutoResult {
- let mut paths = context
- .tab_context_ref()
- .curr_tab_ref()
- .curr_list_ref()
- .map_or(vec![], |s| s.iter_selected().cloned().collect());
+pub fn open(context: &mut AppContext, backend: &mut AppBackend) -> JoshutoResult {
+ let curr_list = context.tab_context_ref().curr_tab_ref().curr_list_ref();
+ let entry = curr_list.and_then(|s| s.curr_entry_ref().cloned());
- if paths.is_empty() {
- paths.push(
- context
- .tab_context_ref()
- .curr_tab_ref()
- .curr_list_ref()
- .and_then(|s| s.curr_entry_ref())
- .unwrap()
- .clone(),
- );
- }
- let files: Vec<&str> = paths.iter().map(|e| e.file_name()).collect();
- let options = get_options(paths[0].file_path());
+ match entry {
+ None => (),
+ Some(entry) if entry.file_path().is_dir() => {
+ let path = entry.file_path().to_path_buf();
+ change_directory::cd(path.as_path(), context)?;
+ reload::soft_reload(context.tab_context_ref().index, context)?;
+ }
+ Some(entry) => {
+ let paths = curr_list.map_or_else(Vec::new, |s| s.iter_selected().cloned().collect());
+ let (path, files) = if paths.is_empty() {
+ (entry.file_path(), vec![entry.file_name()])
+ } else {
+ (
+ paths.get(0).unwrap().file_path(),
+ paths.iter().map(|e| e.file_name()).collect(),
+ )
+ };
+ let options = _get_options(path);
+ let option = options.iter().find(|option| option.program_exists());
+
+ let config = context.config_ref();
- open_with_helper(context, backend, options, &files)?;
+ if let Some(option) = option {
+ _open_with_entry(context, backend, option, &files)?;
+ } else if config.xdg_open {
+ _open_with_xdg(context, backend, path)?;
+ } else {
+ _open_with_helper(context, backend, options, &files)?;
+ }
+ }
+ }
Ok(())
}
pub fn open_with_index(
context: &mut AppContext,
- backend: &mut TuiBackend,
+ backend: &mut AppBackend,
index: usize,
) -> JoshutoResult {
let paths = context
@@ -202,7 +177,7 @@ pub fn open_with_index(
));
}
let files: Vec<&str> = paths.iter().map(|e| e.file_name()).collect();
- let options = get_options(paths[0].file_path());
+ let options = _get_options(paths[0].file_path());
if index >= options.len() {
return Err(JoshutoError::new(
@@ -212,6 +187,31 @@ pub fn open_with_index(
}
let option = &options[index];
- open_with_entry(context, backend, option, &files)?;
+ _open_with_entry(context, backend, option, &files)?;
+ Ok(())
+}
+
+pub fn open_with_interactive(context: &mut AppContext, backend: &mut AppBackend) -> JoshutoResult {
+ let mut paths = context
+ .tab_context_ref()
+ .curr_tab_ref()
+ .curr_list_ref()
+ .map_or(vec![], |s| s.iter_selected().cloned().collect());
+
+ if paths.is_empty() {
+ paths.push(
+ context
+ .tab_context_ref()
+ .curr_tab_ref()
+ .curr_list_ref()
+ .and_then(|s| s.curr_entry_ref())
+ .unwrap()
+ .clone(),
+ );
+ }
+ let files: Vec<&str> = paths.iter().map(|e| e.file_name()).collect();
+ let options = _get_options(paths[0].file_path());
+
+ _open_with_helper(context, backend, options, &files)?;
Ok(())
}
diff --git a/src/commands/rename_file.rs b/src/commands/rename_file.rs
index fa4a23d..cce7ab1 100644
--- a/src/commands/rename_file.rs
+++ b/src/commands/rename_file.rs
@@ -4,7 +4,7 @@ use crate::config::AppKeyMapping;
use crate::context::AppContext;
use crate::error::JoshutoResult;
use crate::history::create_dirlist_with_history;
-use crate::ui::TuiBackend;
+use crate::ui::AppBackend;
use super::command_line;
@@ -52,7 +52,7 @@ pub fn rename_file(context: &mut AppContext, dest: &path::Path) -> JoshutoResult
pub fn _rename_file_append(
context: &mut AppContext,
- backend: &mut TuiBackend,
+ backend: &mut AppBackend,
keymap_t: &AppKeyMapping,
file_name: &str,
) -> JoshutoResult {
@@ -68,7 +68,7 @@ pub fn _rename_file_append(
pub fn rename_file_append(
context: &mut AppContext,
- backend: &mut TuiBackend,
+ backend: &mut AppBackend,
keymap_t: &AppKeyMapping,
) -> JoshutoResult {
let mut file_name: Option<String> = None;
@@ -87,7 +87,7 @@ pub fn rename_file_append(
pub fn _rename_file_prepend(
context: &mut AppContext,
- backend: &mut TuiBackend,
+ backend: &mut AppBackend,
keymap_t: &AppKeyMapping,
file_name: String,
) -> JoshutoResult {
@@ -98,7 +98,7 @@ pub fn _rename_file_prepend(
pub fn rename_file_prepend(
context: &mut AppContext,
- backend: &mut TuiBackend,
+ backend: &mut AppBackend,
keymap_t: &AppKeyMapping,
) -> JoshutoResult {
let file_name = context
diff --git a/src/commands/search_fzf.rs b/src/commands/search_fzf.rs
index 0ae9fae..056fd10 100644
--- a/src/commands/search_fzf.rs
+++ b/src/commands/search_fzf.rs
@@ -5,9 +5,9 @@ use std::process::{Command, Stdio};
use crate::commands::cursor_move;
use crate::context::AppContext;
use crate::error::{JoshutoError, JoshutoErrorKind, JoshutoResult};
-use crate::ui::TuiBackend;
+use crate::ui::AppBackend;
-pub fn search_fzf(context: &mut AppContext, backend: &mut TuiBackend) -> JoshutoResult {
+pub fn search_fzf(context: &mut AppContext, backend: &mut AppBackend) -> JoshutoResult {
let items = context
.tab_context_ref()
.curr_tab_ref()
diff --git a/src/commands/set_mode.rs b/src/commands/set_mode.rs
index 2691483..d62d8a4 100644
--- a/src/commands/set_mode.rs
+++ b/src/commands/set_mode.rs
@@ -3,7 +3,7 @@ use std::fs;
use crate::context::AppContext;
use crate::error::JoshutoResult;
use crate::ui::views::TuiTextField;
-use crate::ui::TuiBackend;
+use crate::ui::AppBackend;
use crate::util::unix;
use super::cursor_move;
@@ -35,7 +35,7 @@ pub fn str_to_mode(s: &str) -> u32 {
mode
}
-pub fn set_mode(context: &mut AppContext, backend: &mut TuiBackend) -> JoshutoResult {
+pub fn set_mode(context: &mut AppContext, backend: &mut AppBackend) -> JoshutoResult {
#[cfg(unix)]
use std::os::unix::fs::PermissionsExt;
diff --git a/src/commands/show_help.rs b/src/commands/show_help.rs
index 739c63b..a8a7a4b 100644
--- a/src/commands/show_help.rs
+++ b/src/commands/show_help.rs
@@ -10,11 +10,11 @@ use crate::event::AppEvent;
use crate::key_command::{Command, CommandKeybind};
use crate::ui::widgets;
use crate::ui::widgets::TuiHelp;
-use crate::ui::TuiBackend;
+use crate::ui::AppBackend;
pub fn help_loop(
context: &mut AppContext,
- backend: &mut TuiBackend,
+ backend: &mut AppBackend,
keymap_t: &AppKeyMapping,
) -> JoshutoResult {
context.flush_event();
diff --git a/src/commands/show_tasks.rs b/src/commands/show_tasks.rs
index 4b22860..64312a1 100644
--- a/src/commands/show_tasks.rs
+++ b/src/commands/show_tasks.rs
@@ -5,12 +5,12 @@ use crate::event::process_event;
use crate::event::AppEvent;
use crate::key_command::{Command, CommandKeybind};
use crate::ui::views::TuiWorkerView;
-use crate::ui::TuiBackend;
+use crate::ui::AppBackend;
use crate::util::to_string::ToString;
pub fn show_tasks(
context: &mut AppContext,
- backend: &mut TuiBackend,
+ backend: &mut AppBackend,
keymap_t: &AppKeyMapping,
) -> JoshutoResult {
context.flush_event();
diff --git a/src/commands/sub_process.rs b/src/commands/sub_process.rs
index e3e2e5e..e2a33dc 100644
--- a/src/commands/sub_process.rs
+++ b/src/commands/sub_process.rs
@@ -1,6 +1,6 @@
use crate::context::AppContext;
use crate::error::JoshutoResult;
-use crate::ui::TuiBackend;
+use crate::ui::AppBackend;
use std::process::{Command, Stdio};
use super::reload;
@@ -49,7 +49,7 @@ fn execute_sub_process(
/// Handler for Joshuto's `shell` and `spawn` commands.
pub fn sub_process(
context: &mut AppContext,
- backend: &mut TuiBackend,
+ backend: &mut AppBackend,
words: &[String],
spawn: bool,
) -> JoshutoResult {
diff --git a/src/commands/subdir_fzf.rs b/src/commands/subdir_fzf.rs
index d1adc07..0944915 100644
--- a/src/commands/subdir_fzf.rs
+++ b/src/commands/subdir_fzf.rs
@@ -5,11 +5,11 @@ use std::process::{Command, Stdio};
use crate::context::AppContext;
use crate::error::JoshutoResult;
-use crate::ui::TuiBackend;
+use crate::ui::AppBackend;
use super::change_directory::change_directory;
-pub fn subdir_fzf(context: &mut AppContext, backend: &mut TuiBackend) -> JoshutoResult {
+pub fn subdir_fzf(context: &mut AppContext, backend: &mut AppBackend) -> JoshutoResult {
let fzf_default_command = std::env::var("FZF_DEFAULT_COMMAND")?;
backend.terminal_drop();
diff --git a/src/commands/zoxide.rs b/src/commands/zoxide.rs
index 9ee1bf6..0725618 100644
--- a/src/commands/zoxide.rs
+++ b/src/commands/zoxide.rs
@@ -5,7 +5,7 @@ use std::process::{Command, Stdio};
use crate::commands::change_directory;
use crate::context::AppContext;
use crate::error::JoshutoResult;
-use crate::ui::TuiBackend;
+use crate::ui::AppBackend;
pub fn zoxide_query(context: &mut AppContext, args: &str) -> JoshutoResult {
let cwd = std::env::current_dir()?;
@@ -39,7 +39,7 @@ pub fn zoxide_query(context: &mut AppContext, args: &str) -> JoshutoResult {
pub fn zoxide_query_interactive(
context: &mut AppContext,
- backend: &mut TuiBackend,
+ backend: &mut AppBackend,
) -> JoshutoResult {
backend.terminal_drop();
diff --git a/src/event/process_event.rs b/src/event/process_event.rs
index aa4cb24..bf587a3 100644
--- a/src/event/process_event.rs
+++ b/src/event/process_event.rs
@@ -19,7 +19,7 @@ use crate::ui::views::TuiCommandMenu;
use crate::util::format;
pub fn get_input_while_composite<'a>(
- backend: &mut ui::TuiBackend,
+ backend: &mut ui::AppBackend,
context: &mut AppContext,
keymap: &'a KeyMapping,
) -> Option<&'a Command> {
@@ -151,7 +151,7 @@ pub fn process_file_preview(
pub fn process_unsupported(
context: &mut AppContext,
- backend: &mut ui::TuiBackend,
+ backend: &mut ui::AppBackend,
keymap_t: &AppKeyMapping,
event: Vec<u8>,
) {
@@ -175,7 +175,7 @@ pub fn process_unsupported(
pub fn process_mouse(
event: MouseEvent,
context: &mut AppContext,
- backend: &mut ui::TuiBackend,
+ backend: &mut ui::AppBackend,
keymap_t: &AppKeyMapping,
) {
let f_size = backend.terminal.as_ref().unwrap().size().unwrap();
diff --git a/src/key_command/impl_appexecute.rs b/src/key_command/impl_appexecute.rs
index 3f88f4b..4febf1e 100644
--- a/src/key_command/impl_appexecute.rs
+++ b/src/key_command/impl_appexecute.rs
@@ -2,7 +2,7 @@ use crate::commands::*;
use crate::config::AppKeyMapping;
use crate::context::AppContext;
use crate::error::JoshutoResult;
-use crate::ui::TuiBackend;
+use crate::ui::AppBackend;
use super::{AppExecute, Command};
@@ -10,7 +10,7 @@ impl AppExecute for Command {
fn execute(
&self,
context: &mut AppContext,
- backend: &mut TuiBackend,
+ backend: &mut AppBackend,
keymap_t: &AppKeyMapping,
) -> JoshutoResult {
match &*self {
diff --git a/src/key_command/impl_numbered.rs b/src/key_command/impl_numbered.rs
index 2a0007c..d1f05f0 100644
--- a/src/key_command/impl_numbered.rs
+++ b/src/key_command/impl_numbered.rs
@@ -2,7 +2,7 @@ use crate::commands::*;
use crate::config::AppKeyMapping;
use crate::context::AppContext;
use crate::error::{JoshutoError, JoshutoErrorKind, JoshutoResult};
-use crate::ui::TuiBackend;
+use crate::ui::AppBackend;
use super::{Command, NumberedExecute};
@@ -15,7 +15,7 @@ impl NumberedExecute for Command {
&self,
number_prefix: usize,
context: &mut AppContext,
- backend: &mut TuiBackend,
+ backend: &mut AppBackend,
keymap_t: &AppKeyMapping,
) -> JoshutoResult {
match self {
diff --git a/src/key_command/traits.rs b/src/key_command/traits.rs
index 08f6c0d..647ad3c 100644
--- a/src/key_command/traits.rs
+++ b/src/key_command/traits.rs
@@ -1,13 +1,13 @@
use crate::config::AppKeyMapping;
use crate::context::AppContext;
use crate::error::JoshutoResult;
-use crate::ui::TuiBackend;
+use crate::ui::AppBackend;
pub trait AppExecute {
fn execute(
&self,
context: &mut AppContext,
- backend: &mut TuiBackend,
+ backend: &mut AppBackend,
keymap_t: &AppKeyMapping,
) -> JoshutoResult;
}
@@ -17,7 +17,7 @@ pub trait NumberedExecute {
&self,
number_prefix: usize,
context: &mut AppContext,
- backend: &mut TuiBackend,
+ backend: &mut AppBackend,
keymap_t: &AppKeyMapping,
) -> JoshutoResult;
}
diff --git a/src/main.rs b/src/main.rs
index d809b58..f7795a6 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -103,7 +103,7 @@ fn run_joshuto(args: Args) -> Result<i32, JoshutoError> {
let mut context = AppContext::new(config, args.clone());
{
- let mut backend: ui::TuiBackend = ui::TuiBackend::new()?;
+ let mut backend: ui::AppBackend = ui::AppBackend::new()?;
run(&mut backend, &mut context, keymap)?;
}
run_quit(&args, &context)?;
diff --git a/src/run.rs b/src/run.rs
index 145e6bc..7ecd694 100644
--- a/src/run.rs
+++ b/src/run.rs
@@ -16,11 +16,17 @@ use termion::event::{Event, Key};
use tui::layout::Rect;
pub fn run(
- backend: &mut ui::TuiBackend,
+ backend: &mut ui::AppBackend,
context: &mut AppContext,
keymap_t: AppKeyMapping,
) -> std::io::Result<()> {
let curr_path = std::env::current_dir()?;
+
+ if let Ok(area) = backend.terminal_ref().size() {
+ // pre-calculate some ui attributes
+ calculate_ui_context(context, area);
+ }
+
{
// Initialize an initial tab
let tab = JoshutoTab::new(
diff --git a/src/ui/tui_backend.rs b/src/ui/backend.rs
index c88590b..8180072 100644
--- a/src/ui/tui_backend.rs
+++ b/src/ui/backend.rs
@@ -1,5 +1,4 @@
-use std::io::stdout;
-use std::io::Write;
+use std::io::{self, stdout, Write};
use termion::raw::{IntoRawMode, RawTerminal};
use termion::screen::AlternateScreen;
@@ -29,21 +28,22 @@ impl New for Screen {
type Screen = AlternateScreen<RawTerminal<std::io::Stdout>>;
#[cfg(not(feature = "mouse"))]
impl New for Screen {
- fn new() -> std::io::Result<Self> {
+ fn new() -> io::Result<Self> {
let stdout = std::io::stdout().into_raw_mode()?;
let alt_screen = AlternateScreen::from(stdout);
Ok(alt_screen)
}
}
-pub type JoshutoTerminal = tui::Terminal<TermionBackend<Screen>>;
+// pub type TuiBackend = TermionBackend<Screen>;
+pub type TuiTerminal = tui::Terminal<TermionBackend<Screen>>;
-pub struct TuiBackend {
- pub terminal: Option<JoshutoTerminal>,
+pub struct AppBackend {
+ pub terminal: Option<TuiTerminal>,
}
-impl TuiBackend {
- pub fn new() -> std::io::Result<Self> {
+impl AppBackend {
+ pub fn new() -> io::Result<Self> {
let mut alt_screen = Screen::new()?;
// clears the screen of artifacts
write!(alt_screen, "{}", termion::clear::All)?;
@@ -66,11 +66,11 @@ impl TuiBackend {
});
}
- pub fn terminal_ref(&self) -> &JoshutoTerminal {
+ pub fn terminal_ref(&self) -> &TuiTerminal {
self.terminal.as_ref().unwrap()
}
- pub fn terminal_mut(&mut self) -> &mut JoshutoTerminal {
+ pub fn terminal_mut(&mut self) -> &mut TuiTerminal {
self.terminal.as_mut().unwrap()
}
@@ -79,8 +79,8 @@ impl TuiBackend {
let _ = stdout().flush();
}
- pub fn terminal_restore(&mut self) -> std::io::Result<()> {
- let mut new_backend = TuiBackend::new()?;
+ pub fn terminal_restore(&mut self) -> io::Result<()> {
+ let mut new_backend = Self::new()?;
std::mem::swap(&mut self.terminal, &mut new_backend.terminal);
Ok(())
}
diff --git a/src/ui/mod.rs b/src/ui/mod.rs
index 2b19584..709e9a4 100644
--- a/src/ui/mod.rs
+++ b/src/ui/mod.rs
@@ -1,10 +1,10 @@
+mod backend;
mod preview_area;
mod rect;
-mod tui_backend;
pub mod views;
pub mod widgets;
+pub use backend::*;
pub use preview_area::*;
pub use rect::*;
-pub use tui_backend::*;
diff --git a/src/ui/views/tui_folder_view.rs b/src/ui/views/tui_folder_view.rs
index 986612f..d84dde1 100644
--- a/src/ui/views/tui_folder_view.rs
+++ b/