From 22b40086819fefb4b62c2c2da4e4f37322a67c4a Mon Sep 17 00:00:00 2001 From: Ilya Grigoriev Date: Fri, 2 Aug 2024 01:05:30 -0700 Subject: [PATCH] built-in pager: write a message to the user before panicking if pager doesn't start This will hopefully improve the experience of users who encounter #4182. Unfortunately, this is the most I can think of doing in the short term to address the problem. See the linked issue for more details. --- cli/src/ui.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/cli/src/ui.rs b/cli/src/ui.rs index 21945db687a..49fb9594fd7 100644 --- a/cli/src/ui.rs +++ b/cli/src/ui.rs @@ -18,6 +18,7 @@ use std::str::FromStr; use std::thread::JoinHandle; use std::{env, fmt, io, mem}; +use indoc::indoc; use minus::Pager as MinusPager; use tracing::instrument; @@ -87,7 +88,31 @@ impl BuiltinPager { pager, dynamic_pager_thread: std::thread::spawn(move || { // This thread handles the actual paging. - minus::dynamic_paging(pager_handle).unwrap(); + // TODO(#4182): handle error better + minus::dynamic_paging(pager_handle) + .inspect_err(|err| { + eprintln!("\n"); + if let minus::error::MinusError::Setup( + minus::error::SetupError::InvalidTerminal, + ) = err + { + eprintln!(indoc! {r#" + jj ERROR: jj's builtin pager is incompatible with this terminal + + This is known to happen with `mintty`, the default Git Bash terminal on Windows. + + POSSIBLE WORKAROUNDS: + - Use `jj --no-pager` + - Use a different terminal (e.g. Windows Terminal or the Command Prompt) + - Configure a different pager, see https://martinvonz.github.io/jj/latest/windows/#pagination for Git Bash on Windows + - Use `winpty jj ...` on Windows."# + }) + } else { + eprintln!("jj ERROR: built-in pager failed to start, will panic.") + } + eprintln!(); + }) + .unwrap(); }), } }