Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make mouse support configurable #494

Merged
merged 5 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,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"]
1 change: 1 addition & 0 deletions config/joshuto.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
numbered_command = false

mouse_support = true
focus_on_create = true
use_trash = true
watch_files = true
Expand Down
2 changes: 2 additions & 0 deletions docs/configuration/joshuto.toml.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions src/config/clean/app/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions src/config/raw/app/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
4 changes: 4 additions & 0 deletions src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ fn process_input(
// handle the event
match event {
AppEvent::Termion(Event::Mouse(event)) => {
if !context.config_ref().mouse_support {
context.flush_event();
return;
}
process_event::process_mouse(event, context, backend, keymap_t);
preview_default::load_preview(context, backend);
}
Expand Down
13 changes: 0 additions & 13 deletions src/ui/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -15,26 +14,14 @@ trait New {
Self: Sized;
}

#[cfg(feature = "mouse")]
type Screen = MouseTerminal<AlternateScreen<RawTerminal<std::io::Stdout>>>;
#[cfg(feature = "mouse")]
impl New for Screen {
// Returns alternate screen
fn new() -> io::Result<Self> {
let stdout = io::stdout().into_raw_mode()?;
Ok(MouseTerminal::from(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())
}
}

// pub type TuiBackend = TermionBackend<Screen>;
pub type TuiTerminal = ratatui::Terminal<TermionBackend<Screen>>;
Expand Down
Loading