summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMroik/PositiveC <mroik@delayed.space>2024-02-21 16:43:09 +0100
committerGitHub <noreply@github.com>2024-02-21 10:43:09 -0500
commitf6d1f71d6c11eaebc13ef9f26b06bd31e2275d51 (patch)
treef7e45da920d6aac4ddce09273a23203e1a8dc4a1
parent8f1c36ae882bed585320292c0942b59bdf4d86a9 (diff)
Make mouse support configurable (#494)
* Make mouse sup configurable instead of build feat * Add mouse_support to docs * Add mouse_support to default config * Don't capture mouse on mouse_support = false * Fmt pass
-rw-r--r--Cargo.toml3
-rw-r--r--config/joshuto.toml1
-rw-r--r--docs/configuration/joshuto.toml.md2
-rw-r--r--src/commands/bulk_rename.rs2
-rw-r--r--src/commands/custom_search.rs2
-rw-r--r--src/commands/fzf.rs15
-rw-r--r--src/commands/open_file.rs6
-rw-r--r--src/commands/sub_process.rs2
-rw-r--r--src/commands/zoxide.rs2
-rw-r--r--src/config/clean/app/config.rs2
-rw-r--r--src/config/raw/app/config.rs2
-rw-r--r--src/main.rs2
-rw-r--r--src/ui/backend.rs51
13 files changed, 58 insertions, 34 deletions
diff --git a/Cargo.toml b/Cargo.toml
index bbacca9..4c5eb76 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -66,6 +66,5 @@ shadow-rs = "0.26"
[features]
devicons = ["phf"]
file_mimetype = []
-mouse = []
syntax_highlight = ["ansi-to-tui"]
-default = ["devicons", "mouse", "syntax_highlight"]
+default = ["devicons", "syntax_highlight"]
diff --git a/config/joshuto.toml b/config/joshuto.toml
index 4ab9cbc..d23da09 100644
--- a/config/joshuto.toml
+++ b/config/joshuto.toml
@@ -1,5 +1,6 @@
numbered_command = false
+mouse_support = true
focus_on_create = true
use_trash = true
watch_files = true
diff --git a/docs/configuration/joshuto.toml.md b/docs/configuration/joshuto.toml.md
index 7c90fc2..acec5bf 100644
--- a/docs/configuration/joshuto.toml.md
+++ b/docs/configuration/joshuto.toml.md
@@ -5,6 +5,8 @@ This file is for general configurations.
All options available and their default values:
```toml
+# Enables mouse support (true by default)
+mouse_support = true
# This is for configuring how many items to reach before 'scrolling' the view
scroll_offset = 6
diff --git a/src/commands/bulk_rename.rs b/src/commands/bulk_rename.rs
index f7009ae..9cc7f26 100644
--- a/src/commands/bulk_rename.rs
+++ b/src/commands/bulk_rename.rs
@@ -128,7 +128,7 @@ pub fn bulk_rename(context: &mut AppContext, backend: &mut AppBackend) -> AppRes
context.remove_external_preview();
backend.terminal_drop();
let res = _bulk_rename(context);
- backend.terminal_restore()?;
+ backend.terminal_restore(context.config_ref().mouse_support)?;
reload::soft_reload_curr_tab(context)?;
res
}
diff --git a/src/commands/custom_search.rs b/src/commands/custom_search.rs
index 422143e..a9d4405 100644
--- a/src/commands/custom_search.rs
+++ b/src/commands/custom_search.rs
@@ -57,7 +57,7 @@ pub fn custom_search(
.stdout(Stdio::piped())
.spawn()?
.wait_with_output()?;
- backend.terminal_restore()?;
+ backend.terminal_restore(context.config_ref().mouse_support)?;
cmd_result
} else {
cmd.output()?
diff --git a/src/commands/fzf.rs b/src/commands/fzf.rs
index 8aeaa1b..9c60c54 100644
--- a/src/commands/fzf.rs
+++ b/src/commands/fzf.rs
@@ -25,7 +25,7 @@ pub fn fzf(
CaseSensitivity::Smart => {}
}
- fzf_impl(backend, items, args)
+ fzf_impl(context, backend, items, args)
}
pub fn fzf_multi(
@@ -47,10 +47,15 @@ pub fn fzf_multi(
}
args.push("-m".to_owned());
- fzf_impl(backend, items, args)
+ fzf_impl(context, backend, items, args)
}
-fn fzf_impl(backend: &mut AppBackend, items: Vec<String>, args: Vec<String>) -> AppResult<String> {
+fn fzf_impl(
+ context: &mut AppContext,
+ backend: &mut AppBackend,
+ items: Vec<String>,
+ args: Vec<String>,
+) -> AppResult<String> {
backend.terminal_drop();
let mut cmd = Command::new("fzf");
@@ -63,7 +68,7 @@ fn fzf_impl(backend: &mut AppBackend, items: Vec<String>, args: Vec<String>) ->
let mut fzf = match cmd.spawn() {
Ok(child) => child,
Err(e) => {
- backend.terminal_restore()?;
+ backend.terminal_restore(context.config_ref().mouse_support)?;
return Err(AppError::from(e));
}
};
@@ -77,7 +82,7 @@ fn fzf_impl(backend: &mut AppBackend, items: Vec<String>, args: Vec<String>) ->
}
let fzf_output = fzf.wait_with_output();
- backend.terminal_restore()?;
+ backend.terminal_restore(context.config_ref().mouse_support)?;
if let Ok(output) = fzf_output {
if output.status.success() {
diff --git a/src/commands/open_file.rs b/src/commands/open_file.rs
index 0d248e9..d206f35 100644
--- a/src/commands/open_file.rs
+++ b/src/commands/open_file.rs
@@ -60,7 +60,7 @@ where
} else {
backend.terminal_drop();
let res = execute_and_wait(option, files);
- backend.terminal_restore()?;
+ backend.terminal_restore(context.config_ref().mouse_support)?;
res?;
}
Ok(())
@@ -79,7 +79,7 @@ fn _open_with_xdg(
backend.terminal_drop();
let handle = open::that_in_background(path);
let result = handle.join();
- backend.terminal_restore()?;
+ backend.terminal_restore(context.config_ref().mouse_support)?;
if let Ok(result) = result {
result?;
}
@@ -136,7 +136,7 @@ where
let mut option = ProgramEntry::new(String::from(cmd));
option.args(args_iter);
let res = execute_and_wait(&option, files);
- backend.terminal_restore()?;
+ backend.terminal_restore(context.config_ref().mouse_support)?;
res?
}
}
diff --git a/src/commands/sub_process.rs b/src/commands/sub_process.rs
index 437112e..58bfdc1 100644
--- a/src/commands/sub_process.rs
+++ b/src/commands/sub_process.rs
@@ -81,7 +81,7 @@ pub fn sub_process(
) -> AppResult {
backend.terminal_drop();
let res = execute_sub_process(context, words, spawn);
- backend.terminal_restore()?;
+ backend.terminal_restore(context.config_ref().mouse_support)?;
let _ = reload::soft_reload_curr_tab(context);
context.message_queue_mut().push_info(format!(
"{}: {}",
diff --git a/src/commands/zoxide.rs b/src/commands/zoxide.rs
index 222bb9d..a065117 100644
--- a/src/commands/zoxide.rs
+++ b/src/commands/zoxide.rs
@@ -49,7 +49,7 @@ pub fn zoxide_query_interactive(context: &mut AppContext, backend: &mut AppBacke
.spawn()?;
let zoxide_output = zoxide_process.wait_with_output()?;
- backend.terminal_restore()?;
+ backend.terminal_restore(context.config_ref().mouse_support)?;
if zoxide_output.status.success() {
if let Ok(zoxide_str) = std::str::from_utf8(&zoxide_output.stdout) {
diff --git a/src/config/clean/app/config.rs b/src/config/clean/app/config.rs
index 60b088d..ee3a24b 100644
--- a/src/config/clean/app/config.rs
+++ b/src/config/clean/app/config.rs
@@ -21,6 +21,7 @@ pub struct AppConfig {
pub watch_files: bool,
pub custom_commands: Vec<CustomCommand>,
pub focus_on_create: bool,
+ pub mouse_support: bool,
pub cmd_aliases: HashMap<String, String>,
pub _display_options: DisplayOption,
pub _preview_options: PreviewOption,
@@ -86,6 +87,7 @@ impl From<AppConfigRaw> for AppConfig {
watch_files: raw.watch_files,
cmd_aliases: raw.cmd_aliases,
focus_on_create: raw.focus_on_create,
+ mouse_support: raw.mouse_support,
_display_options: DisplayOption::from(raw.display_options),
_preview_options: PreviewOption::from(raw.preview_options),
_search_options: SearchOption::from(raw.search_options),
diff --git a/src/config/raw/app/config.rs b/src/config/raw/app/config.rs
index cf2b758..4ded404 100644
--- a/src/config/raw/app/config.rs
+++ b/src/config/raw/app/config.rs
@@ -34,6 +34,8 @@ pub struct AppConfigRaw {
pub watch_files: bool,
#[serde(default = "default_true")]
pub focus_on_create: bool,
+ #[serde(default = "default_true")]
+ pub mouse_support: bool,
#[serde(default)]
pub cmd_aliases: HashMap<String, String>,
#[serde(default, rename = "display")]
diff --git a/src/main.rs b/src/main.rs
index 7a5d44d..02ea567 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -169,7 +169,7 @@ fn run_main(args: Args) -> Result<i32, AppError> {
let mut context = AppContext::new(config, args.clone());
{
- let mut backend: ui::AppBackend = ui::AppBackend::new()?;
+ let mut backend: ui::AppBackend = ui::AppBackend::new(context.config_ref().mouse_support)?;
run::run_loop(&mut backend, &mut context, keymap)?;
}
run_quit(&args, &context)?;
diff --git a/src/ui/backend.rs b/src/ui/backend.rs
index b5b9833..4b5b124 100644
--- a/src/ui/backend.rs
+++ b/src/ui/backend.rs
@@ -6,7 +6,6 @@ use termion::raw::{IntoRawMode, RawTerminal};
use termion::screen::AlternateScreen;
use termion::screen::IntoAlternateScreen;
-#[cfg(feature = "mouse")]
use termion::input::MouseTerminal;
trait New {
@@ -15,24 +14,38 @@ trait New {
Self: Sized;
}
-#[cfg(feature = "mouse")]
-type Screen = MouseTerminal<AlternateScreen<RawTerminal<std::io::Stdout>>>;
-#[cfg(feature = "mouse")]
-impl New for Screen {
+pub enum Screen {
+ WithMouse(MouseTerminal<AlternateScreen<RawTerminal<std::io::Stdout>>>),
+ WithoutMouse(AlternateScreen<RawTerminal<std::io::Stdout>>),
+}
+
+impl Screen {
// Returns alternate screen
- fn new() -> io::Result<Self> {
+ fn new(mouse_support: bool) -> io::Result<Self> {
let stdout = io::stdout().into_raw_mode()?;
- Ok(MouseTerminal::from(stdout.into_alternate_screen().unwrap()))
+ if mouse_support {
+ Ok(Self::WithMouse(MouseTerminal::from(
+ stdout.into_alternate_screen().unwrap(),
+ )))
+ } else {
+ Ok(Self::WithoutMouse(stdout.into_alternate_screen().unwrap()))
+ }
}
}
-#[cfg(not(feature = "mouse"))]
-type Screen = AlternateScreen<RawTerminal<std::io::Stdout>>;
-#[cfg(not(feature = "mouse"))]
-impl New for Screen {
- // Returns alternate screen
- fn new() -> io::Result<Self> {
- let stdout = std::io::stdout().into_raw_mode()?;
- Ok(stdout.into_alternate_screen().unwrap())
+
+impl Write for Screen {
+ fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
+ match self {
+ Screen::WithMouse(t) => t.write(buf),
+ Screen::WithoutMouse(t) => t.write(buf),
+ }
+ }
+
+ fn flush(&mut self) -> io::Result<()> {
+ match self {
+ Screen::WithMouse(t) => t.flush(),
+ Screen::WithoutMouse(t) => t.flush(),
+ }
}
}
@@ -44,8 +57,8 @@ pub struct AppBackend {
}
impl AppBackend {
- pub fn new() -> io::Result<Self> {
- let mut alt_screen = Screen::new()?;
+ pub fn new(mouse_support: bool) -> io::Result<Self> {
+ let mut alt_screen = Screen::new(mouse_support)?;
// clears the screen of artifacts
write!(alt_screen, "{}", termion::clear::All)?;
@@ -80,8 +93,8 @@ impl AppBackend {
let _ = stdout().flush();
}
- pub fn terminal_restore(&mut self) -> io::Result<()> {
- let mut new_backend = Self::new()?;
+ pub fn terminal_restore(&mut self, mouse_support: bool) -> io::Result<()> {
+ let mut new_backend = Self::new(mouse_support)?;
std::mem::swap(&mut self.terminal, &mut new_backend.terminal);
Ok(())
}