Add more vroot options

- ToggleVroot
- UnsetVroot

Along with key bindings.
This commit is contained in:
Arijit Basu 2022-10-27 22:59:12 +05:30
parent 94154c56df
commit 71bd2e2776
No known key found for this signature in database
GPG Key ID: 0F8EF5258DC38077
6 changed files with 95 additions and 10 deletions

View File

@ -59,12 +59,14 @@ of [modes][4] and the key mappings for each mode.
### vroot
| key | remaps | action |
| ------ | ------ | ----------- |
| . | | vroot $PWD |
| / | | vroot / |
| ctrl-r | | reset vroot |
| ~ | | vroot $HOME |
| key | remaps | action |
| ------ | ------ | ------------ |
| . | | vroot $PWD |
| / | | vroot / |
| ~ | | vroot $HOME |
| v | | toggle vroot |
| ctrl-r | | reset vroot |
| ctrl-u | | unset vroot |
### create_file

View File

@ -7,6 +7,7 @@ xplr messages categorized based on their purpose.
- [Exploring](#exploring)
- [Screen](#screen)
- [Navigation](#navigation)
- [Virtual Root](#virtual-root)
- [Reading Input](#reading-input)
- [Switching Mode](#switching-mode)
- [Switching Layout](#switching-layout)
@ -310,9 +311,12 @@ Example:
Lua: `"FollowSymlink"`
YAML: `FollowSymlink`
### Virtual Root
#### SetVroot
Sets the virtual root for isolating xplr navigation, similar to `--vroot`.
Sets the virtual root for isolating xplr navigation, similar to
`--vroot`, but temporary (can be reset back to initial value).
If the $PWD is outside the vroot, xplr will automatically enter vroot.
Type: { SetVroot = "string" }
@ -322,9 +326,28 @@ Example:
Lua: `{ SetVroot = "/tmp" }`
YAML: `SetVroot: /tmp`
#### UnsetVroot
Unset the virtual root temporarily (can be reset back to the initial
value).
Example:
- Lua: `"UnsetVroot"`
- YAML: `UnsetVroot`
#### ToggleVroot
Toggle virtual root between unset, initial value and $PWD.
Example:
- Lua: `"ToggleVroot"`
- YAML: `ToggleVroot`
#### ResetVroot
Resets the virtual root bach to the value passed by `--vroot` or `/`.
Reset the virtual root back to the initial value.
Example:

View File

@ -137,6 +137,12 @@ The builtin switch layout mode.
Type: [Mode](https://xplr.dev/en/mode)
#### xplr.config.modes.builtin.vroot
The builtin vroot mode.
Type: [Mode](https://xplr.dev/en/mode)
#### xplr.config.modes.custom
This is where you define custom modes.

View File

@ -449,6 +449,8 @@ impl App {
NextVisitedPath => self.next_visited_path(),
FollowSymlink => self.follow_symlink(),
SetVroot(p) => self.set_vroot(&p),
UnsetVroot => self.unset_vroot(),
ToggleVroot => self.toggle_vroot(),
ResetVroot => self.reset_vroot(),
SetInputPrompt(p) => self.set_input_prompt(p),
UpdateInputBuffer(op) => self.update_input_buffer(op),
@ -783,6 +785,24 @@ impl App {
}
}
fn unset_vroot(mut self) -> Result<Self> {
self.vroot = None;
Ok(self)
}
fn toggle_vroot(self) -> Result<Self> {
if self.vroot.is_some() && self.vroot == self.initial_vroot {
self.unset_vroot()
} else if self.vroot.is_some() && self.initial_vroot.is_some() {
self.reset_vroot()
} else if self.vroot.is_some() {
self.unset_vroot()
} else {
let vroot = self.pwd.clone();
self.set_vroot(&vroot)
}
}
fn reset_vroot(mut self) -> Result<Self> {
if let Some(vroot) = self.initial_vroot.clone() {
self.set_vroot(&vroot)

View File

@ -2325,6 +2325,13 @@ xplr.config.modes.builtin.vroot = {
name = "vroot",
key_bindings = {
on_key = {
["v"] = {
help = "toggle vroot",
messages = {
"PopMode",
"ToggleVroot",
},
},
["."] = {
help = "vroot $PWD",
messages = {
@ -2361,6 +2368,13 @@ xplr.config.modes.builtin.vroot = {
"ResetVroot",
},
},
["ctrl-u"] = {
help = "unset vroot",
messages = {
"PopMode",
"UnsetVroot",
},
},
},
},
}

View File

@ -266,7 +266,10 @@ pub enum ExternalMsg {
/// YAML: `FollowSymlink`
FollowSymlink,
/// Sets the virtual root for isolating xplr navigation, similar to `--vroot`.
/// ### Virtual Root ------------------------------------------------------
/// Sets the virtual root for isolating xplr navigation, similar to
/// `--vroot`, but temporary (can be reset back to initial value).
/// If the $PWD is outside the vroot, xplr will automatically enter vroot.
///
/// Type: { SetVroot = "string" }
@ -277,7 +280,24 @@ pub enum ExternalMsg {
/// YAML: `SetVroot: /tmp`
SetVroot(String),
/// Resets the virtual root bach to the value passed by `--vroot` or `/`.
/// Unset the virtual root temporarily (can be reset back to the initial
/// value).
///
/// Example:
///
/// - Lua: `"UnsetVroot"`
/// - YAML: `UnsetVroot`
UnsetVroot,
/// Toggle virtual root between unset, initial value and $PWD.
///
/// Example:
///
/// - Lua: `"ToggleVroot"`
/// - YAML: `ToggleVroot`
ToggleVroot,
/// Reset the virtual root back to the initial value.
///
/// Example:
///