Repository: eza-community/eza (language: rust)

Issue:
bug: using `--icons --classify` flag breaks grid output
When using following arguments, the grid output seems a little broken.

```
eza --icons -F
```

![image](https://github.com/eza-community/eza/assets/50587059/fb6fe49d-283d-4f07-9727-b19ff7159179)

Only using both `--icons` and `--classify` will result in wrong output.

The version is
```
eza - A modern, maintained replacement for ls
v0.15.1 [+git]
https://github.com/eza-community/eza
```

The OS is archlinux, and I'm using KDE plasma with wezterm terminal emulator.


Discussion / hints:
Wonder if this is related to #267
I have a fix for this:
```diff
[23/11/23 15:57]ankit@devbox:~/code/external-repo/eza (fix-grid-classify-bug *)$ g d
diff --git a/src/output/grid.rs b/src/output/grid.rs
index 5293348c..f51177a4 100644
--- a/src/output/grid.rs
+++ b/src/output/grid.rs
@@ -91,7 +91,11 @@ impl<'a> Render<'a> {
                 contents: contents.strings().to_string(),
                 // with hyperlink escape sequences,
                 // the actual *contents.width() is larger than actually needed, so we take only the filename
-                width,
+                width: width + classification_width,
```

but I have no idea why it works...

I just see that the grid breaks in this way - when both `classify` and `icons` are used together, there is an extra space after files with a trailing `/` (or other symbol) from the `classify`. So this adjusts the file's width to account for that.  So I won't submit this as a PR unless/until I figure out why it works - maybe it causes other bugs or only works for my setup. I suspect it might have something to do with particular fonts like where icons are 1 char wide when selected but actually take up more space. But if anyone can verify the fix and possibly explain what's happening i could make a PR :)
Oh that is weird.. I thought this was fixed already. Yeah that should work as a temporary solution. I have (slowly) been working on a more permanent solution but that has been hitting speedbumps lately :/
> Oh that is weird.. I thought this was fixed already. Yeah that should work as a temporary solution. I have (slowly) been working on a more permanent solution but that has been hitting speedbumps lately :/

Hmm okay. if you're looking for help, is there any info/docs on why it happens or the solution you're working on? 
The reason it happens is because calculations of width currently are kinda hacky and hyperlinks (the inability to properly escape the ansi escape codes needed, in combination with finding the width of the grapheme clusters) cause us to use the naive calculation of the width instead of the function (`*contents.width()`) to get the unicode width, otherwise it will be wider than we need.
This is just an ongoing problem, the solution is I need to migrate us over to a different library that handles hyperlinks internally so we don't have to do width calculations ourselves, allowing us to be able to then migrate over to a new version of another library, which will then handle all other calculations. (convenient)

That is all stuff I'm going to have to do myself but you are welcome to put in a PR with a fix for specifically the classification issue :+1: .
The classification width needs to get added to 
```rust
                    ShowIcons::Always(spacing) | ShowIcons::Automatic(spacing),
                ) => {
                    filename.bare_width()
                        + 1
                        + (spacing as usize)
                        + space_filename_offset
                        + classification_width // <- here
                }
                (EmbedHyperlinks::Off, _) => *contents.width(),
            };

            grid.add(tg::Cell {
                contents: contents.strings().to_string(),
                // with hyperlink escape sequences,
                // the actual *contents.width() is larger than actually needed, so we take only the filename
                width, // <- where i think u added it 
            });
        }






Fix patch:
diff --git a/src/output/grid.rs b/src/output/grid.rs
index 5293348cf..2986e4514 100644
--- a/src/output/grid.rs
+++ b/src/output/grid.rs
@@ -83,7 +83,13 @@ impl<'a> Render<'a> {
                 (
                     EmbedHyperlinks::Off,
                     ShowIcons::Always(spacing) | ShowIcons::Automatic(spacing),
-                ) => filename.bare_width() + 1 + (spacing as usize) + space_filename_offset,
+                ) => {
+                    filename.bare_width()
+                        + classification_width
+                        + 1
+                        + (spacing as usize)
+                        + space_filename_offset
+                }
                 (EmbedHyperlinks::Off, _) => *contents.width(),
             };
 


Test patch: