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 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 {
let lhs_line_novel = highlight_as_novel(
*lhs_line_num,
@ -594,7 +594,7 @@ mod tests {
use super::*;
use crate::{
options::DEFAULT_DISPLAY_WIDTH,
options::DEFAULT_TERMINAL_WIDTH,
parse::guess_language::Language,
syntax::{AtomKind, MatchKind, TokenKind},
};
@ -602,7 +602,7 @@ mod tests {
#[test]
fn test_width_calculations() {
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.rhs_line_nums_width, 3);
@ -611,7 +611,7 @@ mod tests {
#[test]
fn test_format_missing_line_num() {
let source_dims = SourceDimensions::new(
DEFAULT_DISPLAY_WIDTH,
DEFAULT_TERMINAL_WIDTH,
&[
(Some(0.into()), Some(0.into())),
(Some(1.into()), Some(1.into())),

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