Skip to content

Commit

Permalink
Merge pull request #572 from flipsi/set-display-mode-command
Browse files Browse the repository at this point in the history
Set display mode command
  • Loading branch information
kamiyaa authored Nov 3, 2024
2 parents d5a25d3 + 6c08464 commit dfeabbb
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub mod select_fzf;
pub mod select_glob;
pub mod select_regex;
pub mod select_string;
pub mod set_display_mode;
pub mod set_mode;
pub mod show_help;
pub mod show_hidden;
Expand Down
11 changes: 11 additions & 0 deletions src/commands/set_display_mode.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use crate::error::AppResult;
use crate::types::option::display::DisplayMode;
use crate::types::state::AppState;

use super::reload;

pub fn set_display_mode(app_state: &mut AppState, mode: DisplayMode) -> AppResult {
app_state.config.display_options.mode = mode;
reload::soft_reload_curr_tab(app_state)?;
Ok(())
}
1 change: 1 addition & 0 deletions src/constants/command_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ cmd_constants![
(CMD_TOGGLE_HIDDEN, "toggle_hidden"),
(CMD_TOGGLE_VISUAL, "toggle_visual"),
(CMD_SWITCH_LINE_NUMBERS, "line_nums"),
(CMD_SET_DISPLAY_MODE, "set_display_mode"),
(CMD_SET_LINEMODE, "linemode"),
(CMD_TOUCH_FILE, "touch"),
(CMD_HELP, "help"),
Expand Down
1 change: 1 addition & 0 deletions src/types/command/impl_appcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ impl AppCommand for Command {
} => CMD_SUBPROCESS_CAPTURE,
Self::StdOutPostProcess { .. } => CMD_STDOUT_POST_PROCESS,
Self::SwitchLineNums(_) => CMD_SWITCH_LINE_NUMBERS,
Self::SetDisplayMode(_) => CMD_SET_DISPLAY_MODE,
Self::SetLineMode(_) => CMD_SET_LINEMODE,

Self::SignalSuspend => CMD_SIGNAL_SUSPEND,
Expand Down
1 change: 1 addition & 0 deletions src/types/command/impl_appexecute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ impl AppExecute for Command {
sort_method,
reverse,
} => sort::set_sort(app_state, *sort_method, *reverse),
Self::SetDisplayMode(mode) => set_display_mode::set_display_mode(app_state, *mode),
Self::SetLineMode(mode) => linemode::set_linemode(app_state, *mode),
Self::SortReverse => sort::toggle_reverse(app_state),
Self::SignalSuspend => signal::signal_suspend(backend),
Expand Down
1 change: 1 addition & 0 deletions src/types/command/impl_comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ impl CommandComment for Command {
// These comments are displayed at the help page
fn comment(&self) -> &'static str {
match self {
Self::SetDisplayMode(_) => "Change the display mode",
Self::SetLineMode(_) => "Show File's metadata in line",
Self::Escape => "Escape from visual mode (cancel)",
Self::BulkRename => "Bulk rename",
Expand Down
3 changes: 3 additions & 0 deletions src/types/command/impl_completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ impl CommandCompletion for Command {
"insensitive",
"sensitive",
]),
CMD_SET_DISPLAY_MODE => CompletionKind::Custom(vec![
"default", "minimal", "hsplit",
]),
CMD_SET_LINEMODE => CompletionKind::Custom(vec![
"all", "group", "mtime", "none", "perm", "size", "user",
]),
Expand Down
11 changes: 11 additions & 0 deletions src/types/command/impl_from_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::commands::sub_process::SubprocessCallMode;
use crate::error::{AppError, AppErrorKind};
use crate::tab::NewTabMode;
use crate::types::io::FileOperationOptions;
use crate::types::option::display::DisplayMode;
use crate::types::option::line_mode::{LineMode, LineNumberStyle};
use crate::types::option::search::CaseSensitivity;
use crate::types::option::sort::SortMethod;
Expand Down Expand Up @@ -551,6 +552,16 @@ impl std::str::FromStr for Command {
}
}
}
} else if command == CMD_SET_DISPLAY_MODE {
match arg {
"default" => Ok(Self::SetDisplayMode(DisplayMode::Default)),
"minimal" => Ok(Self::SetDisplayMode(DisplayMode::Minimal)),
"hsplit" => Ok(Self::SetDisplayMode(DisplayMode::HSplit)),
_ => Err(AppError::new(
AppErrorKind::InvalidParameters,
format!("{}: Unknown option '{}'", command, arg),
))
}
} else if command == CMD_SET_LINEMODE {
Ok(Self::SetLineMode(LineMode::from_string(arg)?))
} else if command == CMD_TAB_SWITCH {
Expand Down
2 changes: 2 additions & 0 deletions src/types/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::commands::stdout::PostProcessor;
use crate::commands::sub_process::SubprocessCallMode;
use crate::tab::NewTabMode;
use crate::types::io::FileOperationOptions;
use crate::types::option::display::DisplayMode;
use crate::types::option::line_mode::{LineMode, LineNumberStyle};
use crate::types::option::search::CaseSensitivity;
use crate::types::option::sort::SortMethod;
Expand Down Expand Up @@ -73,6 +74,7 @@ pub enum Command {
CursorMovePageMiddle,
CursorMovePageEnd,

SetDisplayMode(DisplayMode),
SetLineMode(LineMode),

ParentCursorMoveUp {
Expand Down

0 comments on commit dfeabbb

Please sign in to comment.