Skip to content

Commit

Permalink
built-in pager: write a message to the user before panicking if pager…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
ilyagr committed Aug 2, 2024
1 parent 5b22594 commit 6cb2cf6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ git2 = { workspace = true }
gix = { workspace = true }
hex = { workspace = true }
indexmap = { workspace = true }
indoc = { workspace = true }
itertools = { workspace = true }
jj-lib = { workspace = true }
maplit = { workspace = true }
Expand Down Expand Up @@ -102,7 +103,6 @@ anyhow = { workspace = true }
assert_cmd = { workspace = true }
assert_matches = { workspace = true }
async-trait = { workspace = true }
indoc = { workspace = true }
insta = { workspace = true }
test-case = { workspace = true }
testutils = { workspace = true }
Expand Down
36 changes: 35 additions & 1 deletion cli/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -87,7 +88,40 @@ 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. This is a bit tricky.
// Currently, the panic tends to happen early and abort any
// mutating operations. The only way I can think of easily
// preserving the error, it will only be detected after the jj
// operation completes. So, jj could do some mutations, but all
// user output will be lost at that point. This seemed
// problematic to me, so while a panic is not great, it seems
// like a better alternative.
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.
See also https://github.com/martinvonz/jj/issues/4182.
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();
}),
}
}
Expand Down

0 comments on commit 6cb2cf6

Please sign in to comment.