Skip to content

Commit 4ab7bf0

Browse files
authored
Merge pull request #131 from mlange-42/feature/no-pager
Remove pager
2 parents 49ed50a + 8aca907 commit 4ab7bf0

File tree

3 files changed

+11
-113
lines changed

3 files changed

+11
-113
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ In case you have [Rust](https://www.rust-lang.org/) installed, you can install w
4040
cargo install git-graph
4141
```
4242

43+
**From `homebrew`**
44+
45+
If you use the [homebrew](https://brew.sh/) package manager:
46+
47+
```
48+
brew install git-graph
49+
```
50+
4351
## Usage
4452

4553
**For detailed information, see the [manual](docs/manual.md)**.

src/main.rs

Lines changed: 2 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
//! Command line tool to show clear git graphs arranged for your branching model.
22
33
use clap::{crate_version, Arg, Command};
4-
use crossterm::cursor::MoveToRow;
5-
use crossterm::event::{Event, KeyCode, KeyModifiers};
6-
use crossterm::style::Print;
7-
use crossterm::terminal::{disable_raw_mode, enable_raw_mode, Clear, ClearType};
8-
use crossterm::ExecutableCommand;
94
use git2::Repository;
105
use git_graph::config::{
116
create_config, get_available_models, get_model, get_model_name, set_model,
@@ -17,7 +12,6 @@ use git_graph::print::svg::print_svg;
1712
use git_graph::print::unicode::print_unicode;
1813
use git_graph::settings::{BranchOrder, BranchSettings, Characters, MergePatterns, Settings};
1914
use platform_dirs::AppDirs;
20-
use std::io::{stdout, Error};
2115
use std::str::FromStr;
2216
use std::time::Instant;
2317

@@ -139,13 +133,6 @@ fn from_args() -> Result<(), String> {
139133
.required(false)
140134
.num_args(0),
141135
)
142-
.arg(
143-
Arg::new("no-pager")
144-
.long("no-pager")
145-
.help("Use no pager (print everything at once without prompt).")
146-
.required(false)
147-
.num_args(0),
148-
)
149136
.arg(
150137
Arg::new("style")
151138
.long("style")
@@ -301,7 +288,6 @@ fn from_args() -> Result<(), String> {
301288
let reverse_commit_order = matches.get_flag("reverse");
302289

303290
let svg = matches.get_flag("svg");
304-
let pager = !matches.get_flag("no-pager");
305291
let compact = !matches.get_flag("sparse");
306292
let debug = matches.get_flag("debug");
307293
let style = matches
@@ -418,15 +404,14 @@ fn from_args() -> Result<(), String> {
418404
merge_patterns: MergePatterns::default(),
419405
};
420406

421-
run(repository, &settings, svg, commit_limit, pager)
407+
run(repository, &settings, svg, commit_limit)
422408
}
423409

424410
fn run(
425411
repository: Repository,
426412
settings: &Settings,
427413
svg: bool,
428414
max_commits: Option<usize>,
429-
pager: bool,
430415
) -> Result<(), String> {
431416
let now = Instant::now();
432417
let graph = GitGraph::new(repository, settings, None, max_commits)?;
@@ -453,18 +438,7 @@ fn run(
453438
println!("{}", print_svg(&graph, settings)?);
454439
} else {
455440
let (g_lines, t_lines, _indices) = print_unicode(&graph, settings)?;
456-
let use_pager =
457-
// Pager is enabled
458-
pager
459-
// and in a terminal, not a pipe
460-
&& atty::is(atty::Stream::Stdout)
461-
// and terminal height is not enough for all lines + the help text
462-
&& (crossterm::terminal::size().unwrap().1 as usize) < g_lines.len() + 1;
463-
if use_pager {
464-
print_paged(&g_lines, &t_lines).map_err(|err| err.to_string())?;
465-
} else {
466-
print_unpaged(&g_lines, &t_lines);
467-
}
441+
print_unpaged(&g_lines, &t_lines);
468442
};
469443

470444
let duration_print = now.elapsed().as_micros();
@@ -480,90 +454,6 @@ fn run(
480454
Ok(())
481455
}
482456

483-
/// Print the graph, paged (i.e. wait for user input once the terminal is filled).
484-
fn print_paged(graph_lines: &[String], text_lines: &[String]) -> Result<(), Error> {
485-
let (width, height) = crossterm::terminal::size()?;
486-
let mut start_idx: usize = 0;
487-
let mut should_update: bool = true;
488-
let visible_lines: usize = height as usize - 1;
489-
let help = "\r >>> Down/Up: line, PgDown/Enter: page, End: all, Esc/Q/^C: quit\r";
490-
let help = if help.len() > width as usize {
491-
&help[0..width as usize]
492-
} else {
493-
help
494-
};
495-
496-
enable_raw_mode()?;
497-
loop {
498-
// Print commits
499-
if should_update {
500-
should_update = false;
501-
// Make sure that start_idx + visible_lines <= graph_lines.len()
502-
start_idx = start_idx.min(graph_lines.len().saturating_sub(visible_lines));
503-
stdout()
504-
.execute(MoveToRow(0))?
505-
.execute(Clear(ClearType::CurrentLine))?;
506-
let content_len = visible_lines.min(graph_lines.len());
507-
for curr_idx in 0..content_len {
508-
stdout()
509-
.execute(Clear(ClearType::CurrentLine))?
510-
.execute(Print(format!(
511-
" {} {}\r\n",
512-
graph_lines[start_idx + curr_idx],
513-
text_lines[start_idx + curr_idx]
514-
)))?;
515-
}
516-
if content_len < visible_lines {
517-
// Exit if screen is larger than full list
518-
break;
519-
}
520-
// Print help at the end
521-
stdout().execute(Print(help))?;
522-
} else {
523-
let input = crossterm::event::read()?;
524-
if let Event::Key(evt) = input {
525-
match evt.code {
526-
KeyCode::Down => {
527-
start_idx += 1;
528-
should_update = true;
529-
}
530-
KeyCode::Up => {
531-
if start_idx > 0 {
532-
start_idx -= 1;
533-
should_update = true;
534-
}
535-
}
536-
KeyCode::Enter | KeyCode::PageDown => {
537-
start_idx += height as usize - 2;
538-
should_update = true;
539-
}
540-
KeyCode::End => {
541-
start_idx = graph_lines.len() - height as usize - 2;
542-
should_update = true;
543-
// TODO: maybe make this better
544-
}
545-
KeyCode::Char(c) => match c {
546-
'q' => {
547-
break;
548-
}
549-
'c' if evt.modifiers == KeyModifiers::CONTROL => {
550-
break;
551-
}
552-
_ => {}
553-
},
554-
KeyCode::Esc => {
555-
break;
556-
}
557-
_ => {}
558-
}
559-
}
560-
}
561-
}
562-
563-
disable_raw_mode()?;
564-
Ok(())
565-
}
566-
567457
/// Print the graph, un-paged.
568458
fn print_unpaged(graph_lines: &[String], text_lines: &[String]) {
569459
for (g_line, t_line) in graph_lines.iter().zip(text_lines.iter()) {

0 commit comments

Comments
 (0)