hykilpikonna / hyfetch

šŸ³ļøā€šŸŒˆ šŸ³ļøā€āš§ļø Neofetch with LGBTQ+ pride flags!
MIT License
1.27k stars 95 forks source link

color alignment breaks when using own ascii art file #330

Open HimeLexie opened 1 month ago

HimeLexie commented 1 month ago

Describe the bug

When using the flag --ascii-file (file) without leaving a leading new line above the ASCII art in the file, colors will misalign (see picture below)

Expected behavior

first, i expect that the hyfetch ASCII art should display as neofetch does without an extra space above it and work (see picture).

second, i expect that colors should realign correctly for custom ASCII files (see images below, highlighted to show colors).

Screenshots

Color misalignment without new line: 2024-07-23T13:47:51,651487163-05:00 Hyfetch prints extra line above ASCII art compared to neofetch: 2024-07-23T13:51:20,419053531-05:00

showing color misalignment with highlighting to make colors easier to see:

with ASCII file: image without: image

Config file

Please paste the content of ~/.config/hyfetch.json below:

{
    "preset": "transfeminine",
    "mode": "rgb",
    "light_dark": "dark",
    "lightness": 0.65,
    "color_align": {
        "mode": "horizontal",
        "custom_colors": [],
        "fore_back": null
    },
    "backend": "neofetch",
    "args": null,
    "distro": "arch_small",
    "pride_month_shown": [],
    "pride_month_disable": false
}

Additional context

I have seen the extra new line in other screenshots of hyfetch on other issues.

luna-1024 commented 1 month ago

I investigated the cause of these issues:

  1. Blank line above ascii art: This is due to the distros code generation placing the ascii art in raw strings that have the triple quotes on separate lines from the art, resulting in guaranteed leading and ending newlines, which end up padding the art on top and bottom. Unfortnately the proportionally distributed stripe coloring stretches over those invisible blank lines. The distribution could lead to the first and or last colors not being shown. Therefore, this should be fixed by stripping out the extraneous newlines. Can fix by appending [1:-1] slice operation to the ascii art string expression. (See third paragraph of rust-malaysia/hyfetch/pull/30 )
  2. Custom ascii file stripe color distribution broken: This is due to treating the final trailing newline in the ascii art file as a line to color. But like the first issue, since it is a blank line, no color is seen on it. This can result in the last color not being shown. This can be fixed by normalizing the line endings in the file. Get an iterable of the file lines (newlines removed), and join it with \n before proceeding with for further processing. Such an iterator (from splitlines() etc) generally does not consider the file's final newline to be starting a line. That would also ensure correctness for Windows \r\n line ending ascii art files.

The Rust rewrite (#317) that is almost completed, and it does not have the first issue. However it still has the second issue, so I will send a PR to the fork to fix it there. Even though I recently found the first issue, the second one could have gone unnoticed for quite a while without your report. Thanks for taking the time here! šŸ˜Š


This issue can be mitigated by copying the ascii art to a file (unescape backslashes), using the --ascii-file argument, and making sure that file does not have a trailing newline. Text editors often try to enforce that it is there. Inspect the ascii art file with xxd and remove the last byte (if it is a newline) with truncate -s -1 <file>. Then since a custom ascii file is not specifiable in the config.json, instead setup a shell alias.

teohhanhui commented 1 month ago

@HimeLexie Can you help us test if https://github.com/hykilpikonna/hyfetch/pull/317 works correctly for you now?

HimeLexie commented 1 month ago

@teohhanhui Do i just clone the riir branch?

teohhanhui commented 1 month ago

@HimeLexie Yes, quick way (for development): cargo run (you need to install rustup first: https://rustup.rs/)

Or to install it locally (example on Linux):

cargo build --release
cp target/release/hyfetch ~/.local/bin/
HimeLexie commented 1 month ago

Can confirm its fixed, thanks a lot! I was wanting to use this but the weird formatting was frustrating. image

teohhanhui commented 1 month ago

And for the custom ascii file as well? :smile:

You can do e.g. cargo run -- --ascii-file ...

HimeLexie commented 1 month ago

image Appears like it does.