Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions src/ansi/iterator.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use core::str::Bytes;

use ansi_term;
use vte;

pub struct AnsiElementIterator<'a> {
// The input bytes
bytes: Bytes<'a>,
Expand Down Expand Up @@ -131,19 +128,16 @@ impl vte::Perform for Performer {
return;
}

match (c, intermediates.get(0)) {
('m', None) => {
if params.is_empty() {
// Attr::Reset;
} else {
self.element = Some(Element::CSI(
ansi_term_style_from_sgr_parameters(params),
0,
0,
));
}
if let ('m', None) = (c, intermediates.get(0)) {
if params.is_empty() {
// Attr::Reset;
} else {
self.element = Some(Element::CSI(
ansi_term_style_from_sgr_parameters(params),
0,
0,
));
}
_ => {}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ansi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub fn measure_text_width(s: &str) -> usize {
// display_width of the result would exceed `display_width`.
pub fn truncate_str<'a, 'b>(s: &'a str, display_width: usize, tail: &'b str) -> Cow<'a, str> {
let items = ansi_strings_iterator(s).collect::<Vec<(&str, bool)>>();
let width = strip_ansi_codes_from_strings_iterator(items.iter().map(|el| *el)).width();
let width = strip_ansi_codes_from_strings_iterator(items.iter().copied()).width();
if width <= display_width {
return Cow::from(s);
}
Expand Down
2 changes: 1 addition & 1 deletion src/bat/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub fn list_languages() -> std::io::Result<()> {

if loop_through {
for lang in languages {
write!(stdout, "{}:{}\n", lang.name, lang.file_extensions.join(","))?;
writeln!(stdout, "{}:{}", lang.name, lang.file_extensions.join(","))?;
}
} else {
let longest = languages
Expand Down
2 changes: 0 additions & 2 deletions src/bat/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ use std::io::{self, Write};
use std::path::PathBuf;
use std::process::{Child, Command, Stdio};

use shell_words;

use super::less::retrieve_less_version;

use crate::config;
Expand Down
1 change: 0 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::collections::{HashMap, HashSet};
use std::ffi::OsString;
use std::path::PathBuf;

use itertools;
use lazy_static::lazy_static;
use structopt::clap::AppSettings::{ColorAlways, ColoredHelp, DeriveDisplayOrder};
use structopt::{clap, StructOpt};
Expand Down
2 changes: 1 addition & 1 deletion src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ lazy_static! {
}

pub fn ansi_16_color_name_to_number(name: &str) -> Option<u8> {
ANSI_16_COLORS.get(name).map(|n| *n)
ANSI_16_COLORS.get(name).copied()
}

fn ansi_16_color_number_to_name(n: u8) -> Option<&'static str> {
Expand Down
11 changes: 4 additions & 7 deletions src/draw.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use std::cmp::max;
use std::io::Write;

use ansi_term;
use box_drawing;

use crate::ansi;
use crate::cli::Width;
use crate::style::Style;
Expand Down Expand Up @@ -85,7 +82,7 @@ pub fn write_boxed_with_underline(
text_style,
decoration_style,
)?;
write!(writer, "\n")?;
writeln!(writer)?;
Ok(())
}

Expand Down Expand Up @@ -169,7 +166,7 @@ fn _write_under_or_over_lined(
let mut write_line: Box<dyn FnMut(&mut dyn Write) -> std::io::Result<()>> =
Box::new(|writer| {
write_horizontal_line(writer, line_width, text_style, decoration_style)?;
write!(writer, "\n")?;
writeln!(writer)?;
Ok(())
});
match underoverline {
Expand Down Expand Up @@ -253,9 +250,9 @@ fn write_boxed_partial(
)
};
let horizontal_edge = horizontal.repeat(box_width);
write!(
writeln!(
writer,
"{}{}\n",
"{}{}",
decoration_style.paint(&horizontal_edge),
decoration_style.paint(down_left),
)?;
Expand Down
3 changes: 1 addition & 2 deletions src/features/line_numbers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::cmp::max;

use ansi_term;
use lazy_static::lazy_static;
use regex::Regex;

Expand Down Expand Up @@ -201,7 +200,7 @@ impl<'a> LineNumbersData<'a> {
}
}

fn parse_line_number_format<'a>(format_string: &'a str) -> LineNumberFormatData<'a> {
fn parse_line_number_format(format_string: &str) -> LineNumberFormatData {
let mut format_data = Vec::new();
let mut offset = 0;

Expand Down
57 changes: 31 additions & 26 deletions src/features/side_by_side.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use itertools::Itertools;
use std::cmp::Ordering;
use syntect::highlighting::Style as SyntectStyle;

use crate::ansi;
Expand Down Expand Up @@ -137,10 +138,10 @@ pub fn paint_zero_lines_side_by_side(
);
// TODO: Avoid doing the superimpose_style_sections work twice.
// HACK: These are getting incremented twice, so knock them back down once.
line_numbers_data.as_mut().map(|d| {
if let Some(d) = line_numbers_data.as_mut() {
d.hunk_minus_line_number -= 1;
d.hunk_plus_line_number -= 1
});
d.hunk_plus_line_number -= 1;
}
right_pad_left_panel_line(
&mut left_panel_line,
left_panel_line_is_empty,
Expand Down Expand Up @@ -335,14 +336,14 @@ fn paint_minus_or_plus_panel_line(
match (state, &state_for_line_numbers_field) {
(s, t) if s == t => {}
(State::HunkPlus(_), State::HunkMinus(_)) => {
line_numbers_data
.as_mut()
.map(|d| d.hunk_minus_line_number -= 1);
if let Some(d) = line_numbers_data.as_mut() {
d.hunk_minus_line_number -= 1;
}
}
(State::HunkMinus(_), State::HunkPlus(_)) => {
line_numbers_data
.as_mut()
.map(|d| d.hunk_plus_line_number -= 1);
if let Some(d) = line_numbers_data.as_mut() {
d.hunk_plus_line_number -= 1;
}
}
_ => unreachable!(),
}
Expand Down Expand Up @@ -380,23 +381,27 @@ fn right_pad_left_panel_line(
// Pad with (maybe painted) spaces to the panel width.
let text_width = ansi::measure_text_width(&panel_line);
let panel_width = config.side_by_side_data.left_panel.width;
if text_width < panel_width {
let fill_style = get_right_fill_style_for_left_panel(
panel_line_is_empty,
line_index,
&diff_style_sections,
state,
background_color_extends_to_terminal_width,
config,
);
panel_line.push_str(
&fill_style
.paint(" ".repeat(panel_width - text_width))
.to_string(),
);
} else if text_width > panel_width {
*panel_line =
ansi::truncate_str(panel_line, panel_width, &config.truncation_symbol).to_string();
match text_width.cmp(&panel_width) {
Ordering::Less => {
let fill_style = get_right_fill_style_for_left_panel(
panel_line_is_empty,
line_index,
&diff_style_sections,
state,
background_color_extends_to_terminal_width,
config,
);
panel_line.push_str(
&fill_style
.paint(" ".repeat(panel_width - text_width))
.to_string(),
);
}
Ordering::Greater => {
*panel_line =
ansi::truncate_str(panel_line, panel_width, &config.truncation_symbol).to_string();
}
std::cmp::Ordering::Equal => {}
};
}

Expand Down
2 changes: 0 additions & 2 deletions src/format.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::borrow::Cow;

use atty;

use crate::config::Config;
use crate::features;

Expand Down
2 changes: 0 additions & 2 deletions src/git_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
use std::path::Path;
use std::process;

use git2;

pub struct GitConfig {
config: git2::Config,
pub enabled: bool,
Expand Down
2 changes: 1 addition & 1 deletion src/options/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub trait GetOptionValue {
return Some(value_function(opt, &git_config));
}
}
return None;
None
}
}

Expand Down
16 changes: 8 additions & 8 deletions src/options/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ pub fn set_options(
// HACK: make minus-line styles have syntax-highlighting iff side-by-side.
if features.contains(&"side-by-side".to_string()) {
let prefix = "normal ";
if !config::user_supplied_option("minus-style", arg_matches) {
if opt.minus_style.starts_with(prefix) {
opt.minus_style = format!("syntax {}", &opt.minus_style[prefix.len()..]);
}
if !config::user_supplied_option("minus-style", arg_matches)
&& opt.minus_style.starts_with(prefix)
{
opt.minus_style = format!("syntax {}", &opt.minus_style[prefix.len()..]);
}
if !config::user_supplied_option("minus-emph-style", arg_matches) {
if opt.minus_emph_style.starts_with(prefix) {
opt.minus_emph_style = format!("syntax {}", &opt.minus_emph_style[prefix.len()..]);
}
if !config::user_supplied_option("minus-emph-style", arg_matches)
&& opt.minus_emph_style.starts_with(prefix)
{
opt.minus_emph_style = format!("syntax {}", &opt.minus_emph_style[prefix.len()..]);
}
}

Expand Down
6 changes: 1 addition & 5 deletions src/paint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,11 +578,7 @@ impl<'a> Painter<'a> {
fn style_sections_contain_more_than_one_style(sections: &[(Style, &str)]) -> bool {
if sections.len() > 1 {
let (first_style, _) = sections[0];
sections
.iter()
.filter(|(style, _)| *style != first_style)
.next()
.is_some()
sections.iter().any(|(style, _)| *style != first_style)
} else {
false
}
Expand Down
9 changes: 6 additions & 3 deletions src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,12 @@ impl Style {
pub fn to_painted_string(&self) -> ansi_term::ANSIGenericString<str> {
self.paint(self.to_string())
}
}

fn to_string(&self) -> String {
impl fmt::Display for Style {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if self.is_raw {
return "raw".to_string();
return write!(f, "raw");
}
let mut words = Vec::<String>::new();
if self.is_omitted {
Expand Down Expand Up @@ -137,7 +139,8 @@ impl Style {
if let Some(color) = self.ansi_term_style.background {
words.push(color::color_to_string(color))
}
words.join(" ")
let style_str = words.join(" ");
write!(f, "{}", style_str)
}
}

Expand Down