mirror of
https://github.com/eza-community/eza
synced 2024-10-03 06:34:40 +00:00
fix: adjust change width calculations for hyperlink and classify
This fix adjusts the calculations used when hyperlink and classify options are both specified on the command line, correcting behavior that would cause columns to be misaligned. Resolves #267
This commit is contained in:
parent
b1440bdf75
commit
d3926e7a1a
|
@ -314,7 +314,7 @@ impl<'a, 'dir, C: Colours> FileName<'a, 'dir, C> {
|
||||||
/// The character to be displayed after a file when classifying is on, if
|
/// The character to be displayed after a file when classifying is on, if
|
||||||
/// the file’s type has one associated with it.
|
/// the file’s type has one associated with it.
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
fn classify_char(&self, file: &File<'_>) -> Option<&'static str> {
|
pub(crate) fn classify_char(&self, file: &File<'_>) -> Option<&'static str> {
|
||||||
if file.is_executable_file() {
|
if file.is_executable_file() {
|
||||||
Some("*")
|
Some("*")
|
||||||
} else if file.is_directory() {
|
} else if file.is_directory() {
|
||||||
|
@ -331,7 +331,7 @@ impl<'a, 'dir, C: Colours> FileName<'a, 'dir, C> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
fn classify_char(&self, file: &File<'_>) -> Option<&'static str> {
|
pub(crate) fn classify_char(&self, file: &File<'_>) -> Option<&'static str> {
|
||||||
if file.is_directory() {
|
if file.is_directory() {
|
||||||
Some("/")
|
Some("/")
|
||||||
} else if file.is_link() {
|
} else if file.is_link() {
|
||||||
|
|
|
@ -4,7 +4,7 @@ use term_grid as tg;
|
||||||
|
|
||||||
use crate::fs::filter::FileFilter;
|
use crate::fs::filter::FileFilter;
|
||||||
use crate::fs::File;
|
use crate::fs::File;
|
||||||
use crate::output::file_name::Options as FileStyle;
|
use crate::output::file_name::{Classify, Options as FileStyle};
|
||||||
use crate::output::file_name::{EmbedHyperlinks, ShowIcons};
|
use crate::output::file_name::{EmbedHyperlinks, ShowIcons};
|
||||||
use crate::theme::Theme;
|
use crate::theme::Theme;
|
||||||
|
|
||||||
|
@ -44,11 +44,29 @@ impl<'a> Render<'a> {
|
||||||
self.filter.sort_files(&mut self.files);
|
self.filter.sort_files(&mut self.files);
|
||||||
for file in &self.files {
|
for file in &self.files {
|
||||||
let filename = self.file_style.for_file(file, self.theme);
|
let filename = self.file_style.for_file(file, self.theme);
|
||||||
|
|
||||||
|
// Calculate classification width
|
||||||
|
let classification_width =
|
||||||
|
if let Classify::AddFileIndicators = filename.options.classify {
|
||||||
|
match filename.classify_char(file) {
|
||||||
|
Some(s) => s.len(),
|
||||||
|
None => 0,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
};
|
||||||
|
|
||||||
let contents = filename.paint();
|
let contents = filename.paint();
|
||||||
#[rustfmt::skip]
|
let width = match (
|
||||||
let width = match (filename.options.embed_hyperlinks, filename.options.show_icons) {
|
filename.options.embed_hyperlinks,
|
||||||
(EmbedHyperlinks::On, ShowIcons::On(spacing)) => filename.bare_width() + 1 + spacing,
|
filename.options.show_icons,
|
||||||
(EmbedHyperlinks::On, ShowIcons::Off) => filename.bare_width(),
|
) {
|
||||||
|
(EmbedHyperlinks::On, ShowIcons::On(spacing)) => {
|
||||||
|
filename.bare_width() + 1 + spacing + classification_width
|
||||||
|
}
|
||||||
|
(EmbedHyperlinks::On, ShowIcons::Off) => {
|
||||||
|
filename.bare_width() + classification_width
|
||||||
|
}
|
||||||
(EmbedHyperlinks::Off, _) => *contents.width(),
|
(EmbedHyperlinks::Off, _) => *contents.width(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue