mirror of
https://github.com/eza-community/eza.git
synced 2025-08-04 17:08:42 +00:00
refactor: clippy lints
Signed-off-by: Christina Sørensen <ces@fem.gg>
This commit is contained in:
parent
765807b7ee
commit
718d0f7898
27 changed files with 95 additions and 99 deletions
|
@ -9,8 +9,8 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||||
pub fn criterion_benchmark(c: &mut Criterion) {
|
pub fn criterion_benchmark(c: &mut Criterion) {
|
||||||
c.bench_function("logger", |b| {
|
c.bench_function("logger", |b| {
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
eza::logger::configure(black_box(std::env::var_os(eza::options::vars::EZA_DEBUG)))
|
eza::logger::configure(black_box(std::env::var_os(eza::options::vars::EZA_DEBUG)));
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
8
build.rs
8
build.rs
|
@ -9,12 +9,12 @@
|
||||||
/// just the version for *release* versions so the builds are reproducible.
|
/// just the version for *release* versions so the builds are reproducible.
|
||||||
///
|
///
|
||||||
/// This script generates the string from the environment variables that Cargo
|
/// This script generates the string from the environment variables that Cargo
|
||||||
/// adds (http://doc.crates.io/environment-variables.html) and runs `git` to
|
/// adds (<http://doc.crates.io/environment-variables.html>) and runs `git` to
|
||||||
/// get the SHA1 hash. It then writes the string into a file, which exa then
|
/// get the SHA1 hash. It then writes the string into a file, which exa then
|
||||||
/// includes at build-time.
|
/// includes at build-time.
|
||||||
///
|
///
|
||||||
/// - https://stackoverflow.com/q/43753491/3484614
|
/// - <https://stackoverflow.com/q/43753491/3484614>
|
||||||
/// - https://crates.io/crates/vergen
|
/// - <https://crates.io/crates/vergen>
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
|
@ -116,7 +116,7 @@ fn version_string() -> String {
|
||||||
|
|
||||||
/// Finds whether a feature is enabled by examining the Cargo variable.
|
/// Finds whether a feature is enabled by examining the Cargo variable.
|
||||||
fn feature_enabled(name: &str) -> bool {
|
fn feature_enabled(name: &str) -> bool {
|
||||||
env::var(format!("CARGO_FEATURE_{}", name))
|
env::var(format!("CARGO_FEATURE_{name}"))
|
||||||
.map(|e| !e.is_empty())
|
.map(|e| !e.is_empty())
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ use std::io;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::slice::Iter as SliceIter;
|
use std::slice::Iter as SliceIter;
|
||||||
|
|
||||||
use log::*;
|
use log::info;
|
||||||
|
|
||||||
use crate::fs::File;
|
use crate::fs::File;
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ impl Dir {
|
||||||
|
|
||||||
/// Produce an iterator of IO results of trying to read all the files in
|
/// Produce an iterator of IO results of trying to read all the files in
|
||||||
/// this directory.
|
/// this directory.
|
||||||
pub fn files<'dir, 'ig>(
|
#[must_use] pub fn files<'dir, 'ig>(
|
||||||
&'dir self,
|
&'dir self,
|
||||||
dots: DotFilter,
|
dots: DotFilter,
|
||||||
git: Option<&'ig GitCache>,
|
git: Option<&'ig GitCache>,
|
||||||
|
@ -71,12 +71,12 @@ impl Dir {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether this directory contains a file with the given path.
|
/// Whether this directory contains a file with the given path.
|
||||||
pub fn contains(&self, path: &Path) -> bool {
|
#[must_use] pub fn contains(&self, path: &Path) -> bool {
|
||||||
self.contents.iter().any(|p| p.path().as_path() == path)
|
self.contents.iter().any(|p| p.path().as_path() == path)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Append a path onto the path specified by this directory.
|
/// Append a path onto the path specified by this directory.
|
||||||
pub fn join(&self, child: &Path) -> PathBuf {
|
#[must_use] pub fn join(&self, child: &Path) -> PathBuf {
|
||||||
self.path.join(child)
|
self.path.join(child)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ pub enum DirAction {
|
||||||
|
|
||||||
impl DirAction {
|
impl DirAction {
|
||||||
/// Gets the recurse options, if this dir action has any.
|
/// Gets the recurse options, if this dir action has any.
|
||||||
pub fn recurse_options(self) -> Option<RecurseOptions> {
|
#[must_use] pub fn recurse_options(self) -> Option<RecurseOptions> {
|
||||||
match self {
|
match self {
|
||||||
Self::Recurse(o) => Some(o),
|
Self::Recurse(o) => Some(o),
|
||||||
_ => None,
|
_ => None,
|
||||||
|
@ -51,7 +51,7 @@ impl DirAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether to treat directories as regular files or not.
|
/// Whether to treat directories as regular files or not.
|
||||||
pub fn treat_dirs_as_files(self) -> bool {
|
#[must_use] pub fn treat_dirs_as_files(self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Self::AsFile => true,
|
Self::AsFile => true,
|
||||||
Self::Recurse(o) => o.tree,
|
Self::Recurse(o) => o.tree,
|
||||||
|
@ -74,7 +74,7 @@ pub struct RecurseOptions {
|
||||||
|
|
||||||
impl RecurseOptions {
|
impl RecurseOptions {
|
||||||
/// Returns whether a directory of the given depth would be too deep.
|
/// Returns whether a directory of the given depth would be too deep.
|
||||||
pub fn is_too_deep(self, depth: usize) -> bool {
|
#[must_use] pub fn is_too_deep(self, depth: usize) -> bool {
|
||||||
match self.max_depth {
|
match self.max_depth {
|
||||||
None => false,
|
None => false,
|
||||||
Some(d) => d <= depth,
|
Some(d) => d <= depth,
|
||||||
|
|
|
@ -14,7 +14,7 @@ use std::path::{Path, PathBuf};
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
|
|
||||||
use git2::StatusEntry;
|
use git2::StatusEntry;
|
||||||
use log::*;
|
use log::{debug, error, info, warn};
|
||||||
|
|
||||||
use crate::fs::fields as f;
|
use crate::fs::fields as f;
|
||||||
|
|
||||||
|
@ -31,11 +31,11 @@ pub struct GitCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GitCache {
|
impl GitCache {
|
||||||
pub fn has_anything_for(&self, index: &Path) -> bool {
|
#[must_use] pub fn has_anything_for(&self, index: &Path) -> bool {
|
||||||
self.repos.iter().any(|e| e.has_path(index))
|
self.repos.iter().any(|e| e.has_path(index))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(&self, index: &Path, prefix_lookup: bool) -> f::Git {
|
#[must_use] pub fn get(&self, index: &Path, prefix_lookup: bool) -> f::Git {
|
||||||
self.repos
|
self.repos
|
||||||
.iter()
|
.iter()
|
||||||
.find(|repo| repo.has_path(index))
|
.find(|repo| repo.has_path(index))
|
||||||
|
@ -410,7 +410,7 @@ fn current_branch(repo: &git2::Repository) -> Option<String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl f::SubdirGitRepo {
|
impl f::SubdirGitRepo {
|
||||||
pub fn from_path(dir: &Path, status: bool) -> Self {
|
#[must_use] pub fn from_path(dir: &Path, status: bool) -> Self {
|
||||||
let path = &reorient(dir);
|
let path = &reorient(dir);
|
||||||
|
|
||||||
if let Ok(repo) = git2::Repository::open(path) {
|
if let Ok(repo) = git2::Repository::open(path) {
|
||||||
|
|
|
@ -62,7 +62,7 @@ pub enum Type {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Type {
|
impl Type {
|
||||||
pub fn is_regular_file(self) -> bool {
|
#[must_use] pub fn is_regular_file(self) -> bool {
|
||||||
matches!(self, Self::File)
|
matches!(self, Self::File)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ use std::time::SystemTime;
|
||||||
|
|
||||||
use chrono::prelude::*;
|
use chrono::prelude::*;
|
||||||
|
|
||||||
use log::*;
|
use log::{debug, error, trace};
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use std::sync::LazyLock;
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
|
@ -209,18 +209,18 @@ impl<'dir> File<'dir> {
|
||||||
file
|
file
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_aa_current(parent_dir: &'dir Dir, total_size: bool) -> File<'dir> {
|
#[must_use] pub fn new_aa_current(parent_dir: &'dir Dir, total_size: bool) -> File<'dir> {
|
||||||
File::new_aa(parent_dir.path.clone(), parent_dir, ".", total_size)
|
File::new_aa(parent_dir.path.clone(), parent_dir, ".", total_size)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_aa_parent(path: PathBuf, parent_dir: &'dir Dir, total_size: bool) -> File<'dir> {
|
#[must_use] pub fn new_aa_parent(path: PathBuf, parent_dir: &'dir Dir, total_size: bool) -> File<'dir> {
|
||||||
File::new_aa(path, parent_dir, "..", total_size)
|
File::new_aa(path, parent_dir, "..", total_size)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A file’s name is derived from its string. This needs to handle directories
|
/// A file’s name is derived from its string. This needs to handle directories
|
||||||
/// such as `/` or `..`, which have no `file_name` component. So instead, just
|
/// such as `/` or `..`, which have no `file_name` component. So instead, just
|
||||||
/// use the last component as the name.
|
/// use the last component as the name.
|
||||||
pub fn filename(path: &Path) -> String {
|
#[must_use] pub fn filename(path: &Path) -> String {
|
||||||
if let Some(back) = path.components().next_back() {
|
if let Some(back) = path.components().next_back() {
|
||||||
back.as_os_str().to_string_lossy().to_string()
|
back.as_os_str().to_string_lossy().to_string()
|
||||||
} else {
|
} else {
|
||||||
|
@ -1016,7 +1016,7 @@ pub enum FileTarget<'dir> {
|
||||||
impl<'dir> FileTarget<'dir> {
|
impl<'dir> FileTarget<'dir> {
|
||||||
/// Whether this link doesn’t lead to a file, for whatever reason. This
|
/// Whether this link doesn’t lead to a file, for whatever reason. This
|
||||||
/// gets used to determine how to highlight the link in grid views.
|
/// gets used to determine how to highlight the link in grid views.
|
||||||
pub fn is_broken(&self) -> bool {
|
#[must_use] pub fn is_broken(&self) -> bool {
|
||||||
matches!(self, Self::Broken(_) | Self::Err(_))
|
matches!(self, Self::Broken(_) | Self::Err(_))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -365,7 +365,7 @@ impl IgnorePatterns {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new empty set of patterns that matches nothing.
|
/// Create a new empty set of patterns that matches nothing.
|
||||||
pub fn empty() -> Self {
|
#[must_use] pub fn empty() -> Self {
|
||||||
Self {
|
Self {
|
||||||
patterns: Vec::new(),
|
patterns: Vec::new(),
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ impl RecursiveSize {
|
||||||
/// assert_eq!(x.is_none(), false);
|
/// assert_eq!(x.is_none(), false);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn is_none(&self) -> bool {
|
#[must_use] pub const fn is_none(&self) -> bool {
|
||||||
matches!(*self, Self::None)
|
matches!(*self, Self::None)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ impl RecursiveSize {
|
||||||
/// assert_eq!(RecursiveSize::Some(2, 3).unwrap_bytes_or(1), 2);
|
/// assert_eq!(RecursiveSize::Some(2, 3).unwrap_bytes_or(1), 2);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn unwrap_bytes_or(self, default: u64) -> u64 {
|
#[must_use] pub const fn unwrap_bytes_or(self, default: u64) -> u64 {
|
||||||
match self {
|
match self {
|
||||||
Self::Some(bytes, _blocks) => bytes,
|
Self::Some(bytes, _blocks) => bytes,
|
||||||
_ => default,
|
_ => default,
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
// SPDX-FileCopyrightText: 2014 Benjamin Sago
|
// SPDX-FileCopyrightText: 2014 Benjamin Sago
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
use crate::theme::ThemeFileType as FileType;
|
use crate::theme::ThemeFileType as FileType;
|
||||||
use crate::theme::*;
|
use crate::theme::{FileKinds, FileNameStyle, Git, GitRepo, IconStyle, Links, Permissions, SELinuxContext, SecurityContext, Size, UiStyles, Users};
|
||||||
use nu_ansi_term::{Color, Style};
|
use nu_ansi_term::{Color, Style};
|
||||||
use serde::{Deserialize, Deserializer, Serialize};
|
use serde::{Deserialize, Deserializer, Serialize};
|
||||||
use serde_norway;
|
use serde_norway;
|
||||||
|
@ -49,7 +49,7 @@ where
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
fn color_from_str(s: &str) -> Option<Color> {
|
fn color_from_str(s: &str) -> Option<Color> {
|
||||||
use Color::*;
|
use Color::{Black, Blue, Cyan, DarkGray, Default, Fixed, Green, LightBlue, LightCyan, LightGray, LightGreen, LightMagenta, LightPurple, LightRed, LightYellow, Magenta, Purple, Red, Rgb, White, Yellow};
|
||||||
match s {
|
match s {
|
||||||
// nothing
|
// nothing
|
||||||
"" | "none" | "None" => None,
|
"" | "none" | "None" => None,
|
||||||
|
@ -604,10 +604,10 @@ impl FromOverride<UiStylesOverride> for UiStyles {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl ThemeConfig {
|
impl ThemeConfig {
|
||||||
pub fn from_path(path: PathBuf) -> Self {
|
#[must_use] pub fn from_path(path: PathBuf) -> Self {
|
||||||
ThemeConfig { location: path }
|
ThemeConfig { location: path }
|
||||||
}
|
}
|
||||||
pub fn to_theme(&self) -> Option<UiStyles> {
|
#[must_use] pub fn to_theme(&self) -> Option<UiStyles> {
|
||||||
let ui_styles_override: Option<UiStylesOverride> = {
|
let ui_styles_override: Option<UiStylesOverride> = {
|
||||||
let file = std::fs::File::open(&self.location).ok()?;
|
let file = std::fs::File::open(&self.location).ok()?;
|
||||||
serde_norway::from_reader(&file).ok()
|
serde_norway::from_reader(&file).ok()
|
||||||
|
@ -650,7 +650,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_short_hex_color_from_string() {
|
fn parse_short_hex_color_from_string() {
|
||||||
for case in ["#f0f", "#F0F"].iter() {
|
for case in &["#f0f", "#F0F"] {
|
||||||
assert_eq!(color_from_str(case), Some(Color::Rgb(255, 0, 255)));
|
assert_eq!(color_from_str(case), Some(Color::Rgb(255, 0, 255)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,7 +109,7 @@ impl fmt::Display for OptionsError {
|
||||||
impl OptionsError {
|
impl OptionsError {
|
||||||
/// Try to second-guess what the user was trying to do, depending on what
|
/// Try to second-guess what the user was trying to do, depending on what
|
||||||
/// went wrong.
|
/// went wrong.
|
||||||
pub fn suggestion(&self) -> Option<&'static str> {
|
#[must_use] pub fn suggestion(&self) -> Option<&'static str> {
|
||||||
// ‘ls -lt’ and ‘ls -ltr’ are common combinations
|
// ‘ls -lt’ and ‘ls -ltr’ are common combinations
|
||||||
match self {
|
match self {
|
||||||
Self::BadArgument(time, r) if *time == &flags::TIME && r == "r" => {
|
Self::BadArgument(time, r) if *time == &flags::TIME && r == "r" => {
|
||||||
|
|
|
@ -173,7 +173,7 @@ impl Options {
|
||||||
/// Whether the View specified in this set of options includes a Git
|
/// Whether the View specified in this set of options includes a Git
|
||||||
/// status column. It’s only worth trying to discover a repository if the
|
/// status column. It’s only worth trying to discover a repository if the
|
||||||
/// results will end up being displayed.
|
/// results will end up being displayed.
|
||||||
pub fn should_scan_for_git(&self) -> bool {
|
#[must_use] pub fn should_scan_for_git(&self) -> bool {
|
||||||
if self.filter.git_ignore == GitIgnore::CheckAndIgnore {
|
if self.filter.git_ignore == GitIgnore::CheckAndIgnore {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,7 @@ impl ColorScaleInformation {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn adjust_style(&self, mut style: Style, value: f32, range: Option<Extremes>) -> Style {
|
#[must_use] pub fn adjust_style(&self, mut style: Style, value: f32, range: Option<Extremes>) -> Style {
|
||||||
if let (Some(fg), Some(range)) = (style.foreground, range) {
|
if let (Some(fg), Some(range)) = (style.foreground, range) {
|
||||||
let mut ratio = ((value - range.min) / (range.max - range.min)).clamp(0.0, 1.0);
|
let mut ratio = ((value - range.min) / (range.max - range.min)).clamp(0.0, 1.0);
|
||||||
if ratio.is_nan() {
|
if ratio.is_nan() {
|
||||||
|
|
|
@ -72,7 +72,7 @@ use std::vec::IntoIter as VecIntoIter;
|
||||||
use nu_ansi_term::Style;
|
use nu_ansi_term::Style;
|
||||||
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
|
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
|
||||||
|
|
||||||
use log::*;
|
use log::{debug, trace};
|
||||||
|
|
||||||
use crate::fs::dir_action::RecurseOptions;
|
use crate::fs::dir_action::RecurseOptions;
|
||||||
use crate::fs::feature::git::GitCache;
|
use crate::fs::feature::git::GitCache;
|
||||||
|
@ -403,7 +403,7 @@ impl<'a> Render<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render_header(&self, header: TableRow) -> Row {
|
#[must_use] pub fn render_header(&self, header: TableRow) -> Row {
|
||||||
Row {
|
Row {
|
||||||
tree: TreeParams::new(TreeDepth::root(), false),
|
tree: TreeParams::new(TreeDepth::root(), false),
|
||||||
cells: Some(header),
|
cells: Some(header),
|
||||||
|
@ -442,7 +442,7 @@ impl<'a> Render<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn iterate_with_table(&'a self, table: Table<'a>, rows: Vec<Row>) -> TableIter<'a> {
|
#[must_use] pub fn iterate_with_table(&'a self, table: Table<'a>, rows: Vec<Row>) -> TableIter<'a> {
|
||||||
TableIter {
|
TableIter {
|
||||||
tree_trunk: TreeTrunk::default(),
|
tree_trunk: TreeTrunk::default(),
|
||||||
total_width: table.widths().total(),
|
total_width: table.widths().total(),
|
||||||
|
@ -452,7 +452,7 @@ impl<'a> Render<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn iterate(&'a self, rows: Vec<Row>) -> Iter {
|
#[must_use] pub fn iterate(&'a self, rows: Vec<Row>) -> Iter {
|
||||||
Iter {
|
Iter {
|
||||||
tree_trunk: TreeTrunk::default(),
|
tree_trunk: TreeTrunk::default(),
|
||||||
inner: rows.into_iter(),
|
inner: rows.into_iter(),
|
||||||
|
|
|
@ -168,7 +168,7 @@ pub struct FileName<'a, 'dir, C> {
|
||||||
impl<'a, 'dir, C> FileName<'a, 'dir, C> {
|
impl<'a, 'dir, C> FileName<'a, 'dir, C> {
|
||||||
/// Sets the flag on this file name to display link targets with an
|
/// Sets the flag on this file name to display link targets with an
|
||||||
/// arrow followed by their path.
|
/// arrow followed by their path.
|
||||||
pub fn with_link_paths(mut self) -> Self {
|
#[must_use] pub fn with_link_paths(mut self) -> Self {
|
||||||
if !self.file.deref_links {
|
if !self.file.deref_links {
|
||||||
self.link_style = LinkStyle::FullLinkPaths;
|
self.link_style = LinkStyle::FullLinkPaths;
|
||||||
}
|
}
|
||||||
|
@ -177,7 +177,7 @@ impl<'a, 'dir, C> FileName<'a, 'dir, C> {
|
||||||
|
|
||||||
/// Sets the flag on this file name to display mounted filesystem
|
/// Sets the flag on this file name to display mounted filesystem
|
||||||
///details.
|
///details.
|
||||||
pub fn with_mount_details(mut self, enable: bool) -> Self {
|
#[must_use] pub fn with_mount_details(mut self, enable: bool) -> Self {
|
||||||
self.mount_style = if enable {
|
self.mount_style = if enable {
|
||||||
MountStyle::MountInfo
|
MountStyle::MountInfo
|
||||||
} else {
|
} else {
|
||||||
|
@ -194,7 +194,7 @@ impl<'a, 'dir, C: Colours> FileName<'a, 'dir, C> {
|
||||||
/// This method returns some `TextCellContents`, rather than a `TextCell`,
|
/// This method returns some `TextCellContents`, rather than a `TextCell`,
|
||||||
/// because for the last cell in a table, it doesn’t need to have its
|
/// because for the last cell in a table, it doesn’t need to have its
|
||||||
/// width calculated.
|
/// width calculated.
|
||||||
pub fn paint(&self) -> TextCellContents {
|
#[must_use] pub fn paint(&self) -> TextCellContents {
|
||||||
let mut bits = Vec::new();
|
let mut bits = Vec::new();
|
||||||
let (icon_override, filename_style_override) = match self.colours.style_override(self.file)
|
let (icon_override, filename_style_override) = match self.colours.style_override(self.file)
|
||||||
{
|
{
|
||||||
|
@ -461,7 +461,7 @@ impl<'a, 'dir, C: Colours> FileName<'a, 'dir, C> {
|
||||||
/// depending on which “type” of file it appears to be — either from the
|
/// depending on which “type” of file it appears to be — either from the
|
||||||
/// class on the filesystem or from its name. (Or the broken link colour,
|
/// class on the filesystem or from its name. (Or the broken link colour,
|
||||||
/// if there’s nowhere else for that fact to be shown.)
|
/// if there’s nowhere else for that fact to be shown.)
|
||||||
pub fn style(&self) -> Style {
|
#[must_use] pub fn style(&self) -> Style {
|
||||||
if let LinkStyle::JustFilenames = self.link_style {
|
if let LinkStyle::JustFilenames = self.link_style {
|
||||||
if let Some(ref target) = self.target {
|
if let Some(ref target) = self.target {
|
||||||
if target.is_broken() {
|
if target.is_broken() {
|
||||||
|
@ -491,7 +491,7 @@ impl<'a, 'dir, C: Colours> FileName<'a, 'dir, C> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// For grid's use, to cover the case of hyperlink escape sequences
|
/// For grid's use, to cover the case of hyperlink escape sequences
|
||||||
pub fn bare_utf8_width(&self) -> usize {
|
#[must_use] pub fn bare_utf8_width(&self) -> usize {
|
||||||
UnicodeWidthStr::width(self.file.name.as_str())
|
UnicodeWidthStr::width(self.file.name.as_str())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ pub struct Options {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Options {
|
impl Options {
|
||||||
pub fn direction(self) -> Direction {
|
#[must_use] pub fn direction(self) -> Direction {
|
||||||
if self.across {
|
if self.across {
|
||||||
Direction::LeftToRight
|
Direction::LeftToRight
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -29,7 +29,7 @@ pub struct Options {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Options {
|
impl Options {
|
||||||
pub fn to_details_options(&self) -> &DetailsOptions {
|
#[must_use] pub fn to_details_options(&self) -> &DetailsOptions {
|
||||||
&self.details
|
&self.details
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ pub enum TerminalWidth {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TerminalWidth {
|
impl TerminalWidth {
|
||||||
pub fn actual_terminal_width(self) -> Option<usize> {
|
#[must_use] pub fn actual_terminal_width(self) -> Option<usize> {
|
||||||
// All of stdin, stdout, and stderr could not be connected to a
|
// All of stdin, stdout, and stderr could not be connected to a
|
||||||
// terminal, but we’re only interested in stdout because it’s
|
// terminal, but we’re only interested in stdout because it’s
|
||||||
// where the output goes.
|
// where the output goes.
|
||||||
|
|
|
@ -11,7 +11,7 @@ use crate::output::cell::TextCell;
|
||||||
use crate::output::table::FlagsFormat;
|
use crate::output::table::FlagsFormat;
|
||||||
|
|
||||||
impl f::Flags {
|
impl f::Flags {
|
||||||
pub fn render(self, style: Style, _format: FlagsFormat) -> TextCell {
|
#[must_use] pub fn render(self, style: Style, _format: FlagsFormat) -> TextCell {
|
||||||
TextCell::paint(style, "-".to_string())
|
TextCell::paint(style, "-".to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ use crate::fs::fields as f;
|
||||||
use crate::output::cell::TextCell;
|
use crate::output::cell::TextCell;
|
||||||
|
|
||||||
impl f::Inode {
|
impl f::Inode {
|
||||||
pub fn render(self, style: Style) -> TextCell {
|
#[must_use] pub fn render(self, style: Style) -> TextCell {
|
||||||
TextCell::paint(style, self.0.to_string())
|
TextCell::paint(style, self.0.to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,30 +19,27 @@ pub trait PermissionsPlusRender {
|
||||||
impl PermissionsPlusRender for Option<f::PermissionsPlus> {
|
impl PermissionsPlusRender for Option<f::PermissionsPlus> {
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
fn render<C: Colours + FiletypeColours>(&self, colours: &C) -> TextCell {
|
fn render<C: Colours + FiletypeColours>(&self, colours: &C) -> TextCell {
|
||||||
match self {
|
if let Some(p) = self {
|
||||||
Some(p) => {
|
let mut chars = vec![p.file_type.render(colours)];
|
||||||
let mut chars = vec![p.file_type.render(colours)];
|
let permissions = p.permissions;
|
||||||
let permissions = p.permissions;
|
chars.extend(Some(permissions).render(colours, p.file_type.is_regular_file()));
|
||||||
chars.extend(Some(permissions).render(colours, p.file_type.is_regular_file()));
|
|
||||||
|
|
||||||
if p.xattrs {
|
if p.xattrs {
|
||||||
chars.push(colours.attribute().paint("@"));
|
chars.push(colours.attribute().paint("@"));
|
||||||
}
|
|
||||||
|
|
||||||
// As these are all ASCII characters, we can guarantee that they’re
|
|
||||||
// all going to be one character wide, and don’t need to compute the
|
|
||||||
// cell’s display width.
|
|
||||||
TextCell {
|
|
||||||
width: DisplayWidth::from(chars.len()),
|
|
||||||
contents: chars.into(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
None => {
|
|
||||||
let chars: Vec<_> = iter::repeat(colours.dash().paint("-")).take(10).collect();
|
// As these are all ASCII characters, we can guarantee that they’re
|
||||||
TextCell {
|
// all going to be one character wide, and don’t need to compute the
|
||||||
width: DisplayWidth::from(chars.len()),
|
// cell’s display width.
|
||||||
contents: chars.into(),
|
TextCell {
|
||||||
}
|
width: DisplayWidth::from(chars.len()),
|
||||||
|
contents: chars.into(),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let chars: Vec<_> = iter::repeat(colours.dash().paint("-")).take(10).collect();
|
||||||
|
TextCell {
|
||||||
|
width: DisplayWidth::from(chars.len()),
|
||||||
|
contents: chars.into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ use std::sync::{Mutex, MutexGuard};
|
||||||
|
|
||||||
use chrono::prelude::*;
|
use chrono::prelude::*;
|
||||||
|
|
||||||
use log::*;
|
use log::debug;
|
||||||
use std::sync::LazyLock;
|
use std::sync::LazyLock;
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use uzers::UsersCache;
|
use uzers::UsersCache;
|
||||||
|
@ -67,7 +67,7 @@ pub struct Columns {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Columns {
|
impl Columns {
|
||||||
pub fn collect(&self, actually_enable_git: bool, git_repos: bool) -> Vec<Column> {
|
#[must_use] pub fn collect(&self, actually_enable_git: bool, git_repos: bool) -> Vec<Column> {
|
||||||
let mut columns = Vec::with_capacity(4);
|
let mut columns = Vec::with_capacity(4);
|
||||||
|
|
||||||
if self.inode {
|
if self.inode {
|
||||||
|
@ -185,7 +185,7 @@ pub enum Alignment {
|
||||||
impl Column {
|
impl Column {
|
||||||
/// Get the alignment this column should use.
|
/// Get the alignment this column should use.
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
pub fn alignment(self) -> Alignment {
|
#[must_use] pub fn alignment(self) -> Alignment {
|
||||||
#[allow(clippy::wildcard_in_or_patterns)]
|
#[allow(clippy::wildcard_in_or_patterns)]
|
||||||
match self {
|
match self {
|
||||||
Self::FileSize | Self::HardLinks | Self::Inode | Self::Blocksize | Self::GitStatus => {
|
Self::FileSize | Self::HardLinks | Self::Inode | Self::Blocksize | Self::GitStatus => {
|
||||||
|
@ -205,7 +205,7 @@ impl Column {
|
||||||
|
|
||||||
/// Get the text that should be printed at the top, when the user elects
|
/// Get the text that should be printed at the top, when the user elects
|
||||||
/// to have a header row printed.
|
/// to have a header row printed.
|
||||||
pub fn header(self) -> &'static str {
|
#[must_use] pub fn header(self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
Self::Permissions => "Permissions",
|
Self::Permissions => "Permissions",
|
||||||
|
@ -288,7 +288,7 @@ pub enum TimeType {
|
||||||
|
|
||||||
impl TimeType {
|
impl TimeType {
|
||||||
/// Returns the text to use for a column’s heading in the columns output.
|
/// Returns the text to use for a column’s heading in the columns output.
|
||||||
pub fn header(self) -> &'static str {
|
#[must_use] pub fn header(self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
Self::Modified => "Date Modified",
|
Self::Modified => "Date Modified",
|
||||||
Self::Changed => "Date Changed",
|
Self::Changed => "Date Changed",
|
||||||
|
@ -421,7 +421,7 @@ pub struct Row {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Table<'a> {
|
impl<'a> Table<'a> {
|
||||||
pub fn new(
|
#[must_use] pub fn new(
|
||||||
options: &'a Options,
|
options: &'a Options,
|
||||||
git: Option<&'a GitCache>,
|
git: Option<&'a GitCache>,
|
||||||
theme: &'a Theme,
|
theme: &'a Theme,
|
||||||
|
@ -449,11 +449,11 @@ impl<'a> Table<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn widths(&self) -> &TableWidths {
|
#[must_use] pub fn widths(&self) -> &TableWidths {
|
||||||
&self.widths
|
&self.widths
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn header_row(&self) -> Row {
|
#[must_use] pub fn header_row(&self) -> Row {
|
||||||
let cells = self
|
let cells = self
|
||||||
.columns
|
.columns
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -591,7 +591,7 @@ impl<'a> Table<'a> {
|
||||||
f::SubdirGitRepo::default()
|
f::SubdirGitRepo::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render(&self, row: Row) -> TextCell {
|
#[must_use] pub fn render(&self, row: Row) -> TextCell {
|
||||||
let mut cell = TextCell::default();
|
let mut cell = TextCell::default();
|
||||||
|
|
||||||
let iter = row.cells.into_iter().zip(self.widths.iter()).enumerate();
|
let iter = row.cells.into_iter().zip(self.widths.iter()).enumerate();
|
||||||
|
@ -628,7 +628,7 @@ impl Deref for TableWidths {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TableWidths {
|
impl TableWidths {
|
||||||
pub fn zero(count: usize) -> Self {
|
#[must_use] pub fn zero(count: usize) -> Self {
|
||||||
Self(vec![0; count])
|
Self(vec![0; count])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -638,7 +638,7 @@ impl TableWidths {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn total(&self) -> usize {
|
#[must_use] pub fn total(&self) -> usize {
|
||||||
self.0.len() + self.0.iter().sum::<usize>()
|
self.0.len() + self.0.iter().sum::<usize>()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ pub enum TimeFormat {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TimeFormat {
|
impl TimeFormat {
|
||||||
pub fn format(self, time: &DateTime<FixedOffset>) -> String {
|
#[must_use] pub fn format(self, time: &DateTime<FixedOffset>) -> String {
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
return match self {
|
return match self {
|
||||||
Self::DefaultFormat => default(time),
|
Self::DefaultFormat => default(time),
|
||||||
|
@ -164,15 +164,14 @@ mod test {
|
||||||
let max_month_width = 4;
|
let max_month_width = 4;
|
||||||
let month = "1\u{2F49}"; // 1月
|
let month = "1\u{2F49}"; // 1月
|
||||||
let padding = short_month_padding(max_month_width, month);
|
let padding = short_month_padding(max_month_width, month);
|
||||||
let final_str = format!("{:<width$}", month, width = padding);
|
let final_str = format!("{month:<padding$}");
|
||||||
assert_eq!(max_month_width, UnicodeWidthStr::width(final_str.as_str()));
|
assert_eq!(max_month_width, UnicodeWidthStr::width(final_str.as_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn short_month_width_hindi() {
|
fn short_month_width_hindi() {
|
||||||
let max_month_width = 4;
|
let max_month_width = 4;
|
||||||
assert_eq!(
|
assert!(
|
||||||
true,
|
|
||||||
[
|
[
|
||||||
"\u{091C}\u{0928}\u{0970}", // जन॰
|
"\u{091C}\u{0928}\u{0970}", // जन॰
|
||||||
"\u{092B}\u{093C}\u{0930}\u{0970}", // फ़र॰
|
"\u{092B}\u{093C}\u{0930}\u{0970}", // फ़र॰
|
||||||
|
|
|
@ -4,14 +4,14 @@
|
||||||
// SPDX-FileCopyrightText: 2023-2024 Christina Sørensen, eza contributors
|
// SPDX-FileCopyrightText: 2023-2024 Christina Sørensen, eza contributors
|
||||||
// SPDX-FileCopyrightText: 2014 Benjamin Sago
|
// SPDX-FileCopyrightText: 2014 Benjamin Sago
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
use nu_ansi_term::Color::*;
|
use nu_ansi_term::Color::{Blue, Cyan, DarkGray, Green, Purple, Red, Yellow};
|
||||||
use nu_ansi_term::Style;
|
use nu_ansi_term::Style;
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
|
|
||||||
use crate::output::color_scale::{ColorScaleMode, ColorScaleOptions};
|
use crate::output::color_scale::{ColorScaleMode, ColorScaleOptions};
|
||||||
use crate::theme::ui_styles::*;
|
use crate::theme::ui_styles::{FileKinds, FileType, Git, GitRepo, Links, Permissions, SELinuxContext, SecurityContext, Size, UiStyles, Users};
|
||||||
impl UiStyles {
|
impl UiStyles {
|
||||||
pub fn default_theme(scale: ColorScaleOptions) -> Self {
|
#[must_use] pub fn default_theme(scale: ColorScaleOptions) -> Self {
|
||||||
Self {
|
Self {
|
||||||
size: Some(Size::colourful(scale)),
|
size: Some(Size::colourful(scale)),
|
||||||
..Self::default()
|
..Self::default()
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
use std::iter::Peekable;
|
use std::iter::Peekable;
|
||||||
use std::ops::FnMut;
|
use std::ops::FnMut;
|
||||||
|
|
||||||
use nu_ansi_term::Color::*;
|
use nu_ansi_term::Color::{Black, Blue, Cyan, DarkGray, Fixed, Green, LightBlue, LightCyan, LightGray, LightGreen, LightPurple, LightRed, LightYellow, Purple, Red, Rgb, White, Yellow};
|
||||||
use nu_ansi_term::{Color as Colour, Style};
|
use nu_ansi_term::{Color as Colour, Style};
|
||||||
|
|
||||||
// Parsing the LS_COLORS environment variable into a map of names to Style values.
|
// Parsing the LS_COLORS environment variable into a map of names to Style values.
|
||||||
|
|
|
@ -67,7 +67,7 @@ pub struct Theme {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Options {
|
impl Options {
|
||||||
pub fn to_theme(&self, isatty: bool) -> Theme {
|
#[must_use] pub fn to_theme(&self, isatty: bool) -> Theme {
|
||||||
if self.use_colours == UseColours::Never
|
if self.use_colours == UseColours::Never
|
||||||
|| (self.use_colours == UseColours::Automatic && !isatty)
|
|| (self.use_colours == UseColours::Automatic && !isatty)
|
||||||
{
|
{
|
||||||
|
@ -128,7 +128,7 @@ impl Definitions {
|
||||||
/// Also returns if the `EZA_COLORS` variable should reset the existing file
|
/// Also returns if the `EZA_COLORS` variable should reset the existing file
|
||||||
/// type mappings or not. The `reset` code needs to be the first one.
|
/// type mappings or not. The `reset` code needs to be the first one.
|
||||||
fn parse_color_vars(&self, colours: &mut UiStyles) -> (ExtensionMappings, bool) {
|
fn parse_color_vars(&self, colours: &mut UiStyles) -> (ExtensionMappings, bool) {
|
||||||
use log::*;
|
use log::warn;
|
||||||
|
|
||||||
let mut exts = ExtensionMappings::default();
|
let mut exts = ExtensionMappings::default();
|
||||||
|
|
||||||
|
@ -315,7 +315,7 @@ impl FileStyle for FileTypes {
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
impl render::BlocksColours for Theme {
|
impl render::BlocksColours for Theme {
|
||||||
fn blocksize(&self, prefix: Option<number_prefix::Prefix>) -> Style {
|
fn blocksize(&self, prefix: Option<number_prefix::Prefix>) -> Style {
|
||||||
use number_prefix::Prefix::*;
|
use number_prefix::Prefix::{Gibi, Giga, Kibi, Kilo, Mebi, Mega};
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
let style = match prefix {
|
let style = match prefix {
|
||||||
|
@ -329,7 +329,7 @@ impl render::BlocksColours for Theme {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unit(&self, prefix: Option<number_prefix::Prefix>) -> Style {
|
fn unit(&self, prefix: Option<number_prefix::Prefix>) -> Style {
|
||||||
use number_prefix::Prefix::*;
|
use number_prefix::Prefix::{Gibi, Giga, Kibi, Kilo, Mebi, Mega};
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
let style = match prefix {
|
let style = match prefix {
|
||||||
|
@ -416,7 +416,7 @@ impl render::PermissionsColours for Theme {
|
||||||
|
|
||||||
impl render::SizeColours for Theme {
|
impl render::SizeColours for Theme {
|
||||||
fn size(&self, prefix: Option<number_prefix::Prefix>) -> Style {
|
fn size(&self, prefix: Option<number_prefix::Prefix>) -> Style {
|
||||||
use number_prefix::Prefix::*;
|
use number_prefix::Prefix::{Gibi, Giga, Kibi, Kilo, Mebi, Mega};
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
return match prefix {
|
return match prefix {
|
||||||
|
@ -429,7 +429,7 @@ impl render::SizeColours for Theme {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unit(&self, prefix: Option<number_prefix::Prefix>) -> Style {
|
fn unit(&self, prefix: Option<number_prefix::Prefix>) -> Style {
|
||||||
use number_prefix::Prefix::*;
|
use number_prefix::Prefix::{Gibi, Giga, Kibi, Kilo, Mebi, Mega};
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
return match prefix {
|
return match prefix {
|
||||||
|
@ -554,7 +554,7 @@ mod customs_test {
|
||||||
GlobPattern::Simple(h) => {
|
GlobPattern::Simple(h) => {
|
||||||
let mut simple_pats = h
|
let mut simple_pats = h
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(k, v)| (glob::Pattern::new(&format!("*.{}", k)).unwrap(), *v))
|
.map(|(k, v)| (glob::Pattern::new(&format!("*.{k}")).unwrap(), *v))
|
||||||
.collect::<Vec<(glob::Pattern, Style)>>();
|
.collect::<Vec<(glob::Pattern, Style)>>();
|
||||||
|
|
||||||
simple_pats.sort_by_key(|x| x.0.clone());
|
simple_pats.sort_by_key(|x| x.0.clone());
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
// SPDX-FileCopyrightText: 2014 Benjamin Sago
|
// SPDX-FileCopyrightText: 2014 Benjamin Sago
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
use crate::theme::lsc::Pair;
|
use crate::theme::lsc::Pair;
|
||||||
use nu_ansi_term::{Color::*, Style};
|
use nu_ansi_term::{Color::{Blue, Cyan, Green, Purple, Red, Yellow}, Style};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
|
@ -59,7 +59,7 @@ macro_rules! field_accessors {
|
||||||
impl $struct_name {
|
impl $struct_name {
|
||||||
$(
|
$(
|
||||||
#[allow(clippy::wrong_self_convention, clippy::new_ret_no_self)]
|
#[allow(clippy::wrong_self_convention, clippy::new_ret_no_self)]
|
||||||
pub fn $field_name(&self) -> $type {
|
#[must_use] pub fn $field_name(&self) -> $type {
|
||||||
self.$field_name.unwrap_or_default()
|
self.$field_name.unwrap_or_default()
|
||||||
}
|
}
|
||||||
)*
|
)*
|
||||||
|
@ -382,7 +382,7 @@ pub struct FileType {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UiStyles {
|
impl UiStyles {
|
||||||
pub fn plain() -> Self {
|
#[must_use] pub fn plain() -> Self {
|
||||||
Self {
|
Self {
|
||||||
colourful: Some(false),
|
colourful: Some(false),
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue