feat: add guarded and forceful editor restart actions
This commit is contained in:
+33
-1
@@ -53,6 +53,10 @@ Save actions: core.save, core.force_save, core.save_and_quit, core.force_save_an
|
||||
Buffers: :edit PATH, :buffers, :buffer N, :buffer_next, :buffer_previous, :buffer_delete [N], :buffer_force_delete [N]
|
||||
Aliases: bnext, bprev, bdelete, bdelete!; arguments and safety rules are unchanged
|
||||
:quit refuses any dirty buffer; both save-and-quit commands require all buffers clean
|
||||
Restart: :restart closes clean buffers; unsaved buffers remain open and block restart with a warning
|
||||
:force_restart / :restart! discards unsaved text without writing
|
||||
Actions: core.restart, core.force_restart (no default binding)
|
||||
Relaunches the executable with original CLI args/config/startup file; tabs/views reset
|
||||
Tabs: :tab.new, :tab.previous, :tab.next, :tab.close, :tab.force_close
|
||||
Tabs retain pane layouts and independent views; close protects exclusively displayed unsaved edits
|
||||
Markdown links: :follow_link (primary caret; local files only)
|
||||
@@ -134,7 +138,35 @@ fn run() -> Result<(), String> {
|
||||
options.config.as_deref(),
|
||||
)
|
||||
.map_err(|error| format!("cannot open file: {error}"))?;
|
||||
tui::run(&mut session).map_err(|error| format!("terminal error: {error}"))
|
||||
tui::run(&mut session).map_err(|error| format!("terminal error: {error}"))?;
|
||||
let restart = session.editor().should_restart();
|
||||
drop(session);
|
||||
if restart {
|
||||
restart_editor()?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn restart_editor() -> Result<(), String> {
|
||||
let executable = env::current_exe().map_err(|error| format!("Restart failed: {error}"))?;
|
||||
let mut command = std::process::Command::new(executable);
|
||||
command.args(env::args_os().skip(1));
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::unix::process::CommandExt;
|
||||
Err(format!("Restart failed: {}", command.exec()))
|
||||
}
|
||||
#[cfg(not(unix))]
|
||||
{
|
||||
let status = command
|
||||
.status()
|
||||
.map_err(|error| format!("Restart failed: {error}"))?;
|
||||
if status.success() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(format!("Restarted editor exited with {status}"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
Reference in New Issue
Block a user