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

Resizing Breaks Completer #586

Open
Evynglais opened this issue Oct 8, 2020 · 3 comments
Open

Resizing Breaks Completer #586

Evynglais opened this issue Oct 8, 2020 · 3 comments

Comments

@Evynglais
Copy link

Hi,

If you resize during a readLine call with a completer active, the completer doesn't resize properly and ends up with options thrown all over the place (as shown). They also don't disappear once the word has been matched (even if I use CTRL+C to exit the search).

The image also shows the known completer overlapping issue, so just ignore that (I already know you're fixing in 3.16.1), I've temporarily 'fixed' it by using a blank right prompt which overlaps the overlapped line.

Before resize:

image

After resize:

image

For info I'm using the terminal defined by the following:

Terminal terminal = TerminalBuilder.builder() .system(false) .type(environment.getEnv().get(Environment.ENV_TERM)).streams(in, out).size(new Size(Integer.parseInt(environment.getEnv().get(Environment.ENV_COLUMNS)),Integer.parseInt(environment.getEnv().get(Environment.ENV_LINES)))).build();

And using Windows PS (inside Windows Terminal app) and PuTTY to test. The issue is the same on both.

The completer I'm using is the ArgumentCompleter with a StringsCompleter and NullCompleter.INSTANCE (the String is using a List).

@mattirn
Copy link
Collaborator

mattirn commented Oct 8, 2020

If you cannot use system terminal which handles WINCH signal automatically then you have to implement a signal listener yourself. See an example: ShellFactoryImpl.java#L219-L223.
Maybe you could also use JLine remote-ssh or remote-telnet if you use remote connection. I do not know if remote-telnet has signal support.

@Evynglais
Copy link
Author

Evynglais commented Oct 9, 2020

Hm.. I've got this signal listener (pictured), which is similar to the one in the ShellFactoryImpl. It works fine for the terminal, i.e. if I resize and print values then they'll be the correct size for the re-adjusted terminal. My main issue however, is that the completer doesn't resize/disable on resize. So if I TAB for auto-complete and resize, I get the issue above, where the completer text is skewed and permanent (i.e. it doesn't disappear after I finish completing, as it normally does). Resizing works perfectly fine everywhere else.

Any idea how I can force the completer to either disable and re-enable or handle the window resize mid-input?

image

@mattirn
Copy link
Collaborator

mattirn commented Oct 9, 2020

I have been able to reproduce the problem. It will happen when the candidates do not fit to the visible area of the display when resizing window. I think this can be fixed only in JLine.

You can create a widget to refresh tab completions:

groovy-repl> def refreshCompleter() {
add: }     >     _widget('clear-screen')
add: }     >     _widget('list-choices')
add: }     > }
groovy-repl> widget -N _refresh-completer refreshCompleter
groovy-repl> keymap '^[r' _refresh-completer
groovy-repl> 
groovy-repl>  # now press alt-r to refresh completions

To write this in java see example in Widgets and key mapping

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

No branches or pull requests

2 participants