Repository navigation
Add pager functionality back in #155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,8 +23,9 @@ use gleisbau::settings::{ | |
| }; | ||
| use itertools::enumerate; | ||
| use platform_dirs::AppDirs; | ||
| use std::path::PathBuf; | ||
| use std::borrow::Borrow; | ||
| use std::io::IsTerminal; | ||
| use std::path::PathBuf; | ||
| use std::rc::Rc; | ||
| use std::str::FromStr; | ||
| use std::time::Instant; | ||
|
|
@@ -56,6 +57,7 @@ fn from_args() -> Result<(), String> { | |
| ses.svg, | ||
| ses.commit_limit, | ||
| ses.refspecs, | ||
| ses.pager, | ||
| ) | ||
| } | ||
|
|
||
|
|
@@ -134,6 +136,13 @@ fn match_args() -> ArgMatches { | |
| .required(false) | ||
| .num_args(1), | ||
| ) | ||
| .arg( | ||
| Arg::new("no-pager") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you happen to know if there is a
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the more common thing people do is
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes I've certainly used the |
||
| .long("no-pager") | ||
| .help("Use no pager (print everything at once without prompt).") | ||
| .required(false) | ||
| .num_args(0), | ||
| ) | ||
| .arg( | ||
| Arg::new("refspecs") | ||
| .help( | ||
|
|
@@ -210,6 +219,11 @@ fn configure_session(ses: &mut Session, matches: &ArgMatches) -> Result<bool, St | |
| .map(|vals| vals.cloned().collect()) | ||
| .unwrap_or_default(); | ||
|
|
||
| ses.pager = matches | ||
| .get_one::<bool>("no-pager") | ||
| .map(|b| !*b) | ||
| .unwrap_or(true); | ||
|
|
||
| Ok(run_application) | ||
| } | ||
|
|
||
|
|
@@ -225,6 +239,7 @@ struct Session { | |
| pub svg: bool, | ||
| pub commit_limit: Option<usize>, | ||
| pub refspecs: Vec<String>, | ||
| pub pager: bool, | ||
| } | ||
|
|
||
| impl Session { | ||
|
|
@@ -241,6 +256,8 @@ impl Session { | |
| svg: false, | ||
| commit_limit: None, | ||
| refspecs: Vec::new(), | ||
|
|
||
| pager: true, | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -620,6 +637,7 @@ fn run( | |
| svg: bool, | ||
| max_commits: Option<usize>, | ||
| refspecs: Vec<String>, | ||
| pager: bool, | ||
| ) -> Result<(), String> { | ||
| let now = Instant::now(); | ||
| let mut graph_builder = GraphBuilder::new() | ||
|
|
@@ -665,6 +683,13 @@ fn run( | |
| if svg { | ||
| println!("{}", print_svg(&graph, settings)?); | ||
| } else { | ||
| if pager && should_page() { | ||
| let pager_command = git_pager(); | ||
|
|
||
| let mut pager = pager::Pager::with_pager(&pager_command); | ||
| pager.setup(); | ||
| } | ||
|
|
||
| let (g_lines, t_lines, _indices) = print_unicode(&graph, settings)?; | ||
| print_unpaged(&g_lines, &t_lines); | ||
| }; | ||
|
|
@@ -682,6 +707,32 @@ fn run( | |
| Ok(()) | ||
| } | ||
|
|
||
| fn git_pager() -> String { | ||
| std::env::var("GIT_PAGER") | ||
| .ok() | ||
| .or_else(|| { | ||
| std::process::Command::new("git") | ||
| .args(["config", "--get", "core.pager"]) | ||
| .output() | ||
| .ok() | ||
| .filter(|o| o.status.success()) | ||
| .map(|o| String::from_utf8_lossy(&o.stdout).trim().to_owned()) | ||
| .filter(|s| !s.is_empty()) | ||
| }) | ||
| .or_else(|| std::env::var("PAGER").ok()) | ||
| .unwrap_or_else(|| "less".to_owned()) | ||
| } | ||
|
|
||
| fn should_page() -> bool { | ||
| if !std::io::stdout().is_terminal() { | ||
| return false; | ||
| } | ||
|
|
||
| let (width, height) = crossterm::terminal::size().unwrap_or((80, 24)); | ||
|
|
||
| width > 0 && height > 0 | ||
| } | ||
|
|
||
| /// Print the graph, un-paged. | ||
| fn print_unpaged(graph_lines: &[String], text_lines: &[String]) { | ||
| for (g_line, t_line) in graph_lines.iter().zip(text_lines.iter()) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar which this crate, but it seems to not compile on Windows, as seen on the CI pipeline.
In its current state it is not usable as Windows is a supported target for git-graph.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, that's sad. As I do not have a windows to test on, I think it would be best to close this PR then...
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CI pipeline runs the test on Windows for you when you push changes to the PR. This is not a full user test, but it does check if it compiles at all.
But, you would need to find a different crate. The pager crate has a feature request for Windows support from 2017, which suggests that Windows support is not going to be added to it anytime soon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it make more sense to put
pageras a platform specific dependency?AFAIK, pager isn't really a concept under Windows?
I haven't used windows in like 10 years so I might also be wrong :)