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

Recalculate screen size on window resize #230

Closed
MenkeTechnologies opened this issue Mar 18, 2021 · 7 comments
Closed

Recalculate screen size on window resize #230

MenkeTechnologies opened this issue Mar 18, 2021 · 7 comments
Assignees
Labels
enhancement New feature or request

Comments

@MenkeTechnologies
Copy link

MenkeTechnologies commented Mar 18, 2021

  • zsh-autocomplete version: 7662f28
  • Zsh version: 5.8
  • Framework: omz
  • Plugin manager: zinit
 # Make sure you always test with the `main` branch.
$ git -C /path/to/zsh-autocomplete switch main

# Update to the latest commit.
$ git -C /path/to/zsh-autocomplete pull

# Create a temp dir and enter it.
$ cd $(mktemp -d)

# Restart Zsh without config files in this dir.
$ ZDOTDIR=$PWD HOME=$PWD exec zsh -f

# Source the plugin.
% source /path/to/zsh-autocomplete/zsh-autocomplete.plugin.zsh

# Test and document the steps that reproduce the problem.
% <insert your steps to reproduce here>

.autocomplete.screen-space only runs on precmd. Therefore _autocomplete__max_lines is incorrect when terminal was resized, prompt was moved up down without command running. In other words _autocomplete__screen_space is incorrect in these scenarios until precmd. Because of this, you can get stuck in loop where every letter typed results in listscroll mode.

.autocomplete.async.list-choices.complete() {
   # .autocomplete.screen-space
  local -i _autocomplete__max_lines=$(( _autocomplete__max_lines() ))

_autocomplete__max_lines() {
  local -i lines; zstyle -s ":autocomplete:${curcontext}:" list-lines lines ||
    lines=16
  return $(( max( lines, _autocomplete__screen_space - BUFFERLINES ) ))
}
.autocomplete.screen-space() {
  emulate -L zsh; setopt $_autocomplete__options

  local -a reply=()
  print -nr $'\e[6n'
  IFS=$'\e[;' read -Asd R
  local -i y=$reply[-2]
  local -i pslines=${#${(%%)PS1}//[^$'\n']}
  _autocomplete__screen_space=$(( LINES - y - pslines - 2 ))
}

Fix would be to recalculate _autocomplete__screen_space before each list-choices

@MenkeTechnologies MenkeTechnologies added the bug Something isn't working label Mar 18, 2021
@marlonrichert
Copy link
Owner

Fix would be to recalculate _autocomplete__screen_space before each list-choices

Be my guest. Patches welcome. 🙂

@marlonrichert marlonrichert added the help wanted Extra attention is needed label Mar 18, 2021
@MenkeTechnologies
Copy link
Author

MenkeTechnologies@500fd85

i am not sure how to calculate the y value as this breaks my prompt

  local -a reply=()
  print -nr $'\e[6n'
  IFS=$'\e[;' read -Asd R
  local -i y=$reply[-2]
  local -i pslines=${#${(%%)PS1}//[^$'\n']}

I tried to use BUFFERLINES but not sure.

@marlonrichert
Copy link
Owner

The problem is that normal read operations don't work while the Zsh Line Editor is active. You are limited to using only read -q or read -k [<num>].

You need to be able to determine the vertical position of the cursor somehow. Using $BUFFERLINES would work only when the command line starts at the top of the screen.

@marlonrichert marlonrichert changed the title .autocomplete.screen-space only runs on precmd bug .autocomplete.screen-space only runs on precmd Mar 23, 2021
@marlonrichert marlonrichert added enhancement New feature or request and removed bug Something isn't working labels Mar 23, 2021
@marlonrichert marlonrichert changed the title .autocomplete.screen-space only runs on precmd Recalculate screen size on window resize Apr 18, 2021
@marlonrichert
Copy link
Owner

Actually, I just realized, even though we can no longer query the terminal for the cursor after precmd, we can update the calculated screen to account for the new value of $COLUMNS on line-pre-redraw.

@marlonrichert marlonrichert self-assigned this Apr 18, 2021
marlonrichert added a commit that referenced this issue Apr 24, 2021
Fixes issue #230 and resolves discussion #240.
marlonrichert added a commit that referenced this issue Apr 24, 2021
Fixes issue #230 and resolves discussion #240.
@marlonrichert
Copy link
Owner

Done.

@marlonrichert marlonrichert removed the help wanted Extra attention is needed label Apr 24, 2021
@marlonrichert marlonrichert reopened this May 31, 2021
@marlonrichert
Copy link
Owner

@MenkeTechnologies I found a better solution. Patch coming soon.™

@marlonrichert
Copy link
Owner

Nah, never mind; it didn't really work. The best solution is simply to press ⬇️. That will expand the menu as far as possible. 🙂

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants