ss7m / paleofetch

neofetch, but written in C
MIT License
167 stars 49 forks source link

Should we make it possible to put the logo on the right? #44

Open allisio opened 4 years ago

allisio commented 4 years ago

I did a side-by-side of my current configuration and what I wish it looked like, and I thought maybe other folks would like to have the logo on the right (either justified or "as flush as possible" with the data like I have it in the demo).

The problem is this would be a fairly invasive change to the code. We wouldn't know how to position things until the end of data acquisition when we know the length of the longest line. A somewhat clean approach might be to gate all the right-alignment code behind an #ifdef RIGHT, and then instead of straight printf() in main(), we print to a string and then do all the magic on that iff we're trying to right-align. But then we're left dealing with the ANSI escape sequences contributing to line lengths.

It could get hairy, but I think this would be a nifty feature that sets us apart from neofetch (not that the absurd speed improvement is anything to scoff at).

ss7m commented 4 years ago

Dealing with the escape sequences wouldn't be toooo hard, since (aside from get_title) you can just subtract sizeof(COLOR) and sizeof("\e[0m"). Anything more complicated than that would likely involve having to parse ANSI escape sequences, which sounds... not fun.

And we already calculate the displayed length of get_title for get_bar anyways

ss7m commented 4 years ago

I believe snprintf returns the number of characters written, perhaps we can take advantage of that

ss7m commented 4 years ago

I'm working on a solution to finding the maximum length right now

ss7m commented 4 years ago

Check out my latest commit on the allignemt branch I just created. What do you make of that?

allisio commented 4 years ago

Hm... I think that's touching an awful lot of things, but maybe it's still the right way to do it.

I was thinking something more like this, where we just redirect where we're printing to. At the end, we have what we would've printed in output and can finagle it as necessary to reposition the logo.

That's the hard part, but I think you were right about just being able to subtract the lengths of some static strings in order to get a handle on how to start aligning.

ss7m commented 4 years ago

Yeah I became less and less of a fan of my solution as I wrote it. I'm interested to see what you can come up with

ss7m commented 4 years ago

Just a thought, but any UTF8 weirdness in any of the output would further complicate this