ok/jj
1
0
Fork 0
forked from mirrors/jj

cli: split pager arguments like ui.editor

Environment like $PAGER or $EDITOR is supposed to be executed via shell,
so we need to at least split the command string.
This commit is contained in:
Yuya Nishihara 2022-12-01 21:39:34 +09:00
parent f23302bc53
commit 3b5edd480c

View file

@ -14,13 +14,14 @@
use std::io::{Stderr, Stdout, Write}; use std::io::{Stderr, Stdout, Write};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::process::{Child, ChildStdin, Command, Stdio}; use std::process::{Child, ChildStdin, Stdio};
use std::str::FromStr; use std::str::FromStr;
use std::{fmt, io, mem}; use std::{fmt, io, mem};
use crossterm::tty::IsTty; use crossterm::tty::IsTty;
use jujutsu_lib::settings::UserSettings; use jujutsu_lib::settings::UserSettings;
use crate::config::FullCommandArgs;
use crate::formatter::{Formatter, FormatterFactory}; use crate::formatter::{Formatter, FormatterFactory};
pub struct Ui { pub struct Ui {
@ -106,11 +107,11 @@ impl Default for PaginationChoice {
} }
} }
fn pager_setting(settings: &UserSettings) -> String { fn pager_setting(settings: &UserSettings) -> FullCommandArgs {
settings settings
.config() .config()
.get_string("ui.pager") .get("ui.pager")
.unwrap_or_else(|_| "less".to_string()) .unwrap_or_else(|_| "less".into())
} }
impl Ui { impl Ui {
@ -350,7 +351,7 @@ impl UiOutput {
fn new_paged(settings: &UserSettings) -> io::Result<UiOutput> { fn new_paged(settings: &UserSettings) -> io::Result<UiOutput> {
let pager_cmd = pager_setting(settings); let pager_cmd = pager_setting(settings);
let mut child = Command::new(pager_cmd).stdin(Stdio::piped()).spawn()?; let mut child = pager_cmd.to_command().stdin(Stdio::piped()).spawn()?;
let child_stdin = child.stdin.take().unwrap(); let child_stdin = child.stdin.take().unwrap();
Ok(UiOutput::Paged { child, child_stdin }) Ok(UiOutput::Paged { child, child_stdin })
} }