Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

color alignment breaks when using own ascii art file #330

Open
1 task done
HimeLexie opened this issue Jul 23, 2024 · 7 comments
Open
1 task done

color alignment breaks when using own ascii art file #330

HimeLexie opened this issue Jul 23, 2024 · 7 comments

Comments

@HimeLexie
Copy link

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)

  • Does this issue still occur in the master branch? (Required)

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.

@HimeLexie HimeLexie changed the title color alignment and ascii art alignment break when using own ascii art file color alignment breaks when using own ascii art file Jul 23, 2024
@luna-1024
Copy link
Contributor

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 Fix the displaying of color arrangment labels in the interactive config rust-malaysia/hyfetch#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
Copy link
Contributor

@HimeLexie Can you help us test if #317 works correctly for you now?

@HimeLexie
Copy link
Author

@teohhanhui Do i just clone the riir branch?

@teohhanhui
Copy link
Contributor

teohhanhui commented Jul 24, 2024

@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
Copy link
Author

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

@teohhanhui
Copy link
Contributor

teohhanhui commented Jul 24, 2024

And for the custom ascii file as well? 😄

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

@HimeLexie
Copy link
Author

image
Appears like it does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants