Skip to content

Conversation

@neuronull
Copy link

Closes #891

@neuronull
Copy link
Author

(also tested manually)

Copy link
Owner

@sharkdp sharkdp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution.

@sharkdp sharkdp force-pushed the 891_filename_highlighter branch from 3cffcc5 to ee09461 Compare April 11, 2020 08:44
@sharkdp
Copy link
Owner

sharkdp commented Apr 11, 2020

Rebased and fixed merge conflicts.

src/assets.rs Outdated
Comment on lines 213 to 226
(None, InputFile::StdIn(Some(file_name))) => self
.syntax_set
.find_syntax_by_extension(file_name.to_str().unwrap())
.or_else(|| {
self.syntax_set.find_syntax_by_extension(
Path::new(file_name)
.extension()
.and_then(|x| x.to_str())
.unwrap_or(""),
)
})
.or(String::from_utf8(reader.first_line.clone())
.ok()
.and_then(|l| self.syntax_set.find_syntax_by_first_line(&l))),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the fact that the whole logic from the (None, InputFile::Ordinary(ofile)) case above is repeated here. We should extract this into a separate method or try to move both cases into the same match arm.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that makes sense. I chose the helper method approach.

@sharkdp sharkdp force-pushed the 891_filename_highlighter branch from 1e59b36 to 09aef24 Compare April 11, 2020 17:47
@sharkdp sharkdp merged commit a6d9d15 into sharkdp:master Apr 21, 2020
@sharkdp
Copy link
Owner

sharkdp commented Apr 21, 2020

Thank you for the updates!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When reading from stdin, bat should use --file-name (if present) to pick the syntax highlighter

2 participants