mirror of
https://github.com/sharkdp/bat.git
synced 2025-02-21 12:28:30 +00:00
Improve iterator usage
This commit is contained in:
parent
372e42f350
commit
7956485e37
@ -351,7 +351,7 @@ impl HighlightingAssets {
|
|||||||
let file_path = Path::new(file_name);
|
let file_path = Path::new(file_name);
|
||||||
let mut syntax = None;
|
let mut syntax = None;
|
||||||
if let Some(file_str) = file_path.to_str() {
|
if let Some(file_str) = file_path.to_str() {
|
||||||
for suffix in IGNORED_SUFFIXES.iter() {
|
for suffix in &IGNORED_SUFFIXES {
|
||||||
if let Some(stripped_filename) = file_str.strip_suffix(suffix) {
|
if let Some(stripped_filename) = file_str.strip_suffix(suffix) {
|
||||||
syntax = self.get_extension_syntax(OsStr::new(stripped_filename))?;
|
syntax = self.get_extension_syntax(OsStr::new(stripped_filename))?;
|
||||||
break;
|
break;
|
||||||
|
@ -91,7 +91,7 @@ pub fn get_languages(config: &Config) -> Result<String> {
|
|||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
// Handling of file-extension conflicts, see issue #1076
|
// Handling of file-extension conflicts, see issue #1076
|
||||||
for lang in languages.iter_mut() {
|
for lang in &mut languages {
|
||||||
let lang_name = lang.name.clone();
|
let lang_name = lang.name.clone();
|
||||||
lang.file_extensions.retain(|extension| {
|
lang.file_extensions.retain(|extension| {
|
||||||
// The 'extension' variable is not certainly a real extension.
|
// The 'extension' variable is not certainly a real extension.
|
||||||
@ -115,7 +115,7 @@ pub fn get_languages(config: &Config) -> Result<String> {
|
|||||||
|
|
||||||
let configured_languages = get_syntax_mapping_to_paths(config.syntax_mapping.mappings());
|
let configured_languages = get_syntax_mapping_to_paths(config.syntax_mapping.mappings());
|
||||||
|
|
||||||
for lang in languages.iter_mut() {
|
for lang in &mut languages {
|
||||||
if let Some(additional_paths) = configured_languages.get(lang.name.as_str()) {
|
if let Some(additional_paths) = configured_languages.get(lang.name.as_str()) {
|
||||||
lang.file_extensions
|
lang.file_extensions
|
||||||
.extend(additional_paths.iter().cloned());
|
.extend(additional_paths.iter().cloned());
|
||||||
|
@ -175,8 +175,8 @@ impl<'b> Controller<'b> {
|
|||||||
let mut line_ranges: Vec<LineRange> = vec![];
|
let mut line_ranges: Vec<LineRange> = vec![];
|
||||||
|
|
||||||
if let Some(line_changes) = line_changes {
|
if let Some(line_changes) = line_changes {
|
||||||
for line in line_changes.keys() {
|
for &line in line_changes.keys() {
|
||||||
let line = *line as usize;
|
let line = line as usize;
|
||||||
line_ranges.push(LineRange::new(line - context, line + context));
|
line_ranges.push(LineRange::new(line - context, line + context));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -420,8 +420,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
|
|||||||
let decorations = self
|
let decorations = self
|
||||||
.decorations
|
.decorations
|
||||||
.iter()
|
.iter()
|
||||||
.map(|d| d.generate(line_number, false, self))
|
.map(|d| d.generate(line_number, false, self));
|
||||||
.collect::<Vec<_>>();
|
|
||||||
|
|
||||||
for deco in decorations {
|
for deco in decorations {
|
||||||
write!(handle, "{} ", deco.text)?;
|
write!(handle, "{} ", deco.text)?;
|
||||||
@ -435,7 +434,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
|
|||||||
let colored_output = self.config.colored_output;
|
let colored_output = self.config.colored_output;
|
||||||
let italics = self.config.use_italic_text;
|
let italics = self.config.use_italic_text;
|
||||||
|
|
||||||
for &(style, region) in regions.iter() {
|
for &(style, region) in ®ions {
|
||||||
let text = &*self.preprocess(region, &mut cursor_total);
|
let text = &*self.preprocess(region, &mut cursor_total);
|
||||||
let text_trimmed = text.trim_end_matches(|c| c == '\r' || c == '\n');
|
let text_trimmed = text.trim_end_matches(|c| c == '\r' || c == '\n');
|
||||||
write!(
|
write!(
|
||||||
@ -472,7 +471,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
|
|||||||
writeln!(handle)?;
|
writeln!(handle)?;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for &(style, region) in regions.iter() {
|
for &(style, region) in ®ions {
|
||||||
let ansi_iterator = AnsiCodeIterator::new(region);
|
let ansi_iterator = AnsiCodeIterator::new(region);
|
||||||
let mut ansi_prefix: String = String::new();
|
let mut ansi_prefix: String = String::new();
|
||||||
for chunk in ansi_iterator {
|
for chunk in ansi_iterator {
|
||||||
|
@ -81,7 +81,7 @@ impl<'a> SyntaxMapping<'a> {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
for glob in [
|
for glob in &[
|
||||||
"**/systemd/**/*.conf",
|
"**/systemd/**/*.conf",
|
||||||
"**/systemd/**/*.example",
|
"**/systemd/**/*.example",
|
||||||
"*.automount",
|
"*.automount",
|
||||||
@ -100,9 +100,7 @@ impl<'a> SyntaxMapping<'a> {
|
|||||||
"*.swap",
|
"*.swap",
|
||||||
"*.target",
|
"*.target",
|
||||||
"*.timer",
|
"*.timer",
|
||||||
]
|
] {
|
||||||
.iter()
|
|
||||||
{
|
|
||||||
mapping.insert(glob, MappingTarget::MapTo("INI")).unwrap();
|
mapping.insert(glob, MappingTarget::MapTo("INI")).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user