Define a display submodule

pull/290/head
Wilfred Hughes 2022-05-14 12:09:40 +07:00
parent 43a03d2939
commit 8fe0fc13b5
8 changed files with 20 additions and 17 deletions

@ -1,11 +1,11 @@
//! Inline, or "unified" diff display.
use crate::{
context::{calculate_after_context, calculate_before_context, opposite_positions},
display::context::{calculate_after_context, calculate_before_context, opposite_positions},
display::style::{self, apply_colors},
hunks::Hunk,
lines::{format_line_num, MaxLine},
options::DisplayOptions,
style::{self, apply_colors},
syntax::MatchedPos,
};
use owo_colors::colored::*;

@ -0,0 +1,4 @@
pub mod context;
pub mod inline;
pub mod side_by_side;
pub mod style;

@ -6,12 +6,14 @@ use std::{cmp::max, collections::HashSet};
use crate::{
constants::Side,
context::all_matched_lines_filled,
display::context::all_matched_lines_filled,
display::style::{
self, apply_colors, color_positions, novel_style, split_and_apply, BackgroundColor,
},
hunks::{matched_lines_for_hunk, Hunk},
lines::{codepoint_len, format_line_num, LineNumber},
options::{DisplayMode, DisplayOptions},
positions::SingleLineSpan,
style::{self, apply_colors, color_positions, novel_style, split_and_apply, BackgroundColor},
syntax::{zip_pad_shorter, MatchedPos},
};

@ -11,9 +11,9 @@ use rustc_hash::FxHashMap;
use crate::{
constants::Side,
context::{add_context, opposite_positions, MAX_PADDING},
display::context::{add_context, opposite_positions, MAX_PADDING},
display::side_by_side::lines_with_novel,
lines::LineNumber,
side_by_side::lines_with_novel,
syntax::{zip_pad_shorter, MatchedPos},
};

@ -15,21 +15,18 @@
mod changes;
mod constants;
mod context;
mod dijkstra;
mod display;
mod files;
mod graph;
mod guess_language;
mod hunks;
mod inline;
mod line_parser;
mod lines;
mod myers_diff;
mod options;
mod positions;
mod side_by_side;
mod sliders;
mod style;
mod summary;
mod syntax;
mod tree_sitter_parser;
@ -40,7 +37,7 @@ extern crate log;
use crate::hunks::{matched_pos_to_hunks, merge_adjacent};
use changes::ChangeMap;
use context::opposite_positions;
use display::context::opposite_positions;
use files::{is_probably_binary, read_files_or_die, read_or_die, relative_paths_in_either};
use guess_language::guess;
use log::info;
@ -415,7 +412,7 @@ fn print_diff_result(display_options: &DisplayOptions, summary: &DiffResult) {
if display_options.print_unchanged {
println!(
"{}",
style::header(
display::style::header(
&summary.lhs_display_path,
&summary.rhs_display_path,
1,
@ -437,7 +434,7 @@ fn print_diff_result(display_options: &DisplayOptions, summary: &DiffResult) {
match display_options.display_mode {
DisplayMode::Inline => {
inline::print(
display::inline::print(
lhs_src,
rhs_src,
display_options,
@ -450,7 +447,7 @@ fn print_diff_result(display_options: &DisplayOptions, summary: &DiffResult) {
);
}
DisplayMode::SideBySide | DisplayMode::SideBySideShowBoth => {
side_by_side::print(
display::side_by_side::print(
&hunks,
display_options,
&summary.lhs_display_path,
@ -469,7 +466,7 @@ fn print_diff_result(display_options: &DisplayOptions, summary: &DiffResult) {
if display_options.print_unchanged || changed {
println!(
"{}",
style::header(
display::style::header(
&summary.lhs_display_path,
&summary.rhs_display_path,
1,
@ -489,7 +486,7 @@ fn print_diff_result(display_options: &DisplayOptions, summary: &DiffResult) {
// We're diffing a binary file against a text file.
println!(
"{}",
style::header(
display::style::header(
&summary.lhs_display_path,
&summary.rhs_display_path,
1,

@ -6,7 +6,7 @@ use atty::Stream;
use clap::{crate_authors, crate_description, crate_version, Arg, Command};
use const_format::formatcp;
use crate::{guess_language, style::BackgroundColor};
use crate::{guess_language, display::style::BackgroundColor};
pub const DEFAULT_NODE_LIMIT: u32 = 30_000;
pub const DEFAULT_BYTE_LIMIT: usize = 1_000_000;