Use winsplit to split editor commands on windows
This commit is contained in:
parent
4228c51459
commit
dc98a89e3e
|
@ -25,10 +25,15 @@ ui = { package = "requestty-ui", path = "./requestty-ui", version = "=0.4.1" }
|
||||||
macro = { package = "requestty-macro", path = "./requestty-macro", optional = true, version = "=0.4.1" }
|
macro = { package = "requestty-macro", path = "./requestty-macro", optional = true, version = "=0.4.1" }
|
||||||
|
|
||||||
tempfile = "3"
|
tempfile = "3"
|
||||||
shell-words = "1"
|
|
||||||
|
|
||||||
smallvec = { version = "1.8", optional = true }
|
smallvec = { version = "1.8", optional = true }
|
||||||
|
|
||||||
|
[target.'cfg(unix)'.dependencies]
|
||||||
|
shell-words = "1.1"
|
||||||
|
|
||||||
|
[target.'cfg(windows)'.dependencies]
|
||||||
|
winsplit = "0.1"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
trybuild = { version = "1.0.42", features = ["diff"] }
|
trybuild = { version = "1.0.42", features = ["diff"] }
|
||||||
# remove color printing since it messes with the snapshot's colours
|
# remove color printing since it messes with the snapshot's colours
|
||||||
|
|
|
@ -33,20 +33,31 @@ impl<'a> Default for Editor<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
fn split(command: &str) -> Option<Vec<String>> {
|
||||||
|
shell_words::split(command).ok()
|
||||||
|
}
|
||||||
|
#[cfg(windows)]
|
||||||
|
fn split(command: &str) -> Option<Vec<String>> {
|
||||||
|
Some(winsplit::split(command))
|
||||||
|
}
|
||||||
|
|
||||||
fn get_editor() -> Command {
|
fn get_editor() -> Command {
|
||||||
let editor_command = env::var_os("VISUAL")
|
let editor_args = env::var_os("VISUAL")
|
||||||
.or_else(|| env::var_os("EDITOR"))
|
.or_else(|| env::var_os("EDITOR"))
|
||||||
|
.map(|editor_command| editor_command.to_str().map(split))
|
||||||
|
.flatten()
|
||||||
|
.flatten()
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
if cfg!(windows) {
|
if cfg!(windows) {
|
||||||
"notepad".into()
|
vec!["notepad".into()]
|
||||||
} else {
|
} else {
|
||||||
"vim".into()
|
vec!["vim".into()]
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let parts = shell_words::split(editor_command.to_str().unwrap()).unwrap();
|
let mut command = Command::new(&editor_args[0]);
|
||||||
let mut command = Command::new(&parts[0]);
|
command.args(&editor_args[1..]);
|
||||||
command.args(&parts[1..]);
|
|
||||||
command
|
command
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user