-
Notifications
You must be signed in to change notification settings - Fork 421
fix(__lp_strip_escapes): remove Unicode's empty character #857
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
base: master
Are you sure you want to change the base?
Conversation
Allows the user to set configuration parameters that default to space(s) into an empty string without messing with displayed text length computation.
|
This seems to me to be over-complicating the problem. If the problem is the inability to set certain config values to the empty string, then there is a much easier way to solve it. From the Bash docs:
All of our config options are checked with So, it seems to me the much easier solution is to change the assignment of those config variables from Not all would need changing. Any config option that controls how Liquid Prompt works needs to never be null. But config options that are meant to be used as strings to display to the user should be changed. So I think these variables would be appropriate for that treatment: Lines 647 to 749 in b4e1d34
Note that Now, I imagine that you might still want the removal of the empty character. (By the way, which character are you using? And anyway, it seems you are only removing one certain character, and there are multiple zero width characters in Unicode. |
Allows the user to remove default spaces in some parameters.
Why?
When a configuration variable defaults as a space, it cannot be set to an empty string by the end user. The only way to effectively remove the default space is to use Unicode's empty character (U+0000).
Example:
In Liquid Prompt, the configuration variables managing spacing are set like that (see
LP_MARK_PREFIX,LP_MARK_ENV_VAR_SEP). In the default theme, using an empty character would just work. So far so good.But for themes using right alignment, it is necessary to compute the width of the displayed string. This is done by first running
__lp_strip_escapes, to get rid of escaped sequences, and then get the length of the remaining string.However, an empty character, while technically not really displayed, would still amount to the length computed by the shell, effectively ruining the expected behavior.
This patch proposes to consider that the empty character is akin to escaped sequences, and as such should be removed by
__lp_strip_escapes, which effectively fix the aforementioned behavior.Technical checklist:
_LP_SHELL_*)tests/test_*.shfiles)tests.shshellcheck.sh(requires shellcheck)... versionadded:: X.Yor.. versionchanged:: Y.Zdocs/docs-lint.sh(requires Python 3 andrequirements.txtinstalled (
cd docs/; python3 -m venv venv; . venv/bin/activate; pip install -r requirements.txt))