Skip to content

Commit dfeabbb

Browse files
authored
Merge pull request #572 from flipsi/set-display-mode-command
Set display mode command
2 parents d5a25d3 + 6c08464 commit dfeabbb

File tree

9 files changed

+32
-0
lines changed

9 files changed

+32
-0
lines changed

src/commands/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub mod select_fzf;
3434
pub mod select_glob;
3535
pub mod select_regex;
3636
pub mod select_string;
37+
pub mod set_display_mode;
3738
pub mod set_mode;
3839
pub mod show_help;
3940
pub mod show_hidden;

src/commands/set_display_mode.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
use crate::error::AppResult;
2+
use crate::types::option::display::DisplayMode;
3+
use crate::types::state::AppState;
4+
5+
use super::reload;
6+
7+
pub fn set_display_mode(app_state: &mut AppState, mode: DisplayMode) -> AppResult {
8+
app_state.config.display_options.mode = mode;
9+
reload::soft_reload_curr_tab(app_state)?;
10+
Ok(())
11+
}

src/constants/command_name.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ cmd_constants![
7979
(CMD_TOGGLE_HIDDEN, "toggle_hidden"),
8080
(CMD_TOGGLE_VISUAL, "toggle_visual"),
8181
(CMD_SWITCH_LINE_NUMBERS, "line_nums"),
82+
(CMD_SET_DISPLAY_MODE, "set_display_mode"),
8283
(CMD_SET_LINEMODE, "linemode"),
8384
(CMD_TOUCH_FILE, "touch"),
8485
(CMD_HELP, "help"),

src/types/command/impl_appcommand.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ impl AppCommand for Command {
102102
} => CMD_SUBPROCESS_CAPTURE,
103103
Self::StdOutPostProcess { .. } => CMD_STDOUT_POST_PROCESS,
104104
Self::SwitchLineNums(_) => CMD_SWITCH_LINE_NUMBERS,
105+
Self::SetDisplayMode(_) => CMD_SET_DISPLAY_MODE,
105106
Self::SetLineMode(_) => CMD_SET_LINEMODE,
106107

107108
Self::SignalSuspend => CMD_SIGNAL_SUSPEND,

src/types/command/impl_appexecute.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ impl AppExecute for Command {
150150
sort_method,
151151
reverse,
152152
} => sort::set_sort(app_state, *sort_method, *reverse),
153+
Self::SetDisplayMode(mode) => set_display_mode::set_display_mode(app_state, *mode),
153154
Self::SetLineMode(mode) => linemode::set_linemode(app_state, *mode),
154155
Self::SortReverse => sort::toggle_reverse(app_state),
155156
Self::SignalSuspend => signal::signal_suspend(backend),

src/types/command/impl_comment.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ impl CommandComment for Command {
99
// These comments are displayed at the help page
1010
fn comment(&self) -> &'static str {
1111
match self {
12+
Self::SetDisplayMode(_) => "Change the display mode",
1213
Self::SetLineMode(_) => "Show File's metadata in line",
1314
Self::Escape => "Escape from visual mode (cancel)",
1415
Self::BulkRename => "Bulk rename",

src/types/command/impl_completion.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ impl CommandCompletion for Command {
4545
"insensitive",
4646
"sensitive",
4747
]),
48+
CMD_SET_DISPLAY_MODE => CompletionKind::Custom(vec![
49+
"default", "minimal", "hsplit",
50+
]),
4851
CMD_SET_LINEMODE => CompletionKind::Custom(vec![
4952
"all", "group", "mtime", "none", "perm", "size", "user",
5053
]),

src/types/command/impl_from_str.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::commands::sub_process::SubprocessCallMode;
88
use crate::error::{AppError, AppErrorKind};
99
use crate::tab::NewTabMode;
1010
use crate::types::io::FileOperationOptions;
11+
use crate::types::option::display::DisplayMode;
1112
use crate::types::option::line_mode::{LineMode, LineNumberStyle};
1213
use crate::types::option::search::CaseSensitivity;
1314
use crate::types::option::sort::SortMethod;
@@ -551,6 +552,16 @@ impl std::str::FromStr for Command {
551552
}
552553
}
553554
}
555+
} else if command == CMD_SET_DISPLAY_MODE {
556+
match arg {
557+
"default" => Ok(Self::SetDisplayMode(DisplayMode::Default)),
558+
"minimal" => Ok(Self::SetDisplayMode(DisplayMode::Minimal)),
559+
"hsplit" => Ok(Self::SetDisplayMode(DisplayMode::HSplit)),
560+
_ => Err(AppError::new(
561+
AppErrorKind::InvalidParameters,
562+
format!("{}: Unknown option '{}'", command, arg),
563+
))
564+
}
554565
} else if command == CMD_SET_LINEMODE {
555566
Ok(Self::SetLineMode(LineMode::from_string(arg)?))
556567
} else if command == CMD_TAB_SWITCH {

src/types/command/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use crate::commands::stdout::PostProcessor;
1616
use crate::commands::sub_process::SubprocessCallMode;
1717
use crate::tab::NewTabMode;
1818
use crate::types::io::FileOperationOptions;
19+
use crate::types::option::display::DisplayMode;
1920
use crate::types::option::line_mode::{LineMode, LineNumberStyle};
2021
use crate::types::option::search::CaseSensitivity;
2122
use crate::types::option::sort::SortMethod;
@@ -73,6 +74,7 @@ pub enum Command {
7374
CursorMovePageMiddle,
7475
CursorMovePageEnd,
7576

77+
SetDisplayMode(DisplayMode),
7678
SetLineMode(LineMode),
7779

7880
ParentCursorMoveUp {

0 commit comments

Comments
 (0)