mirror of
https://github.com/astral-sh/uv.git
synced 2025-10-28 10:50:29 +00:00
Use which-retrieved path directly when spawning pager (#5198)
## Summary Closes https://github.com/astral-sh/uv/issues/5124. ## Test Plan Ran `cargo run -- help pip compile` on my Windows machine, which failed before but succeeds after this change.
This commit is contained in:
parent
dfe2faa71e
commit
54bca18184
1 changed files with 14 additions and 8 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
use std::ffi::OsStr;
|
||||||
use std::{fmt::Display, fmt::Write};
|
use std::{fmt::Display, fmt::Write};
|
||||||
|
|
||||||
use anstream::{stream::IsTerminal, ColorChoice};
|
use anstream::{stream::IsTerminal, ColorChoice};
|
||||||
|
|
@ -68,13 +69,18 @@ pub(crate) fn help(query: &[String], printer: Printer, no_pager: bool) -> Result
|
||||||
|
|
||||||
let is_terminal = std::io::stdout().is_terminal();
|
let is_terminal = std::io::stdout().is_terminal();
|
||||||
let should_page = !no_pager && !is_root && is_terminal;
|
let should_page = !no_pager && !is_root && is_terminal;
|
||||||
if should_page && which("less").is_ok() {
|
|
||||||
// When using less, we use the command name as the file name and can support colors
|
if should_page {
|
||||||
let prompt = format!("help: uv {}", query.join(" "));
|
if let Ok(less) = which("less") {
|
||||||
spawn_pager("less", &["-R", "-P", &prompt], &help_ansi)?;
|
// When using less, we use the command name as the file name and can support colors
|
||||||
} else if should_page && which("more").is_ok() {
|
let prompt = format!("help: uv {}", query.join(" "));
|
||||||
// When using more, we skip the ANSI color codes
|
spawn_pager(less, &["-R", "-P", &prompt], &help_ansi)?;
|
||||||
spawn_pager("more", &[], &help)?;
|
} else if let Ok(more) = which("more") {
|
||||||
|
// When using more, we skip the ANSI color codes
|
||||||
|
spawn_pager(more, &[], &help)?;
|
||||||
|
} else {
|
||||||
|
writeln!(printer.stdout(), "{help_ansi}")?;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
writeln!(printer.stdout(), "{help_ansi}")?;
|
writeln!(printer.stdout(), "{help_ansi}")?;
|
||||||
}
|
}
|
||||||
|
|
@ -98,7 +104,7 @@ fn find_command<'a>(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Spawn a paging command to display contents.
|
/// Spawn a paging command to display contents.
|
||||||
fn spawn_pager(command: &str, args: &[&str], contents: impl Display) -> Result<()> {
|
fn spawn_pager(command: impl AsRef<OsStr>, args: &[&str], contents: impl Display) -> Result<()> {
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
let mut child = std::process::Command::new(command)
|
let mut child = std::process::Command::new(command)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue