Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use --file-name to detect syntax highlighting #892

Merged
merged 12 commits into from
Apr 21, 2020

Conversation

neuronull
Copy link
Contributor

Closes #891

@neuronull
Copy link
Contributor 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.

src/assets.rs Outdated Show resolved Hide resolved
@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
Contributor 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.

src/assets.rs Outdated Show resolved Hide resolved
src/printer.rs Outdated Show resolved Hide resolved
src/assets.rs Outdated Show resolved Hide resolved
@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