From 8fe0fc13b580e33e897266650be0de0394bd5fa4 Mon Sep 17 00:00:00 2001 From: Wilfred Hughes Date: Sat, 14 May 2022 12:09:40 -0400 Subject: [PATCH] Define a display submodule --- src/{ => display}/context.rs | 0 src/{ => display}/inline.rs | 4 ++-- src/display/mod.rs | 4 ++++ src/{ => display}/side_by_side.rs | 6 ++++-- src/{ => display}/style.rs | 0 src/hunks.rs | 4 ++-- src/main.rs | 17 +++++++---------- src/options.rs | 2 +- 8 files changed, 20 insertions(+), 17 deletions(-) rename src/{ => display}/context.rs (100%) rename src/{ => display}/inline.rs (95%) create mode 100644 src/display/mod.rs rename src/{ => display}/side_by_side.rs (99%) rename src/{ => display}/style.rs (100%) diff --git a/src/context.rs b/src/display/context.rs similarity index 100% rename from src/context.rs rename to src/display/context.rs diff --git a/src/inline.rs b/src/display/inline.rs similarity index 95% rename from src/inline.rs rename to src/display/inline.rs index c1185820f..dd83aecfe 100644 --- a/src/inline.rs +++ b/src/display/inline.rs @@ -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::*; diff --git a/src/display/mod.rs b/src/display/mod.rs new file mode 100644 index 000000000..cc98f560a --- /dev/null +++ b/src/display/mod.rs @@ -0,0 +1,4 @@ +pub mod context; +pub mod inline; +pub mod side_by_side; +pub mod style; diff --git a/src/side_by_side.rs b/src/display/side_by_side.rs similarity index 99% rename from src/side_by_side.rs rename to src/display/side_by_side.rs index 45d06bc85..f2afe4f22 100644 --- a/src/side_by_side.rs +++ b/src/display/side_by_side.rs @@ -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}, }; diff --git a/src/style.rs b/src/display/style.rs similarity index 100% rename from src/style.rs rename to src/display/style.rs diff --git a/src/hunks.rs b/src/hunks.rs index 9cc6996a3..a29a284d0 100644 --- a/src/hunks.rs +++ b/src/hunks.rs @@ -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}, }; diff --git a/src/main.rs b/src/main.rs index 322e9ed3e..ca3bd0043 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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, diff --git a/src/options.rs b/src/options.rs index 257cab2f2..8cce73c26 100644 --- a/src/options.rs +++ b/src/options.rs @@ -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;