|
@@ -6,6 +6,7 @@ use column::{Column, Permissions, FileName, FileSize, User, Group};
|
|
|
use format::{format_metric_bytes, format_IEC_bytes};
|
|
use format::{format_metric_bytes, format_IEC_bytes};
|
|
|
use unix::{get_user_name, get_group_name};
|
|
use unix::{get_user_name, get_group_name};
|
|
|
use sort::SortPart;
|
|
use sort::SortPart;
|
|
|
|
|
+use dir::Dir;
|
|
|
|
|
|
|
|
static IMAGE_TYPES: &'static [&'static str] = &[
|
|
static IMAGE_TYPES: &'static [&'static str] = &[
|
|
|
"png", "jpeg", "jpg", "gif", "bmp", "tiff", "tif",
|
|
"png", "jpeg", "jpg", "gif", "bmp", "tiff", "tif",
|
|
@@ -37,6 +38,7 @@ static TEMP_TYPES: &'static [&'static str] = &[
|
|
|
static CRYPTO_TYPES: &'static [&'static str] = &[
|
|
static CRYPTO_TYPES: &'static [&'static str] = &[
|
|
|
"asc", "gpg", "sig", "signature", "pgp" ];
|
|
"asc", "gpg", "sig", "signature", "pgp" ];
|
|
|
|
|
|
|
|
|
|
+
|
|
|
// Instead of working with Rust's Paths, we have our own File object
|
|
// Instead of working with Rust's Paths, we have our own File object
|
|
|
// that holds the Path and various cached information. Each file is
|
|
// that holds the Path and various cached information. Each file is
|
|
|
// definitely going to have its filename used at least once, its stat
|
|
// definitely going to have its filename used at least once, its stat
|
|
@@ -46,6 +48,7 @@ static CRYPTO_TYPES: &'static [&'static str] = &[
|
|
|
|
|
|
|
|
pub struct File<'a> {
|
|
pub struct File<'a> {
|
|
|
pub name: &'a str,
|
|
pub name: &'a str,
|
|
|
|
|
+ pub dir: &'a Dir<'a>,
|
|
|
pub ext: Option<&'a str>,
|
|
pub ext: Option<&'a str>,
|
|
|
pub path: &'a Path,
|
|
pub path: &'a Path,
|
|
|
pub stat: io::FileStat,
|
|
pub stat: io::FileStat,
|
|
@@ -53,7 +56,7 @@ pub struct File<'a> {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
impl<'a> File<'a> {
|
|
impl<'a> File<'a> {
|
|
|
- pub fn from_path(path: &'a Path) -> File<'a> {
|
|
|
|
|
|
|
+ pub fn from_path(path: &'a Path, parent: &'a Dir) -> File<'a> {
|
|
|
// Getting the string from a filename fails whenever it's not
|
|
// Getting the string from a filename fails whenever it's not
|
|
|
// UTF-8 representable - just assume it is for now.
|
|
// UTF-8 representable - just assume it is for now.
|
|
|
let filename: &str = path.filename_str().unwrap();
|
|
let filename: &str = path.filename_str().unwrap();
|
|
@@ -68,6 +71,7 @@ impl<'a> File<'a> {
|
|
|
|
|
|
|
|
return File {
|
|
return File {
|
|
|
path: path,
|
|
path: path,
|
|
|
|
|
+ dir: parent,
|
|
|
stat: stat,
|
|
stat: stat,
|
|
|
name: filename,
|
|
name: filename,
|
|
|
ext: File::ext(filename),
|
|
ext: File::ext(filename),
|
|
@@ -90,40 +94,36 @@ impl<'a> File<'a> {
|
|
|
fn is_tmpfile(&self) -> bool {
|
|
fn is_tmpfile(&self) -> bool {
|
|
|
self.name.ends_with("~") || (self.name.starts_with("#") && self.name.ends_with("#"))
|
|
self.name.ends_with("~") || (self.name.starts_with("#") && self.name.ends_with("#"))
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- fn with_extension(&self, newext: &'static str) -> String {
|
|
|
|
|
- format!("{}.{}", self.path.filestem_str().unwrap(), newext)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// Highlight the compiled versions of files. Some of them, like .o,
|
|
// Highlight the compiled versions of files. Some of them, like .o,
|
|
|
// get special highlighting when they're alone because there's no
|
|
// get special highlighting when they're alone because there's no
|
|
|
// point in existing without their source. Others can be perfectly
|
|
// point in existing without their source. Others can be perfectly
|
|
|
// content without their source files, such as how .js is valid
|
|
// content without their source files, such as how .js is valid
|
|
|
// without a .coffee.
|
|
// without a .coffee.
|
|
|
|
|
|
|
|
- fn get_source_files(&self) -> Vec<String> {
|
|
|
|
|
|
|
+ fn get_source_files(&self) -> Vec<Path> {
|
|
|
match self.ext {
|
|
match self.ext {
|
|
|
- Some("class") => vec![self.with_extension("java")], // Java
|
|
|
|
|
- Some("elc") => vec![self.name.chop()], // Emacs Lisp
|
|
|
|
|
- Some("hi") => vec![self.with_extension("hs")], // Haskell
|
|
|
|
|
- Some("o") => vec![self.with_extension("c"), self.with_extension("cpp")], // C, C++
|
|
|
|
|
- Some("pyc") => vec![self.name.chop()], // Python
|
|
|
|
|
|
|
+ Some("class") => vec![self.path.with_extension("java")], // Java
|
|
|
|
|
+ Some("elc") => vec![self.path.with_extension("el")], // Emacs Lisp
|
|
|
|
|
+ Some("hi") => vec![self.path.with_extension("hs")], // Haskell
|
|
|
|
|
+ Some("o") => vec![self.path.with_extension("c"), self.path.with_extension("cpp")], // C, C++
|
|
|
|
|
+ Some("pyc") => vec![self.path.with_extension("py")], // Python
|
|
|
_ => vec![],
|
|
_ => vec![],
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- fn get_source_files_usual(&self) -> Vec<String> {
|
|
|
|
|
|
|
+ fn get_source_files_usual(&self) -> Vec<Path> {
|
|
|
match self.ext {
|
|
match self.ext {
|
|
|
- Some("js") => vec![self.with_extension("coffee"), self.with_extension("ts")], // CoffeeScript, TypeScript
|
|
|
|
|
- Some("css") => vec![self.with_extension("sass"), self.with_extension("less")], // SASS, Less
|
|
|
|
|
|
|
+ Some("js") => vec![self.path.with_extension("coffee"), self.path.with_extension("ts")], // CoffeeScript, TypeScript
|
|
|
|
|
+ Some("css") => vec![self.path.with_extension("sass"), self.path.with_extension("less")], // SASS, Less
|
|
|
|
|
|
|
|
- Some("aux") => vec![self.with_extension("tex")], // TeX: auxiliary file
|
|
|
|
|
- Some("bbl") => vec![self.with_extension("tex")], // BibTeX bibliography file
|
|
|
|
|
- Some("blg") => vec![self.with_extension("tex")], // BibTeX log file
|
|
|
|
|
- Some("lof") => vec![self.with_extension("tex")], // list of figures
|
|
|
|
|
- Some("log") => vec![self.with_extension("tex")], // TeX log file
|
|
|
|
|
- Some("lot") => vec![self.with_extension("tex")], // list of tables
|
|
|
|
|
- Some("toc") => vec![self.with_extension("tex")], // table of contents
|
|
|
|
|
|
|
+ Some("aux") => vec![self.path.with_extension("tex")], // TeX: auxiliary file
|
|
|
|
|
+ Some("bbl") => vec![self.path.with_extension("tex")], // BibTeX bibliography file
|
|
|
|
|
+ Some("blg") => vec![self.path.with_extension("tex")], // BibTeX log file
|
|
|
|
|
+ Some("lof") => vec![self.path.with_extension("tex")], // list of figures
|
|
|
|
|
+ Some("log") => vec![self.path.with_extension("tex")], // TeX log file
|
|
|
|
|
+ Some("lot") => vec![self.path.with_extension("tex")], // list of tables
|
|
|
|
|
+ Some("toc") => vec![self.path.with_extension("tex")], // table of contents
|
|
|
|
|
|
|
|
_ => vec![],
|
|
_ => vec![],
|
|
|
}
|
|
}
|
|
@@ -213,14 +213,14 @@ impl<'a> File<'a> {
|
|
|
let source_files = self.get_source_files();
|
|
let source_files = self.get_source_files();
|
|
|
if source_files.len() == 0 {
|
|
if source_files.len() == 0 {
|
|
|
let source_files_usual = self.get_source_files_usual();
|
|
let source_files_usual = self.get_source_files_usual();
|
|
|
- if source_files_usual.iter().any(|filename| Path::new(format!("{}/{}", self.path.dirname_str().unwrap(), filename)).exists()) {
|
|
|
|
|
|
|
+ if source_files_usual.iter().any(|path| self.dir.contains(path)) {
|
|
|
Fixed(244).normal()
|
|
Fixed(244).normal()
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
|
Plain
|
|
Plain
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- else if source_files.iter().any(|filename| Path::new(format!("{}/{}", self.path.dirname_str().unwrap(), filename)).exists()) {
|
|
|
|
|
|
|
+ else if source_files.iter().any(|path| self.dir.contains(path)) {
|
|
|
Fixed(244).normal()
|
|
Fixed(244).normal()
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
@@ -256,13 +256,3 @@ impl<'a> File<'a> {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-trait Chop {
|
|
|
|
|
- fn chop(&self) -> String;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-impl<'a> Chop for &'a str {
|
|
|
|
|
- fn chop(&self) -> String {
|
|
|
|
|
- self.slice_to(self.len() - 1).to_string()
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|