diff options
-rw-r--r-- | development.md | 1 | ||||
-rw-r--r-- | src/action_map.rs | 4 | ||||
-rw-r--r-- | src/event_exec.rs | 34 | ||||
-rw-r--r-- | src/help.rs | 1 | ||||
-rw-r--r-- | src/keybindings.rs | 1 | ||||
-rw-r--r-- | src/mode.rs | 3 | ||||
-rw-r--r-- | src/status.rs | 4 | ||||
-rw-r--r-- | src/tab.rs | 4 |
8 files changed, 39 insertions, 13 deletions
diff --git a/development.md b/development.md index 5a97a56..5b4d08b 100644 --- a/development.md +++ b/development.md @@ -417,6 +417,7 @@ New view: Tree ! Toggle with 't', fold with 'z'. Navigate normally. - [x] refactor config creation - [x] shorten long names in first line - [x] use skim to search for specific line in file + - [x] manually setup a neovim server with shift+i. Get the server address with `echo serverstart()`. - [ ] Version 0.1.50 : safety & memory usage diff --git a/src/action_map.rs b/src/action_map.rs index 4a7a341..92ed26c 100644 --- a/src/action_map.rs +++ b/src/action_map.rs @@ -54,6 +54,7 @@ pub enum ActionMap { NewFile, Nothing, NvimFilepicker, + NvimSetAddress, OpenConfig, OpenFile, PageDown, @@ -133,7 +134,8 @@ impl ActionMap { ActionMap::MoveUp => EventExec::event_move_up(status, colors), ActionMap::NewDir => EventExec::event_new_dir(current_tab), ActionMap::NewFile => EventExec::event_new_file(current_tab), - ActionMap::NvimFilepicker => EventExec::event_nvim_filepicker(current_tab), + ActionMap::NvimFilepicker => EventExec::event_nvim_filepicker(status), + ActionMap::NvimSetAddress => EventExec::event_set_nvim_server(status), ActionMap::OpenFile => EventExec::event_open_file(status), ActionMap::PageDown => EventExec::event_page_down(status, colors), ActionMap::PageUp => EventExec::event_page_up(status, colors), diff --git a/src/event_exec.rs b/src/event_exec.rs index 7a13d76..4d720c0 100644 --- a/src/event_exec.rs +++ b/src/event_exec.rs @@ -286,6 +286,12 @@ impl EventExec { status.reset_tabs_view() } + pub fn exec_set_neovim_address(status: &mut Status) -> FmResult<()> { + status.nvim_server = status.selected_non_mut().input.string(); + status.selected().reset_mode(); + Ok(()) + } + /// Execute a jump to the selected flagged file. /// If the user selected a directory, we jump inside it. /// Otherwise, we jump to the parent and select the file. @@ -855,27 +861,36 @@ impl EventExec { /// If no RPC server were provided at launch time - which may happen for /// reasons unknow to me - it does nothing. /// It requires the "nvim-send" application to be in $PATH. - pub fn event_nvim_filepicker(tab: &mut Tab) -> FmResult<()> { + pub fn event_nvim_filepicker(status: &mut Status) -> FmResult<()> { if !is_program_in_path(NVIM_RPC_SENDER) { return Ok(()); }; - Self::reset_nvim_listen_address(tab); - if tab.nvim_server.is_empty() { + Self::read_nvim_listen_address_if_needed(status); + if status.nvim_server.is_empty() { return Ok(()); }; + let nvim_server = status.nvim_server.clone(); + let tab = status.selected(); let Some(fileinfo) = tab.selected() else { return Ok(()) }; let Some(path_str) = fileinfo.path.to_str() else { return Ok(()) }; - Self::open_in_current_neovim(path_str, &tab.nvim_server); + Self::open_in_current_neovim(path_str, &nvim_server); Ok(()) } + pub fn event_set_nvim_server(status: &mut Status) -> FmResult<()> { + status + .selected() + .set_mode(Mode::InputSimple(InputSimple::SetNvimAddress)); + Ok(()) + } + fn open_in_current_neovim(path_str: &str, nvim_server: &str) { let _ = execute_in_child( NVIM_RPC_SENDER, &vec![ "--remote-send", - &format!("<esc>:e {path_str}<cr><esc>:close<cr>"), + &format!("<esc>:e {path_str}<cr><esc>:set number<cr><esc>:close<cr>"), "--servername", nvim_server, ], @@ -947,12 +962,12 @@ impl EventExec { Ok(()) } - fn reset_nvim_listen_address(tab: &mut Tab) { - if !tab.nvim_server.is_empty() { + fn read_nvim_listen_address_if_needed(status: &mut Status) { + if !status.nvim_server.is_empty() { return; } let Ok(nvim_listen_address) = std::env::var("NVIM_LISTEN_ADDRESS") else { return; }; - tab.nvim_server = nvim_listen_address; + status.nvim_server = nvim_listen_address; } /// Execute a rename of the selected file. @@ -1323,6 +1338,9 @@ impl EventExec { Mode::InputSimple(InputSimple::Newdir) => EventExec::exec_newdir(status.selected())?, Mode::InputSimple(InputSimple::Chmod) => EventExec::exec_chmod(status)?, Mode::InputSimple(InputSimple::RegexMatch) => EventExec::exec_regex(status)?, + Mode::InputSimple(InputSimple::SetNvimAddress) => { + EventExec::exec_set_neovim_address(status)? + } Mode::InputSimple(InputSimple::Filter) => { must_refresh = false; EventExec::exec_filter(status, colors)? diff --git a/src/help.rs b/src/help.rs index b89d0b2..a6f50ad 100644 --- a/src/help.rs +++ b/src/help.rs @@ -29,6 +29,7 @@ static HELP_TO_FORMAT: &str = " {Shell}: shell in current directory {OpenFile}: open the selected file {NvimFilepicker}: open in current nvim session +{NvimSetAddress}: setup the nvim rpc address {Preview}: preview this file {MediaInfo}: display a thumbnail of an image with ueberzug {Back}: move back to previous dir diff --git a/src/keybindings.rs b/src/keybindings.rs index 09300a6..98b0dd7 100644 --- a/src/keybindings.rs +++ b/src/keybindings.rs @@ -51,6 +51,7 @@ impl Bindings { (Key::Char('F'), ActionMap::Filter), (Key::Char('G'), ActionMap::Shortcut), (Key::Char('H'), ActionMap::History), + (Key::Char('I'), ActionMap::NvimSetAddress), (Key::Char('M'), ActionMap::MarksNew), (Key::Char('O'), ActionMap::Sort), (Key::Char('P'), ActionMap::Preview), diff --git a/src/mode.rs b/src/mode.rs index cb1ec30..8bcf3ea 100644 --- a/src/mode.rs +++ b/src/mode.rs @@ -74,6 +74,8 @@ pub enum InputSimple { Sort, /// Filter by extension, name, directory or no filter Filter, + /// Set a new neovim RPC address + SetNvimAddress, /// Input a password (chars a replaced by *) Password(PasswordKind, EncryptedAction), } @@ -130,6 +132,7 @@ impl fmt::Display for Mode { Mode::InputSimple(InputSimple::Newfile) => write!(f, "Newfile: "), Mode::InputSimple(InputSimple::Newdir) => write!(f, "Newdir: "), Mode::InputSimple(InputSimple::RegexMatch) => write!(f, "Regex: "), + Mode::InputSimple(InputSimple::SetNvimAddress) => write!(f, "Neovim: "), Mode::InputSimple(InputSimple::Sort) => { write!(f, "Sort: Kind Name Modif Size Ext Rev :") } diff --git a/src/status.rs b/src/status.rs index aa5498d..8c4a1a3 100644 --- a/src/status.rs +++ b/src/status.rs @@ -66,6 +66,8 @@ pub struct Status { pub encrypted_devices: DeviceOpener, /// Compression methods pub compression: Compresser, + /// NVIM RPC server address + pub nvim_server: String, } impl Status { @@ -86,6 +88,7 @@ impl Status { let sys = System::new_with_specifics(RefreshKind::new().with_disks()); let opener = load_opener(OPENER_PATH, terminal).unwrap_or_else(|_| Opener::new(terminal)); let users_cache = unsafe { UsersCache::with_all_users() }; + let nvim_server = args.server.clone(); let mut right_tab = Tab::new(args.clone(), height, users_cache)?; right_tab .shortcut @@ -116,6 +119,7 @@ impl Status { trash, encrypted_devices, compression, + nvim_server, }) } @@ -33,8 +33,6 @@ pub struct Tab { pub height: usize, /// read from command line pub show_hidden: bool, - /// NVIM RPC server address - pub nvim_server: String, /// Completion list and index in it. pub completion: Completion, /// True if the user issued a quit event (`Key::Char('q')` by default). @@ -64,7 +62,6 @@ impl Tab { let show_hidden = false; let path_content = PathContent::new(&path, users_cache, &filter, show_hidden)?; let show_hidden = false; - let nvim_server = args.server; let mode = Mode::Normal; let previous_mode = Mode::Normal; let window = ContentWindow::new(path_content.content.len(), height); @@ -83,7 +80,6 @@ impl Tab { input, path_content, height, - nvim_server, completion, must_quit, preview, |