mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-12-26 01:57:32 +00:00
Move colours module into output
This commit moves the colours module to be a sub-module of the output one. This makes sense because finding which colour a certain file should be is only done during output, and (I think) the only places that the `Colours` struct's fields are ever queried is from the output module. The only casualty was that the `file_colour` from the filetype module had to be moved, as determining colours is no longer part of that module - only determining filetype is. So it now reflects its name!
This commit is contained in:
parent
15cd67abe6
commit
1b3492ce45
@ -1,31 +1,7 @@
|
||||
use ansi_term::Style;
|
||||
|
||||
use file::File;
|
||||
use colours::Colours;
|
||||
|
||||
|
||||
pub fn file_colour(colours: &Colours, file: &File) -> Style {
|
||||
match file {
|
||||
f if f.is_directory() => colours.filetypes.directory,
|
||||
f if f.is_executable_file() => colours.filetypes.executable,
|
||||
f if f.is_link() => colours.filetypes.symlink,
|
||||
f if !f.is_file() => colours.filetypes.special,
|
||||
f if f.is_immediate() => colours.filetypes.immediate,
|
||||
f if f.is_image() => colours.filetypes.image,
|
||||
f if f.is_video() => colours.filetypes.video,
|
||||
f if f.is_music() => colours.filetypes.music,
|
||||
f if f.is_lossless() => colours.filetypes.lossless,
|
||||
f if f.is_crypto() => colours.filetypes.crypto,
|
||||
f if f.is_document() => colours.filetypes.document,
|
||||
f if f.is_compressed() => colours.filetypes.compressed,
|
||||
f if f.is_temp() => colours.filetypes.temp,
|
||||
f if f.is_compiled() => colours.filetypes.compiled,
|
||||
_ => colours.filetypes.normal,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
trait FileTypes {
|
||||
pub trait FileTypes {
|
||||
fn is_immediate(&self) -> bool;
|
||||
fn is_image(&self) -> bool;
|
||||
fn is_video(&self) -> bool;
|
||||
|
@ -26,7 +26,6 @@ use dir::Dir;
|
||||
use file::File;
|
||||
use options::{Options, View};
|
||||
|
||||
mod colours;
|
||||
mod dir;
|
||||
mod feature;
|
||||
mod file;
|
||||
|
@ -7,10 +7,10 @@ use std::os::unix::fs::MetadataExt;
|
||||
use getopts;
|
||||
use natord;
|
||||
|
||||
use colours::Colours;
|
||||
use feature::xattr;
|
||||
use file::File;
|
||||
use output::{Grid, Details, GridDetails, Lines};
|
||||
use output::Colours;
|
||||
use output::column::{Columns, TimeTypes, SizeFormat};
|
||||
use term::dimensions;
|
||||
|
||||
|
@ -118,12 +118,12 @@ use std::string::ToString;
|
||||
use std::ops::Add;
|
||||
use std::iter::repeat;
|
||||
|
||||
use colours::Colours;
|
||||
use dir::Dir;
|
||||
use feature::xattr::{Attribute, FileAttributes};
|
||||
use file::fields as f;
|
||||
use file::File;
|
||||
use options::{FileFilter, RecurseOptions};
|
||||
use output::colours::Colours;
|
||||
use output::column::{Alignment, Column, Columns, SizeFormat};
|
||||
use output::cell::{TextCell, DisplayWidth};
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
use colours::Colours;
|
||||
use file::File;
|
||||
use filetype::file_colour;
|
||||
use output::DisplayWidth;
|
||||
|
||||
use term_grid as grid;
|
||||
|
||||
use file::File;
|
||||
use output::DisplayWidth;
|
||||
use output::colours::Colours;
|
||||
use super::file_colour;
|
||||
|
||||
|
||||
#[derive(PartialEq, Debug, Copy, Clone)]
|
||||
pub struct Grid {
|
||||
|
@ -1,9 +1,9 @@
|
||||
use colours::Colours;
|
||||
use file::File;
|
||||
|
||||
use ansi_term::ANSIStrings;
|
||||
|
||||
use file::File;
|
||||
|
||||
use super::filename;
|
||||
use super::colours::Colours;
|
||||
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
|
@ -1,14 +1,13 @@
|
||||
use ansi_term::Style;
|
||||
|
||||
use colours::Colours;
|
||||
use file::File;
|
||||
use filetype::file_colour;
|
||||
|
||||
pub use self::cell::{TextCell, TextCellContents, DisplayWidth};
|
||||
pub use self::colours::Colours;
|
||||
pub use self::details::Details;
|
||||
pub use self::grid_details::GridDetails;
|
||||
pub use self::grid::Grid;
|
||||
pub use self::lines::Lines;
|
||||
pub use self::grid_details::GridDetails;
|
||||
|
||||
mod grid;
|
||||
pub mod details;
|
||||
@ -16,7 +15,7 @@ mod lines;
|
||||
mod grid_details;
|
||||
pub mod column;
|
||||
mod cell;
|
||||
|
||||
mod colours;
|
||||
|
||||
pub fn filename(file: File, colours: &Colours, links: bool) -> TextCellContents {
|
||||
if links && file.is_link() {
|
||||
@ -49,3 +48,25 @@ fn symlink_filename(file: File, colours: &Colours) -> TextCellContents {
|
||||
].into(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn file_colour(colours: &Colours, file: &File) -> Style {
|
||||
use filetype::FileTypes;
|
||||
|
||||
match file {
|
||||
f if f.is_directory() => colours.filetypes.directory,
|
||||
f if f.is_executable_file() => colours.filetypes.executable,
|
||||
f if f.is_link() => colours.filetypes.symlink,
|
||||
f if !f.is_file() => colours.filetypes.special,
|
||||
f if f.is_immediate() => colours.filetypes.immediate,
|
||||
f if f.is_image() => colours.filetypes.image,
|
||||
f if f.is_video() => colours.filetypes.video,
|
||||
f if f.is_music() => colours.filetypes.music,
|
||||
f if f.is_lossless() => colours.filetypes.lossless,
|
||||
f if f.is_crypto() => colours.filetypes.crypto,
|
||||
f if f.is_document() => colours.filetypes.document,
|
||||
f if f.is_compressed() => colours.filetypes.compressed,
|
||||
f if f.is_temp() => colours.filetypes.temp,
|
||||
f if f.is_compiled() => colours.filetypes.compiled,
|
||||
_ => colours.filetypes.normal,
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user