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

Add a newline if the prompt is too long #599

Open
Rmano opened this issue Apr 1, 2020 · 4 comments
Open

Add a newline if the prompt is too long #599

Rmano opened this issue Apr 1, 2020 · 4 comments
Labels
enhancement Feature request

Comments

@Rmano
Copy link
Contributor

Rmano commented Apr 1, 2020

Shell: zsh
Operating system: linux Ubuntu 18.04
Liquid Prompt version (tag, commit): 5f4aeec

I am trying to add a newline to the prompt only if the characters left are less than, say, 30. In plain zsh you can use the %-30 prompt directive, so I tried

export LP_PS1_POSTFIX=$'%-30(l:\n> :)'

...but it is doing nothing. Is there a correct way to do this?

Thanks for the nice software!

@Rycieos
Copy link
Collaborator

Rycieos commented Jun 26, 2020

I'm assuming that that type of expansion doesn't work because we set the nopromptsubst option:
https://github.com/nojhan/liquidprompt/blob/af63c4cfb8afe3f3161f3ace4aba3b940847a7a8/liquidprompt#L1942-L1943

You could try enabling it yourself and seeing if it will then expand this option.

I like this idea though, and want to see it added as a feature. This means we couldn't rely on zsh specific things obviously.

@Rycieos Rycieos added the enhancement Feature request label Jun 26, 2020
@Rycieos Rycieos added this to the v2.1 milestone Jun 26, 2020
@Rmano
Copy link
Contributor Author

Rmano commented Jul 2, 2020

I tried this in my .zshrc:

liquidprompt=$HOME/software/liquidprompt/liquidprompt
[[ -f $liquidprompt ]] && source $liquidprompt
# see https://github.com/nojhan/liquidprompt/issues/599
setopt promptsubst
export LP_PS1_POSTFIX=$'%-30(l:\n> :)'

...but still not working. Well, I'll wait...

PandaWill pushed a commit to PandaWill/liquidprompt that referenced this issue Sep 9, 2020
Add new setting LP_MINIMUM_CMD_LENGTH, which controls when a newline is
added.

See feature request liquidprompt#599.
PandaWill pushed a commit to PandaWill/liquidprompt that referenced this issue Sep 9, 2020
Add new setting LP_MINIMUM_CMD_LENGTH, which controls when a newline is
added.

See feature request liquidprompt#599.
PandaWill pushed a commit to PandaWill/liquidprompt that referenced this issue Sep 10, 2020
Add new setting LP_MINIMUM_SPACE_AFTER_PROMPT. A new line is added when the prompt would leave less space than this in the terminal.

See feature request liquidprompt#599.
PandaWill pushed a commit to PandaWill/liquidprompt that referenced this issue Feb 1, 2021
Add new setting LP_MINIMUM_SPACE_AFTER_PROMPT. A new line is added when the prompt would leave less space than this in the terminal.

See feature request liquidprompt#599.
PandaWill pushed a commit to PandaWill/liquidprompt that referenced this issue Feb 1, 2021
Add new setting LP_MINIMUM_SPACE_AFTER_PROMPT. A new line is added when the prompt would leave less space than this in the terminal.

See feature request liquidprompt#599.
PandaWill pushed a commit to PandaWill/liquidprompt that referenced this issue Apr 28, 2021
Add new setting LP_MINIMUM_SPACE_AFTER_PROMPT. A new line is added when the prompt would leave less space than this in the terminal.

See feature request liquidprompt#599.
PandaWill pushed a commit to PandaWill/liquidprompt that referenced this issue Sep 23, 2021
Add new setting LP_MINIMUM_SPACE_AFTER_PROMPT. A new line is added when the prompt would leave less space than this in the terminal.

See feature request liquidprompt#599.
@Rycieos Rycieos modified the milestones: v2.1, v2.2 May 25, 2022
@nojhan
Copy link
Collaborator

nojhan commented Dec 23, 2022

What are your ideas about the following options for generalizing @PandaWill's idea?

  1. Allow to automatically switch theme when the current prompt overflows the terminal width. Cons: this would need some specific themes to actually implement the prompt shortening (like a heavily multi-line theme); this allows for only two options. Pros: this is very simple, with the current code; this may be generalized later as an automatic theme switcher ("if this state matches this, switch to this theme").
  2. Allow for several, ordered, breakable markers, which would be activated if the prompt overflows. Themes would need to be updated to add markers (I'm thinking something like $LP_BREAK_1, $LP_BREAK_2), which would be replaced either by an empty space or a new line. Pros: this allows for adaptation to any terminal width. Cons: this is more complicated to implement (need to check that themes do not use duplicate breaks, for instance) which may hinder speed.

@Rycieos
Copy link
Collaborator

Rycieos commented Dec 26, 2022

What are your ideas about the following options for generalizing @PandaWill's idea?

I really like your second idea. I have another one:
3. A priority system for each section, where if maximum prompt width and/or lines are reached, lowest priority sections are not displayed. Could be combined with idea 2 to still define where to break.

Unfortunately I think that is beyond the possibility of the Liquid Prompt engine...

I think something like 2 could be possible, if not very complicated...

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

No branches or pull requests

3 participants