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

lp fill incompatible with  _lp_analog_time #814

Open
nojhan opened this issue Dec 3, 2023 · 5 comments
Open

lp fill incompatible with  _lp_analog_time #814

nojhan opened this issue Dec 3, 2023 · 5 comments
Labels

Comments

@nojhan
Copy link
Collaborator

nojhan commented Dec 3, 2023

When using LP_TIME_ANALOG, the clock character is two-characters wide in a terminal with fixed-size font, hence making computation of the width by lp_fill wrong by one character, making the end of line overshooting.

Liquid Prompt version: v2.2.0.rc-2

Steps to Reproduce

LP_TIME_ANALOG=1 ; LP_ENABLE_TIME=1 ; source liquidprompt/theme/unfold.theme ; lp_theme unfold

Expected Behavior

Line width should not overshoot.

Possible Solution

Add an option in lp_fill to force aiming at width minus n characters, so that themes using it can fix width computation whenever some option (here, at least LP_TIME_ANALOG) is active or not.

@nojhan nojhan added the bug label Dec 3, 2023
@Rycieos
Copy link
Collaborator

Rycieos commented Dec 3, 2023

Yeah, this is a tricky one. My dream is to have a function that will take a string and return its printable width. I did some research in the past on this, and it is pretty impossible to do in Shell. The best idea I had was to print the string, and ask the terminal where the cursor ended up. That is guaranteed to be the correct answer, but it means more terminal emulator hacking, and if the terminal emulator is not fast, the user might see a flicker of the string before it gets overwritten.

But if we can't get a perfect solution, I guess your hack could work. It sounds super hacky though, and not likely to be easy for themes to do correctly.

@nojhan
Copy link
Collaborator Author

nojhan commented Dec 3, 2023

Another option would be to add a space after all the clock characters, right at declaration. That way, the width will actually be explicitly two characters wide, which will allow lp_fill to have correct computations.

@Rycieos
Copy link
Collaborator

Rycieos commented Dec 3, 2023

Wait, does that work? Terminal emulators won't render that as 3 width wide?

@nojhan
Copy link
Collaborator Author

nojhan commented Dec 4, 2023

I thought I had tried that before and it was working (maybe for some characters, depending on metadata?), but at least here, with the clock characters, it does not.

@Rycieos
Copy link
Collaborator

Rycieos commented Dec 4, 2023

iTerm and MacOS Terminal render 🕐 as 3 characters wide:

$ printf '********\n***🕐 ***\n********\n'
********
***🕐 ***
********
Screenshot 2023-12-04 at 11 37 09 AM

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

No branches or pull requests

2 participants