|
|
|
@ -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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|