mirror of
https://github.com/Llewellynvdm/exa.git
synced 2025-02-04 19:48:25 +00:00
Create info module with business logic routines
Currently these routines number two: file type checking based on a file's name, and source file checking, also based on the file's name.
This commit is contained in:
parent
b83844f384
commit
fae0f3874e
@ -310,41 +310,6 @@ impl<'dir> File<'dir> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// For this file, return a vector of alternate file paths that, if any of
|
|
||||||
/// them exist, mean that *this* file should be coloured as `Compiled`.
|
|
||||||
///
|
|
||||||
/// The point of this is to highlight compiled files such as `foo.o` when
|
|
||||||
/// their source file `foo.c` exists in the same directory. It's too
|
|
||||||
/// dangerous to highlight *all* compiled, so the paths in this vector
|
|
||||||
/// are checked for existence first: for example, `foo.js` is perfectly
|
|
||||||
/// valid without `foo.coffee`.
|
|
||||||
pub fn get_source_files(&self) -> Vec<PathBuf> {
|
|
||||||
if let Some(ref ext) = self.ext {
|
|
||||||
match &ext[..] {
|
|
||||||
"class" => vec![self.path.with_extension("java")], // Java
|
|
||||||
"css" => vec![self.path.with_extension("sass"), self.path.with_extension("less")], // SASS, Less
|
|
||||||
"elc" => vec![self.path.with_extension("el")], // Emacs Lisp
|
|
||||||
"hi" => vec![self.path.with_extension("hs")], // Haskell
|
|
||||||
"js" => vec![self.path.with_extension("coffee"), self.path.with_extension("ts")], // CoffeeScript, TypeScript
|
|
||||||
"o" => vec![self.path.with_extension("c"), self.path.with_extension("cpp")], // C, C++
|
|
||||||
"pyc" => vec![self.path.with_extension("py")], // Python
|
|
||||||
|
|
||||||
"aux" => vec![self.path.with_extension("tex")], // TeX: auxiliary file
|
|
||||||
"bbl" => vec![self.path.with_extension("tex")], // BibTeX bibliography file
|
|
||||||
"blg" => vec![self.path.with_extension("tex")], // BibTeX log file
|
|
||||||
"lof" => vec![self.path.with_extension("tex")], // TeX list of figures
|
|
||||||
"log" => vec![self.path.with_extension("tex")], // TeX log file
|
|
||||||
"lot" => vec![self.path.with_extension("tex")], // TeX list of tables
|
|
||||||
"toc" => vec![self.path.with_extension("tex")], // TeX table of contents
|
|
||||||
|
|
||||||
_ => vec![], // No source files if none of the above
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
vec![] // No source files if there's no extension, either!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Whether this file's extension is any of the strings that get passed in.
|
/// Whether this file's extension is any of the strings that get passed in.
|
||||||
///
|
///
|
||||||
/// This will always return `false` if the file has no extension.
|
/// This will always return `false` if the file has no extension.
|
||||||
|
@ -2,7 +2,6 @@ mod dir;
|
|||||||
pub use self::dir::Dir;
|
pub use self::dir::Dir;
|
||||||
|
|
||||||
mod file;
|
mod file;
|
||||||
pub mod filetype;
|
|
||||||
pub use self::file::File;
|
pub use self::file::File;
|
||||||
|
|
||||||
pub mod feature;
|
pub mod feature;
|
||||||
|
@ -1,7 +1,17 @@
|
|||||||
|
//! Tests for various types of file (video, image, compressed, etc).
|
||||||
|
//!
|
||||||
|
//! Currently this is dependent on the file’s name and extension, because
|
||||||
|
//! those are the only metadata that we have access to without reading the
|
||||||
|
//! file’s contents.
|
||||||
|
|
||||||
use fs::File;
|
use fs::File;
|
||||||
|
|
||||||
|
|
||||||
impl<'_> File<'_> {
|
impl<'_> File<'_> {
|
||||||
|
|
||||||
|
/// An “immediate” file is something that can be run or activated somehow
|
||||||
|
/// in order to kick off the build of a project. It’s usually only present
|
||||||
|
/// in directories full of source code.
|
||||||
pub fn is_immediate(&self) -> bool {
|
pub fn is_immediate(&self) -> bool {
|
||||||
self.name.starts_with("README") || self.name_is_one_of( &[
|
self.name.starts_with("README") || self.name_is_one_of( &[
|
||||||
"Makefile", "Cargo.toml", "SConstruct", "CMakeLists.txt",
|
"Makefile", "Cargo.toml", "SConstruct", "CMakeLists.txt",
|
||||||
@ -32,6 +42,7 @@ impl<'_> File<'_> {
|
|||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Lossless music, rather than any other kind of data...
|
||||||
pub fn is_lossless(&self) -> bool {
|
pub fn is_lossless(&self) -> bool {
|
||||||
self.extension_is_one_of( &[
|
self.extension_is_one_of( &[
|
||||||
"alac", "ape", "flac", "wav",
|
"alac", "ape", "flac", "wav",
|
7
src/info/mod.rs
Normal file
7
src/info/mod.rs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
//! The "info" module contains routines that aren't about probing the
|
||||||
|
//! filesystem nor displaying output to the user, but are internal "business
|
||||||
|
//! logic” routines that are performed on a file’s already-read metadata.
|
||||||
|
//! (This counts the file name as metadata.)
|
||||||
|
|
||||||
|
mod filetype;
|
||||||
|
mod sources;
|
42
src/info/sources.rs
Normal file
42
src/info/sources.rs
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use fs::File;
|
||||||
|
|
||||||
|
|
||||||
|
impl<'_> File<'_> {
|
||||||
|
|
||||||
|
/// For this file, return a vector of alternate file paths that, if any of
|
||||||
|
/// them exist, mean that *this* file should be coloured as “compiled”.
|
||||||
|
///
|
||||||
|
/// The point of this is to highlight compiled files such as `foo.o` when
|
||||||
|
/// their source file `foo.c` exists in the same directory. It's too
|
||||||
|
/// dangerous to highlight *all* compiled, so the paths in this vector
|
||||||
|
/// are checked for existence first: for example, `foo.js` is perfectly
|
||||||
|
/// valid without `foo.coffee`.
|
||||||
|
pub fn get_source_files(&self) -> Vec<PathBuf> {
|
||||||
|
if let Some(ref ext) = self.ext {
|
||||||
|
match &ext[..] {
|
||||||
|
"class" => vec![self.path.with_extension("java")], // Java
|
||||||
|
"css" => vec![self.path.with_extension("sass"), self.path.with_extension("less")], // SASS, Less
|
||||||
|
"elc" => vec![self.path.with_extension("el")], // Emacs Lisp
|
||||||
|
"hi" => vec![self.path.with_extension("hs")], // Haskell
|
||||||
|
"js" => vec![self.path.with_extension("coffee"), self.path.with_extension("ts")], // CoffeeScript, TypeScript
|
||||||
|
"o" => vec![self.path.with_extension("c"), self.path.with_extension("cpp")], // C, C++
|
||||||
|
"pyc" => vec![self.path.with_extension("py")], // Python
|
||||||
|
|
||||||
|
"aux" => vec![self.path.with_extension("tex")], // TeX: auxiliary file
|
||||||
|
"bbl" => vec![self.path.with_extension("tex")], // BibTeX bibliography file
|
||||||
|
"blg" => vec![self.path.with_extension("tex")], // BibTeX log file
|
||||||
|
"lof" => vec![self.path.with_extension("tex")], // TeX list of figures
|
||||||
|
"log" => vec![self.path.with_extension("tex")], // TeX log file
|
||||||
|
"lot" => vec![self.path.with_extension("tex")], // TeX list of tables
|
||||||
|
"toc" => vec![self.path.with_extension("tex")], // TeX table of contents
|
||||||
|
|
||||||
|
_ => vec![], // No source files if none of the above
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
vec![] // No source files if there's no extension, either!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -27,6 +27,7 @@ use fs::{Dir, File};
|
|||||||
use options::{Options, View};
|
use options::{Options, View};
|
||||||
|
|
||||||
mod fs;
|
mod fs;
|
||||||
|
mod info;
|
||||||
mod options;
|
mod options;
|
||||||
mod output;
|
mod output;
|
||||||
mod term;
|
mod term;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user