zsh-users
 help / color / mirror / code / Atom feed
* Limiting height of completion menu
@ 2020-12-19 18:53 Vincent Bernat
  2020-12-19 20:30 ` Bart Schaefer
  0 siblings, 1 reply; 13+ messages in thread
From: Vincent Bernat @ 2020-12-19 18:53 UTC (permalink / raw)
  To: zsh-users

Hey!

I was wondering if it would have been possible to limit the height of
the completion menu. I am using:

zstyle ':completion:*' menu yes=long select

Ideally, if the completion menu could not be more than half the screen,
it would be great, this way, I keep the top of the screen intact when
trying to complete. I have looked around in the source code, and it
seems the "long" option is hardcoding "LINES" to detect if it should
trigger the menu and in the C code, it uses zterm_lines to control how
the menu is displayed. But maybe it's possible to tell ZLE that LINES is
in fact half the real lines?

Thanks.
-- 
You may my glories and my state dispose,
But not my griefs; still am I king of those.
		-- William Shakespeare, "Richard II"


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Limiting height of completion menu
  2020-12-19 18:53 Limiting height of completion menu Vincent Bernat
@ 2020-12-19 20:30 ` Bart Schaefer
  2020-12-19 21:05   ` Vincent Bernat
  2020-12-19 21:38   ` Vincent Bernat
  0 siblings, 2 replies; 13+ messages in thread
From: Bart Schaefer @ 2020-12-19 20:30 UTC (permalink / raw)
  To: Vincent Bernat; +Cc: Zsh Users

On Sat, Dec 19, 2020 at 10:53 AM Vincent Bernat <bernat@luffy.cx> wrote:
>
> I was wondering if it would have been possible to limit the height of
> the completion menu. I am using:
>
> zstyle ':completion:*' menu yes=long select

This seems to work:

autoload add-zsh-hook
autoload add-zle-hook-widget
half-lines() {
  LINES=$((LINES/2))
}
full-lines() {
  # Force terminal query
  LINES=0
}
comp-lines() {
  full-lines
  compprefuncs=( half-lines )
}
add-zsh-hook preexec full-lines
add-zle-hook-widget line-init comp-lines

However, there is an odd side-effect in that the command line is
temporarily garbled if you are NOT using menu-select and the "do you
wish to see all X possibilities" prompt is printed.  It fixes itself
as soon as you answer yes/no, but it's curious that it happens in the
first place.

Note it does not work to use comppostfuncs=( full-lines ) ... the
comppostfuncs are run before menu-selection determines the screen
size.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Limiting height of completion menu
  2020-12-19 20:30 ` Bart Schaefer
@ 2020-12-19 21:05   ` Vincent Bernat
  2020-12-19 21:38   ` Vincent Bernat
  1 sibling, 0 replies; 13+ messages in thread
From: Vincent Bernat @ 2020-12-19 21:05 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Users

 ❦ 19 décembre 2020 12:30 -08, Bart Schaefer:

>> I was wondering if it would have been possible to limit the height of
>> the completion menu. I am using:
>>
>> zstyle ':completion:*' menu yes=long select
>
> This seems to work:
>
> autoload add-zsh-hook
> autoload add-zle-hook-widget
> half-lines() {
>   LINES=$((LINES/2))
> }
> full-lines() {
>   # Force terminal query
>   LINES=0
> }
> comp-lines() {
>   full-lines
>   compprefuncs=( half-lines )
> }
> add-zsh-hook preexec full-lines
> add-zle-hook-widget line-init comp-lines

Yes, it works great! Thanks!
-- 
Program defensively.
            - The Elements of Programming Style (Kernighan & Plauger)


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Limiting height of completion menu
  2020-12-19 20:30 ` Bart Schaefer
  2020-12-19 21:05   ` Vincent Bernat
@ 2020-12-19 21:38   ` Vincent Bernat
  2020-12-19 22:03     ` Bart Schaefer
  1 sibling, 1 reply; 13+ messages in thread
From: Vincent Bernat @ 2020-12-19 21:38 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Users

 ❦ 19 décembre 2020 12:30 -08, Bart Schaefer:

> However, there is an odd side-effect in that the command line is
> temporarily garbled if you are NOT using menu-select and the "do you
> wish to see all X possibilities" prompt is printed.  It fixes itself
> as soon as you answer yes/no, but it's curious that it happens in the
> first place.

Unfortunately, it's also garbled when there is a non-ambiguous match:

echo ~/do<tab>

becomes

echo ~/doecho ~/download/

It happens at the bottom of the screen or at the top. Dunno what's the
relation with LINES is.
-- 
Keep it right when you make it faster.
            - The Elements of Programming Style (Kernighan & Plauger)


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Limiting height of completion menu
  2020-12-19 21:38   ` Vincent Bernat
@ 2020-12-19 22:03     ` Bart Schaefer
  2020-12-19 22:12       ` Vincent Bernat
  0 siblings, 1 reply; 13+ messages in thread
From: Bart Schaefer @ 2020-12-19 22:03 UTC (permalink / raw)
  To: Vincent Bernat; +Cc: Zsh Users

On Sat, Dec 19, 2020 at 1:38 PM Vincent Bernat <bernat@luffy.cx> wrote:
>
> Unfortunately, it's also garbled when there is a non-ambiguous match

Try this change:

half-lines() {
  LINES=$((LINES/2))
  tput cr
}

I have no idea why that's needed.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Limiting height of completion menu
  2020-12-19 22:03     ` Bart Schaefer
@ 2020-12-19 22:12       ` Vincent Bernat
  2020-12-19 22:15         ` Bart Schaefer
  0 siblings, 1 reply; 13+ messages in thread
From: Vincent Bernat @ 2020-12-19 22:12 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Users

 ❦ 19 décembre 2020 14:03 -08, Bart Schaefer:

>> Unfortunately, it's also garbled when there is a non-ambiguous match
>
> Try this change:
>
> half-lines() {
>   LINES=$((LINES/2))
>   tput cr
> }
>
> I have no idea why that's needed.

It also resets $LINES in my case.
-- 
10.0 times 0.1 is hardly ever 1.0.
            - The Elements of Programming Style (Kernighan & Plauger)


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Limiting height of completion menu
  2020-12-19 22:12       ` Vincent Bernat
@ 2020-12-19 22:15         ` Bart Schaefer
  2020-12-19 22:24           ` Vincent Bernat
  2020-12-20 14:41           ` Stephane Chazelas
  0 siblings, 2 replies; 13+ messages in thread
From: Bart Schaefer @ 2020-12-19 22:15 UTC (permalink / raw)
  To: Vincent Bernat; +Cc: Zsh Users

On Sat, Dec 19, 2020 at 2:12 PM Vincent Bernat <bernat@luffy.cx> wrote:
>
> It also resets $LINES in my case.

Yeah, I just noticed that.  Sometimes you have to save ZLE from itself.

half-lines () {
        print -n $(tput sc)
        LINES=$((LINES/2))
        print -n $(tput rc)
}


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Limiting height of completion menu
  2020-12-19 22:15         ` Bart Schaefer
@ 2020-12-19 22:24           ` Vincent Bernat
  2020-12-19 23:26             ` Bart Schaefer
  2020-12-20 14:41           ` Stephane Chazelas
  1 sibling, 1 reply; 13+ messages in thread
From: Vincent Bernat @ 2020-12-19 22:24 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Users

 ❦ 19 décembre 2020 14:15 -08, Bart Schaefer:

>> It also resets $LINES in my case.
>
> Yeah, I just noticed that.  Sometimes you have to save ZLE from itself.
>
> half-lines () {
>         print -n $(tput sc)
>         LINES=$((LINES/2))
>         print -n $(tput rc)
> }

It doesn't seem to fix the garbled non-select completion.

This simpler solution seems to work for me:

zstyle -e ':completion:*' menu 'reply=(yes=$((LINES/2)) select)'
_vbe_half-lines() {
    LINES=$((LINES/2))
}
_vbe_full-lines() {
    # Force terminal query
    LINES=0
}
add-zsh-hook preexec _vbe_full-lines
add-zle-hook-widget line-init _vbe_half-lines

Its scope is wider than completion, but it doesn't seem to break
anything for me.
-- 
10.0 times 0.1 is hardly ever 1.0.
            - The Elements of Programming Style (Kernighan & Plauger)


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Limiting height of completion menu
  2020-12-19 22:24           ` Vincent Bernat
@ 2020-12-19 23:26             ` Bart Schaefer
  2020-12-19 23:30               ` Vincent Bernat
  0 siblings, 1 reply; 13+ messages in thread
From: Bart Schaefer @ 2020-12-19 23:26 UTC (permalink / raw)
  To: Vincent Bernat; +Cc: Zsh Users

On Sat, Dec 19, 2020 at 2:24 PM Vincent Bernat <bernat@luffy.cx> wrote:
>
> It doesn't seem to fix the garbled non-select completion.

Fooey.

> This simpler solution seems to work

Yes, obviously I was trying to avoid having it go outside completion scope.

I think having $((LINES/2)) both in line-init and in the zstyle is
going to result in "menu yes=" with a value of your actual lines
divided by four, but maybe that's what you intended.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Limiting height of completion menu
  2020-12-19 23:26             ` Bart Schaefer
@ 2020-12-19 23:30               ` Vincent Bernat
  0 siblings, 0 replies; 13+ messages in thread
From: Vincent Bernat @ 2020-12-19 23:30 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Users

 ❦ 19 décembre 2020 15:26 -08, Bart Schaefer:

>> It doesn't seem to fix the garbled non-select completion.
>
> Fooey.
>
>> This simpler solution seems to work
>
> Yes, obviously I was trying to avoid having it go outside completion scope.
>
> I think having $((LINES/2)) both in line-init and in the zstyle is
> going to result in "menu yes=" with a value of your actual lines
> divided by four, but maybe that's what you intended.

Oh, right! I can just use yes=long.
-- 
Don't use conditional branches as a substitute for a logical expression.
            - The Elements of Programming Style (Kernighan & Plauger)


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Limiting height of completion menu
  2020-12-19 22:15         ` Bart Schaefer
  2020-12-19 22:24           ` Vincent Bernat
@ 2020-12-20 14:41           ` Stephane Chazelas
  2020-12-20 21:55             ` Bart Schaefer
  1 sibling, 1 reply; 13+ messages in thread
From: Stephane Chazelas @ 2020-12-20 14:41 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Vincent Bernat, Zsh Users

2020-12-19 14:15:30 -0800, Bart Schaefer:
> On Sat, Dec 19, 2020 at 2:12 PM Vincent Bernat <bernat@luffy.cx> wrote:
> >
> > It also resets $LINES in my case.
> 
> Yeah, I just noticed that.  Sometimes you have to save ZLE from itself.
> 
> half-lines () {
>         print -n $(tput sc)

Or rather:

  print -rn $terminfo[sc]

Or:

  printf %s $terminfo[sc]

Or

  echoti sc

Or if tput is to cover the cases where zsh/terminfo is not
included:

  tput sc


>         LINES=$((LINES/2))

Or:

(( LINES /= 2 ))

-- 
Stephane


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Limiting height of completion menu
  2020-12-20 14:41           ` Stephane Chazelas
@ 2020-12-20 21:55             ` Bart Schaefer
  2020-12-21 12:22               ` Vincent Bernat
  0 siblings, 1 reply; 13+ messages in thread
From: Bart Schaefer @ 2020-12-20 21:55 UTC (permalink / raw)
  To: Bart Schaefer, Vincent Bernat, Zsh Users

On Sun, Dec 20, 2020 at 6:41 AM Stephane Chazelas <stephane@chazelas.org> wrote:
>
> 2020-12-19 14:15:30 -0800, Bart Schaefer:
> > half-lines () {
> >         print -n $(tput sc)
>
> Or if tput is to cover the cases where zsh/terminfo is not
> included:
>
>   tput sc

That doesn't actually work as expected; for some reason running "tput"
directly from the current shell causes a zle reset and the bug
returns, probably due to some sort of handling of the forked job.
Hiding it in a $(...) subshell prevents that (but the whole
formulation still has other problems).


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Limiting height of completion menu
  2020-12-20 21:55             ` Bart Schaefer
@ 2020-12-21 12:22               ` Vincent Bernat
  0 siblings, 0 replies; 13+ messages in thread
From: Vincent Bernat @ 2020-12-21 12:22 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Users

 ❦ 20 décembre 2020 13:55 -08, Bart Schaefer:

>> > half-lines () {
>> >         print -n $(tput sc)
>>
>> Or if tput is to cover the cases where zsh/terminfo is not
>> included:
>>
>>   tput sc
>
> That doesn't actually work as expected; for some reason running "tput"
> directly from the current shell causes a zle reset and the bug
> returns, probably due to some sort of handling of the forked job.
> Hiding it in a $(...) subshell prevents that (but the whole
> formulation still has other problems).

Some completions also reset the state. File completion is working but
for example, apt completion is resetting the state (maybe because there
is some fork involved to grab the information).

I may have better luck proposing a patch to Zsh to be able to have a
maximum height for the completion menu.
-- 
The lunatic, the lover, and the poet,
Are of imagination all compact...
		-- Wm. Shakespeare, "A Midsummer Night's Dream"


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2020-12-21 12:23 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-19 18:53 Limiting height of completion menu Vincent Bernat
2020-12-19 20:30 ` Bart Schaefer
2020-12-19 21:05   ` Vincent Bernat
2020-12-19 21:38   ` Vincent Bernat
2020-12-19 22:03     ` Bart Schaefer
2020-12-19 22:12       ` Vincent Bernat
2020-12-19 22:15         ` Bart Schaefer
2020-12-19 22:24           ` Vincent Bernat
2020-12-19 23:26             ` Bart Schaefer
2020-12-19 23:30               ` Vincent Bernat
2020-12-20 14:41           ` Stephane Chazelas
2020-12-20 21:55             ` Bart Schaefer
2020-12-21 12:22               ` Vincent Bernat

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).