diff --git a/docs/en/src/messages.md b/docs/en/src/messages.md index 7c0dca6..54fc18d 100644 --- a/docs/en/src/messages.md +++ b/docs/en/src/messages.md @@ -208,8 +208,6 @@ Example: #### FocusByFileName -**YAML:** `FocusByFileName: string` - Focus on the file by name from the present working directory. Type: { FocusByFileName = "string" } @@ -219,6 +217,42 @@ Example: - Lua: `{ FocusByFileName = "filename.ext" }` - YAML: `FocusByFileName: filename.ext` +#### ScrollUp + +Scroll up by terminal height. + +Example: + +- Lua: `"ScrollUp"` +- YAML: `ScrollUp` + +#### ScrollDown + +Scroll down by terminal height. + +Example: + +- Lua: `"ScrollDown"` +- YAML: `ScrollDown` + +#### ScrollUpHalf + +Scroll up by half of terminal height. + +Example: + +- Lua: `"ScrollUpHalf"` +- YAML: `ScrollUpHalf` + +#### ScrollDownHalf + +Scroll down by half of terminal height. + +Example: + +- Lua: `"ScrollDownHalf"` +- YAML: `ScrollDownHalf` + #### ChangeDirectory Change the present working directory ($PWD) diff --git a/src/app.rs b/src/app.rs index 669b3c1..ce7711c 100644 --- a/src/app.rs +++ b/src/app.rs @@ -406,6 +406,10 @@ impl App { FocusByIndex(i) => self.focus_by_index(i), FocusByIndexFromInput => self.focus_by_index_from_input(), FocusByFileName(n) => self.focus_by_file_name(&n, true), + ScrollUp => self.scroll_up(), + ScrollDown => self.scroll_down(), + ScrollUpHalf => self.scroll_up_half(), + ScrollDownHalf => self.scroll_down_half(), ChangeDirectory(dir) => self.change_directory(&dir, true), Enter => self.enter(), Back => self.back(), @@ -635,7 +639,7 @@ impl App { Ok(self) } - fn focus_previous_by_relative_index(mut self, index: usize) -> Result { + pub fn focus_previous_by_relative_index(mut self, index: usize) -> Result { let mut history = self.history.clone(); if let Some(dir) = self.directory_buffer_mut() { if let Some(n) = dir.focused_node() { @@ -680,7 +684,7 @@ impl App { Ok(self) } - fn focus_next_by_relative_index(mut self, index: usize) -> Result { + pub fn focus_next_by_relative_index(mut self, index: usize) -> Result { let mut history = self.history.clone(); if let Some(dir) = self.directory_buffer_mut() { if let Some(n) = dir.focused_node() { @@ -927,6 +931,26 @@ impl App { } } + pub fn scroll_up(mut self) -> Result { + self.msg_out.push_back(MsgOut::ScrollUp); + Ok(self) + } + + pub fn scroll_down(mut self) -> Result { + self.msg_out.push_back(MsgOut::ScrollDown); + Ok(self) + } + + pub fn scroll_up_half(mut self) -> Result { + self.msg_out.push_back(MsgOut::ScrollUp); + Ok(self) + } + + pub fn scroll_down_half(mut self) -> Result { + self.msg_out.push_back(MsgOut::ScrollDownHalf); + Ok(self) + } + pub fn focus_path(self, path: &str, save_history: bool) -> Result { let mut pathbuf = PathBuf::from(path); if pathbuf.is_relative() { diff --git a/src/init.lua b/src/init.lua index 53c5392..7f4ebae 100644 --- a/src/init.lua +++ b/src/init.lua @@ -1206,6 +1206,30 @@ xplr.config.modes.builtin.default = { }, }, }, + ["page-up"] = { + help = "scroll up", + messages = { + "ScrollUp", + }, + }, + ["page-down"] = { + help = "scroll down", + messages = { + "ScrollDown", + }, + }, + ["{"] = { + help = "scroll up half", + messages = { + "ScrollUpHalf", + }, + }, + ["}"] = { + help = "scroll down half", + messages = { + "ScrollDownHalf", + }, + }, }, on_number = { help = "input", diff --git a/src/msg/in_/external.rs b/src/msg/in_/external.rs index 8442d82..277d283 100644 --- a/src/msg/in_/external.rs +++ b/src/msg/in_/external.rs @@ -174,9 +174,6 @@ pub enum ExternalMsg { /// - YAML: `FocusByIndexFromInput` FocusByIndexFromInput, - /// - /// **YAML:** `FocusByFileName: string` - /// /// Focus on the file by name from the present working directory. /// /// Type: { FocusByFileName = "string" } @@ -187,6 +184,38 @@ pub enum ExternalMsg { /// - YAML: `FocusByFileName: filename.ext` FocusByFileName(String), + /// Scroll up by terminal height. + /// + /// Example: + /// + /// - Lua: `"ScrollUp"` + /// - YAML: `ScrollUp` + ScrollUp, + + /// Scroll down by terminal height. + /// + /// Example: + /// + /// - Lua: `"ScrollDown"` + /// - YAML: `ScrollDown` + ScrollDown, + + /// Scroll up by half of terminal height. + /// + /// Example: + /// + /// - Lua: `"ScrollUpHalf"` + /// - YAML: `ScrollUpHalf` + ScrollUpHalf, + + /// Scroll down by half of terminal height. + /// + /// Example: + /// + /// - Lua: `"ScrollDownHalf"` + /// - YAML: `ScrollDownHalf` + ScrollDownHalf, + /// Change the present working directory ($PWD) /// /// Type: { ChangeDirectory = "string" } diff --git a/src/msg/out/mod.rs b/src/msg/out/mod.rs index ba47fa0..5f4cc8c 100644 --- a/src/msg/out/mod.rs +++ b/src/msg/out/mod.rs @@ -8,7 +8,6 @@ pub enum MsgOut { ExploreParentsAsync, Refresh, ClearScreen, - Quit, Debug(String), Call(Command), CallSilently(Command), @@ -23,6 +22,11 @@ pub enum MsgOut { StartFifo(String), StopFifo, ToggleFifo(String), + ScrollUp, + ScrollDown, + ScrollUpHalf, + ScrollDownHalf, + Quit, PrintPwdAndQuit, PrintFocusPathAndQuit, PrintSelectionAndQuit, diff --git a/src/runner.rs b/src/runner.rs index 90698f9..16a40c5 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -316,6 +316,30 @@ impl Runner { terminal.clear()?; } + ScrollUp => { + app = app.focus_previous_by_relative_index( + terminal.size()?.height as usize, + )?; + } + + ScrollDown => { + app = app.focus_next_by_relative_index( + terminal.size()?.height as usize, + )?; + } + + ScrollUpHalf => { + app = app.focus_next_by_relative_index( + terminal.size()?.height as usize / 2, + )?; + } + + ScrollDownHalf => { + app = app.focus_next_by_relative_index( + terminal.size()?.height as usize / 2, + )?; + } + ExplorePwdAsync => { explorer::explore_async( app.explorer_config.clone(),