Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Strip color codes from ascii art line length calculations #1543

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

Syphist
Copy link

@Syphist Syphist commented Aug 25, 2020

Description

This removes color and formatting codes from the line length calculation to allow for more control over custom ascii art. This would also fix issues I found when attempting to use the patch in #1220.

Features

Allows for support for finer control of ascii art using escapes such as "[38;5;39m" for defining coloring and formatting in the terminal.

Issues

None that I have found

TODO

Nothing

Fixed Issues

This so far only works if you directly paste the character for \033 or "�" into the file. I was unable to get it to work for both.

@Syphist
Copy link
Author

Syphist commented Aug 25, 2020

I have made several more attempts to work around SC2001, but have had no success. I am wondering if it is too complex to do it with the search and replace in bash and may need to be done with sed. I will probably make further attempts at this, if anyone else has any ideas feel free to let me know too.

@Syphist
Copy link
Author

Syphist commented Aug 25, 2020

I have figured out the solution and have updated my code accordingly and have cleaned it up. I have tested both with the pasted character in the ascii file and the escape code and both work. This is also much faster than my initial sed implementation. I have updated the OP to reflect these changes as well as clarify a few things.

exu-g added a commit to exu-g/neofetch that referenced this pull request Oct 30, 2020
@Z-8Bit
Copy link

Z-8Bit commented Jul 27, 2021

+1 I agree, it's much needed this.

@thenick775
Copy link

+1 this modification works well for me, have tested on Big Sur

Screen Shot 2021-12-27 at 9 54 00 PM

@fvegaswp
Copy link

Just tested this with colored ascii generated with lolcat and works great.

@jonaramos
Copy link

Tested with colored ascii generated from jp2a and ascii-image-converter. Thanks Syphist.
image

@hykilpikonna
Copy link

Lol I actually ran into this issue while creating HyFetch. My solution was to pass in a separate ascii_len variable:

image

Thanks a lot!

@hykilpikonna
Copy link

Works!

image

hykilpikonna added a commit to hykilpikonna/hyfetch that referenced this pull request Aug 12, 2022
…scii art line length calculations

Upstream PR: dylanaraps/neofetch#1543
Thanks to @Syphist

Co-authored-by: Syphist <[email protected]>
@hykilpikonna
Copy link

Thank you for your contribution!

This PR is merged into hyfetch since this repo (dylanaraps/neofetch) seems no longer maintained.

HyFetch is a fork of neofetch with LGBTQ pride flags, but the repo also maintains an updated version of the original neofetch, addressing many pull requests that are not merged in the original repo.

Read the "Running Updated Original Neofetch" section for more info!

@hykilpikonna
Copy link

I found a bug in the last line of strip_escape_codes:

-     eval "$2=\"${output}\""
+     eval "$2='${output}'"

If there exists $ signs in the ascii art, this eval statement will replace the $ with a variable content. You should use single quotes to prevent this.

Before Fix:

image

After Fix:

image

neofetch Outdated Show resolved Hide resolved
Proposed by hykilpikonna. Fixes a bug that evals stuff that follows $ characters.

Co-authored-by: Hykilpikonna <[email protected]>
hykilpikonna added a commit to hykilpikonna/hyfetch that referenced this pull request Aug 23, 2022
@Syphist
Copy link
Author

Syphist commented Aug 23, 2022

I have committed your fix. Thanks for finding a solution and testing further.

@hykilpikonna
Copy link

Okay I found another bug lol

- while IFS=$'\n' read -r line; do
+ while IFS=$'\n' read line; do

The width is incorrectly calculated for ascii distros with backslashes in them (e.g. Bedrock) because the backslashes were not treated as escape characters in read -r while they are actually escaped when defining the ASCII:

image

So, if read -r is used, the escaped backslash (\\) will not be resolved as one character but two characters, making the ascii length longer. (hykilpikonna/hyfetch#19)

Before Fix:

image

After Fix:

image

hykilpikonna added a commit to hykilpikonna/hyfetch that referenced this pull request Sep 5, 2022
@Syphist
Copy link
Author

Syphist commented Sep 5, 2022

Thanks @hykilpikonna I fixed the issue on my fork as well just in case this ever gets merged upstream to neofetch or if someone bothers to use my fork.

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

Successfully merging this pull request may close these issues.

6 participants