mirror of
https://github.com/sharkdp/bat.git
synced 2024-11-22 15:53:29 +01:00
Allow for non-unicode filenames, closes #225
This commit is contained in:
parent
e98f34b1e8
commit
7779d9f622
@ -9,7 +9,7 @@ use console::Term;
|
|||||||
use std::process;
|
use std::process;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let files = std::env::args().skip(1).collect::<Vec<_>>();
|
let files = std::env::args_os().skip(1).collect::<Vec<_>>();
|
||||||
|
|
||||||
if files.is_empty() {
|
if files.is_empty() {
|
||||||
eprintln!("No input files specified");
|
eprintln!("No input files specified");
|
||||||
|
@ -227,7 +227,7 @@ impl App {
|
|||||||
|
|
||||||
fn files(&self) -> Vec<InputFile> {
|
fn files(&self) -> Vec<InputFile> {
|
||||||
self.matches
|
self.matches
|
||||||
.values_of("FILE")
|
.values_of_os("FILE")
|
||||||
.map(|values| {
|
.map(|values| {
|
||||||
values
|
values
|
||||||
.map(|filename| {
|
.map(|filename| {
|
||||||
|
@ -13,6 +13,7 @@ use std::io;
|
|||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process;
|
use std::process;
|
||||||
|
use std::ffi::OsStr;
|
||||||
|
|
||||||
use ansi_term::Colour::Green;
|
use ansi_term::Colour::Green;
|
||||||
use ansi_term::Style;
|
use ansi_term::Style;
|
||||||
@ -160,7 +161,7 @@ fn run() -> Result<bool> {
|
|||||||
Ok(true)
|
Ok(true)
|
||||||
} else {
|
} else {
|
||||||
let mut config = app.config()?;
|
let mut config = app.config()?;
|
||||||
config.files = vec![InputFile::Ordinary(&"cache")];
|
config.files = vec![InputFile::Ordinary(OsStr::new("cache"))];
|
||||||
|
|
||||||
run_controller(&config)
|
run_controller(&config)
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
use git2::{DiffOptions, IntoCString, Repository};
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
use std::ffi::OsStr;
|
||||||
|
|
||||||
|
use git2::{DiffOptions, IntoCString, Repository};
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub enum LineChange {
|
pub enum LineChange {
|
||||||
@ -13,7 +15,7 @@ pub enum LineChange {
|
|||||||
|
|
||||||
pub type LineChanges = HashMap<u32, LineChange>;
|
pub type LineChanges = HashMap<u32, LineChange>;
|
||||||
|
|
||||||
pub fn get_git_diff(filename: &str) -> Option<LineChanges> {
|
pub fn get_git_diff(filename: &OsStr) -> Option<LineChanges> {
|
||||||
let repo = Repository::discover(&filename).ok()?;
|
let repo = Repository::discover(&filename).ok()?;
|
||||||
|
|
||||||
let repo_path_absolute = fs::canonicalize(repo.workdir()?).ok()?;
|
let repo_path_absolute = fs::canonicalize(repo.workdir()?).ok()?;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{self, BufRead, BufReader};
|
use std::io::{self, BufRead, BufReader};
|
||||||
|
use std::ffi::OsStr;
|
||||||
|
|
||||||
use content_inspector::{self, ContentType};
|
use content_inspector::{self, ContentType};
|
||||||
|
|
||||||
@ -54,7 +55,7 @@ impl<'a> InputFileReader<'a> {
|
|||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub enum InputFile<'a> {
|
pub enum InputFile<'a> {
|
||||||
StdIn,
|
StdIn,
|
||||||
Ordinary(&'a str),
|
Ordinary(&'a OsStr),
|
||||||
ThemePreviewFile,
|
ThemePreviewFile,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,10 +64,10 @@ impl<'a> InputFile<'a> {
|
|||||||
match self {
|
match self {
|
||||||
InputFile::StdIn => Ok(InputFileReader::new(stdin.lock())),
|
InputFile::StdIn => Ok(InputFileReader::new(stdin.lock())),
|
||||||
InputFile::Ordinary(filename) => {
|
InputFile::Ordinary(filename) => {
|
||||||
let file = File::open(filename).map_err(|e| format!("'{}': {}", filename, e))?;
|
let file = File::open(filename).map_err(|e| format!("'{}': {}", filename.to_string_lossy(), e))?;
|
||||||
|
|
||||||
if file.metadata()?.is_dir() {
|
if file.metadata()?.is_dir() {
|
||||||
return Err(format!("'{}' is a directory.", filename).into());
|
return Err(format!("'{}' is a directory.", filename.to_string_lossy()).into());
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(InputFileReader::new(BufReader::new(file)))
|
Ok(InputFileReader::new(BufReader::new(file)))
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::vec::Vec;
|
use std::vec::Vec;
|
||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use ansi_term::Colour::{Fixed, Green, Red, Yellow};
|
use ansi_term::Colour::{Fixed, Green, Red, Yellow};
|
||||||
use ansi_term::Style;
|
use ansi_term::Style;
|
||||||
@ -225,7 +226,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
|
|||||||
if !self.config.output_components.header() {
|
if !self.config.output_components.header() {
|
||||||
if Some(ContentType::BINARY) == self.content_type && !self.config.show_nonprintable {
|
if Some(ContentType::BINARY) == self.content_type && !self.config.show_nonprintable {
|
||||||
let input = match file {
|
let input = match file {
|
||||||
InputFile::Ordinary(filename) => format!("file '{}'", filename),
|
InputFile::Ordinary(filename) => format!("file '{}'", filename.to_string_lossy()),
|
||||||
_ => "STDIN".into(),
|
_ => "STDIN".into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -261,8 +262,8 @@ impl<'a> Printer for InteractivePrinter<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let (prefix, name) = match file {
|
let (prefix, name) = match file {
|
||||||
InputFile::Ordinary(filename) => ("File: ", filename),
|
InputFile::Ordinary(filename) => ("File: ", filename.to_string_lossy()),
|
||||||
_ => ("", "STDIN"),
|
_ => ("", Cow::from("STDIN")),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mode = match self.content_type {
|
let mode = match self.content_type {
|
||||||
|
Loading…
Reference in New Issue
Block a user