Prefer 'terminal' over 'display' terminology

pull/708/merge
Wilfred Hughes 2024-05-10 15:53:40 +07:00
parent ec7a765453
commit 6a3b340d5f
2 changed files with 16 additions and 16 deletions

@ -436,7 +436,7 @@ pub(crate) fn print(
let no_rhs_changes = hunk.novel_rhs.is_empty(); let no_rhs_changes = hunk.novel_rhs.is_empty();
let same_lines = aligned_lines.iter().all(|(l, r)| l == r); let same_lines = aligned_lines.iter().all(|(l, r)| l == r);
let source_dims = SourceDimensions::new(display_options.display_width, aligned_lines); let source_dims = SourceDimensions::new(display_options.terminal_width, aligned_lines);
for (lhs_line_num, rhs_line_num) in aligned_lines { for (lhs_line_num, rhs_line_num) in aligned_lines {
let lhs_line_novel = highlight_as_novel( let lhs_line_novel = highlight_as_novel(
*lhs_line_num, *lhs_line_num,
@ -594,7 +594,7 @@ mod tests {
use super::*; use super::*;
use crate::{ use crate::{
options::DEFAULT_DISPLAY_WIDTH, options::DEFAULT_TERMINAL_WIDTH,
parse::guess_language::Language, parse::guess_language::Language,
syntax::{AtomKind, MatchKind, TokenKind}, syntax::{AtomKind, MatchKind, TokenKind},
}; };
@ -602,7 +602,7 @@ mod tests {
#[test] #[test]
fn test_width_calculations() { fn test_width_calculations() {
let line_nums = [(Some(1.into()), Some(10.into()))]; let line_nums = [(Some(1.into()), Some(10.into()))];
let source_dims = SourceDimensions::new(DEFAULT_DISPLAY_WIDTH, &line_nums); let source_dims = SourceDimensions::new(DEFAULT_TERMINAL_WIDTH, &line_nums);
assert_eq!(source_dims.lhs_line_nums_width, 2); assert_eq!(source_dims.lhs_line_nums_width, 2);
assert_eq!(source_dims.rhs_line_nums_width, 3); assert_eq!(source_dims.rhs_line_nums_width, 3);
@ -611,7 +611,7 @@ mod tests {
#[test] #[test]
fn test_format_missing_line_num() { fn test_format_missing_line_num() {
let source_dims = SourceDimensions::new( let source_dims = SourceDimensions::new(
DEFAULT_DISPLAY_WIDTH, DEFAULT_TERMINAL_WIDTH,
&[ &[
(Some(0.into()), Some(0.into())), (Some(0.into()), Some(0.into())),
(Some(1.into()), Some(1.into())), (Some(1.into()), Some(1.into())),

@ -44,13 +44,13 @@ pub(crate) struct DisplayOptions {
pub(crate) display_mode: DisplayMode, pub(crate) display_mode: DisplayMode,
pub(crate) print_unchanged: bool, pub(crate) print_unchanged: bool,
pub(crate) tab_width: usize, pub(crate) tab_width: usize,
pub(crate) display_width: usize, pub(crate) terminal_width: usize,
pub(crate) num_context_lines: u32, pub(crate) num_context_lines: u32,
pub(crate) syntax_highlight: bool, pub(crate) syntax_highlight: bool,
pub(crate) sort_paths: bool, pub(crate) sort_paths: bool,
} }
pub(crate) const DEFAULT_DISPLAY_WIDTH: usize = 80; pub(crate) const DEFAULT_TERMINAL_WIDTH: usize = 80;
impl Default for DisplayOptions { impl Default for DisplayOptions {
fn default() -> Self { fn default() -> Self {
@ -60,7 +60,7 @@ impl Default for DisplayOptions {
display_mode: DisplayMode::SideBySide, display_mode: DisplayMode::SideBySide,
print_unchanged: true, print_unchanged: true,
tab_width: 8, tab_width: 8,
display_width: DEFAULT_DISPLAY_WIDTH, terminal_width: DEFAULT_TERMINAL_WIDTH,
num_context_lines: 3, num_context_lines: 3,
syntax_highlight: true, syntax_highlight: true,
sort_paths: false, sort_paths: false,
@ -650,12 +650,12 @@ pub(crate) fn parse_args() -> Mode {
}; };
} }
let display_width = if let Some(arg_width) = matches.value_of("width") { let terminal_width = if let Some(arg_width) = matches.value_of("width") {
arg_width arg_width
.parse::<usize>() .parse::<usize>()
.expect("Already validated by clap") .expect("Already validated by clap")
} else { } else {
detect_display_width() detect_terminal_width()
}; };
let display_mode = match matches.value_of("display").expect("display has a default") { let display_mode = match matches.value_of("display").expect("display has a default") {
@ -803,7 +803,7 @@ pub(crate) fn parse_args() -> Mode {
print_unchanged, print_unchanged,
tab_width, tab_width,
display_mode, display_mode,
display_width, terminal_width,
num_context_lines, num_context_lines,
syntax_highlight, syntax_highlight,
sort_paths, sort_paths,
@ -840,7 +840,7 @@ pub(crate) fn parse_args() -> Mode {
print_unchanged, print_unchanged,
tab_width, tab_width,
display_mode, display_mode,
display_width, terminal_width,
num_context_lines, num_context_lines,
syntax_highlight, syntax_highlight,
sort_paths, sort_paths,
@ -860,14 +860,14 @@ pub(crate) fn parse_args() -> Mode {
} }
} }
/// Choose the display width: try to autodetect, or fall back to a /// Try to work out the width of the terminal we're on, or fall back
/// sensible default. /// to a sensible default value.
fn detect_display_width() -> usize { fn detect_terminal_width() -> usize {
if let Ok((columns, _rows)) = crossterm::terminal::size() { if let Ok((columns, _rows)) = crossterm::terminal::size() {
return columns.into(); return columns.into();
} }
DEFAULT_DISPLAY_WIDTH DEFAULT_TERMINAL_WIDTH
} }
pub(crate) fn should_use_color(color_output: ColorOutput) -> bool { pub(crate) fn should_use_color(color_output: ColorOutput) -> bool {
@ -895,6 +895,6 @@ mod tests {
#[test] #[test]
fn test_detect_display_width() { fn test_detect_display_width() {
// Basic smoke test. // Basic smoke test.
assert!(detect_display_width() > 10); assert!(detect_terminal_width() > 10);
} }
} }