Skip to content
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

feat: Add pager support #587

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
188 changes: 188 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ unicode-segmentation = "1.10.1"
human-panic = "1.1.4"
shadow-rs = { version = "0.21.0", optional = true }
enum_dispatch = "0.3.11"
minus = { version = "5.2.0", features = ["search", "dynamic_output"] }

[dev-dependencies]
test-case = "3.1.0"
Expand Down
13 changes: 6 additions & 7 deletions src/bin/diffsitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ use human_panic::setup_panic;
use libdiffsitter::cli;
use libdiffsitter::cli::Args;
use libdiffsitter::config::{Config, ReadError};
use libdiffsitter::console_utils;
use libdiffsitter::diff;
use libdiffsitter::generate_ast_vector_data;
#[cfg(feature = "static-grammar-libs")]
use libdiffsitter::parse::supported_languages;
use libdiffsitter::parse::{generate_language, language_from_ext};
use libdiffsitter::render::{DisplayData, DocumentDiffData, Renderer};
use libdiffsitter::{console_utils, diff};
use log::{debug, error, info, warn, LevelFilter};
use minus::Pager;
use serde_json as json;
use std::{
io,
Expand Down Expand Up @@ -150,11 +150,10 @@ fn run_diff(args: Args, config: Config) -> Result<()> {
// the user just cares about the output at the end, we don't care about how frequently the
// terminal does partial updates or anything like that. If the user is curious about progress,
// they can enable logging and see when hunks are processed and written to the buffer.
let mut buf_writer = Term::buffered_stdout();
let term_info = buf_writer.clone();
renderer.render(&mut buf_writer, &params, Some(&term_info))?;
buf_writer.flush()?;
Ok(())
let mut pager = Pager::new();
// So we can write from another thread
let term_info = Term::stdout();
renderer.render(&mut pager, &params, Some(&term_info))
}

/// Serialize the default options struct to a json file and print that to stdout
Expand Down
2 changes: 1 addition & 1 deletion src/render/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::render::Renderer;
use console::Term;
use logging_timer::time;
use serde::{Deserialize, Serialize};
use std::io::Write;
use std::fmt::Write;

/// A renderer that outputs json data about the diff.
///
Expand Down
2 changes: 1 addition & 1 deletion src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use console::{Color, Style, Term};
use enum_dispatch::enum_dispatch;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::io::Write;
use std::fmt::Write;
use strum::{self, Display, EnumIter, EnumString};
use unified::Unified;

Expand Down
4 changes: 2 additions & 2 deletions src/render/unified.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use anyhow::Result;
use console::{Color, Style, Term};
use log::{debug, error, info};
use serde::{Deserialize, Serialize};
use std::{cmp::max, io::Write};
use std::{cmp::max, fmt::Write};

/// The ascii separator used after the diff title
const TITLE_SEPARATOR: &str = "=";
Expand Down Expand Up @@ -167,7 +167,7 @@ impl Unified {
old_fmt: &FormattingDirectives,
new_fmt: &FormattingDirectives,
term_info: Option<&Term>,
) -> std::io::Result<()> {
) -> std::fmt::Result {
// The different ways we can stack the title
#[derive(Debug, Eq, PartialEq, PartialOrd, Ord, strum_macros::Display)]
#[strum(serialize_all = "snake_case")]
Expand Down
Loading