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

feat(line_break): add break_below_width option #5760

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

OddBloke
Copy link
Contributor

@OddBloke OddBloke commented Feb 6, 2024

Description

When specified, this option will change line_break's behaviour to only insert a line break when the width of the terminal is below the given value.

Motivation and Context

I value being able to see as much of my terminal history as possible, so my current starship configuration disables line_break. This is disadvantageous in narrow terminals, as commands I type are more likely to wrap and my right prompt may not be displayed at all.

Setting an appropriate break_below_width value allows users like me to increase the vertical space used by their prompt only when horizontal space is at a premium: I don't "lose" lines of history off the top of my screen except when doing so will give me more space to type and/or mean that my right prompt will be displayed.

Screenshots (if appropriate):

These screenshots are of the same prompt with only the width of the terminal changed:

startship-bbw-wide
starship-bbw-narrow

How Has This Been Tested?

I have built starship locally with this change (on an Ubuntu 20.04 system) and tested it by:

  • setting break_below_width and resizing my terminal across the boundary to observe its behaviour
  • unsetting break_below_width and confirming that a line break is always emitted

Additionally, there are cargo test tests to ensure that the correct output is being emitted.

  • I have tested using MacOS
  • I have tested using Linux
  • I have tested using Windows

Checklist:

  • I have updated the documentation accordingly.
  • I have updated the tests accordingly.

@OddBloke
Copy link
Contributor Author

OddBloke commented Feb 6, 2024

This change was inspired by my current custom zsh prompt, which will insert a newline if my prompt will leave me below a certain amount of space on-screen:

    PROMPT_PREFIX="<my actual prompt value>"
    # I want 20 characters of space available assuming 24 characters for RPROMPT
    MAX_PROMPT_LENGTH=$((COLUMNS-24-20))
    PROMPT="$(print "$PROMPT_PREFIX%$MAX_PROMPT_LENGTH(l.\n.)%# ")"

(The magic here is in zsh prompt escaping: %<number>(l.\n.)% means (approximately; this is my first time revisiting this part of my .zshrc in about a decade 😅) "if at least <number> characters have already been printed on this line, then emit \n otherwise emit nothing".)

@OddBloke OddBloke force-pushed the oddbloke/break_below_width branch 2 times, most recently from 1bce0f4 to 69dfa90 Compare February 12, 2024 19:30
When specified, this option will change `line_break`'s behaviour to only
insert a line break when the width of the terminal is below the given
value.  This allows users to increase the vertical space used by their
prompt only when horizontal space is at a premium.

(This is particularly useful when a right prompt is configured, as a
sufficiently long left prompt may mean it is never displayed in smaller
terminals with `line_break` completely disabled.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant