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

Issue With Resizing Command Prompt With Status Bar #939

Closed
philiprichens opened this issue Feb 12, 2024 · 4 comments
Closed

Issue With Resizing Command Prompt With Status Bar #939

philiprichens opened this issue Feb 12, 2024 · 4 comments
Assignees
Milestone

Comments

@philiprichens
Copy link

philiprichens commented Feb 12, 2024

I've attached a short test program which shows the issue when using 3.25.1. When the status bar is visible, resizing a Command Prompt on Windows causes the status bar to be repeated across the window.

Here's a screen shot showing the result.

ScreenShot-StatusBar

import java.io.IOException;
import java.util.Collections;
import org.jline.reader.LineReader;
import org.jline.reader.LineReaderBuilder;
import org.jline.terminal.Terminal;
import org.jline.terminal.TerminalBuilder;
import org.jline.utils.AttributedStringBuilder;
import org.jline.utils.Log;
import org.jline.utils.Status;

public class TestStatusBar {

    public static void main(String[] args) throws IOException {
        TestStatusBar tester = new TestStatusBar();
        tester.processInput();
    }

    private final Terminal terminal;
    private final LineReader reader;
    private Status status;
    
    public TestStatusBar() throws IOException {
        terminal = TerminalBuilder.builder().build();
        Log.info(terminal.getClass().getSimpleName());
        reader = LineReaderBuilder.builder()
                .terminal(terminal)
                .build();
    }

    public void processInput() {
        while (true) {
            String line = reader.readLine("TESTSTATUSBAR> ");
            if (status == null) {
                status = Status.getStatus(terminal, true);                        
            }
            AttributedStringBuilder attribStringBuilder = new AttributedStringBuilder();
            attribStringBuilder.append("something for the status bar: " + line);
            status.update(Collections.singletonList(attribStringBuilder.toAttributedString()));
            if (line.equalsIgnoreCase("QUIT")) {
                System.exit(0);
            }
        }
    }
}
@mattirn
Copy link
Collaborator

mattirn commented Feb 13, 2024

@philiprichens , after a resize, you need to redraw the terminal, see #902.

@philiprichens
Copy link
Author

To follow the advice in #902, I would need to handle the WINCH when LineReaderImpl is in readLine waiting for character input. But in this situation LineReaderImpl has replaced my handler with its own. Is there a way I can respond to WINCH even when waiting for character input? Even a clear screen following a resize would improve things.

@philiprichens
Copy link
Author

Playing with this some more, I can see that it is the redrawing of the status bar that is making a mess of the terminal window, and jline is at least in control of that. I can improve things somewhat if I override handleSignal like this:-

    @Override
    protected void handleSignal(Terminal.Signal signal) {            
        if (signal == Terminal.Signal.WINCH) {
            Status status = Status.getStatus(terminal, true);
            status.update(Collections.singletonList(new AttributedStringBuilder().toAttributedString()));
        }
        super.handleSignal(signal);
        if (signal == Terminal.Signal.WINCH) {
            Status status = Status.getStatus(terminal, false);
            AttributedStringBuilder attribStringBuilder = new AttributedStringBuilder();
            attribStringBuilder.append("something for the status bar");
            status.update(Collections.singletonList(attribStringBuilder.toAttributedString()));
        }
    }        

However, there is then a problem with the prompt disappearing that I am unsure how to resolve. Perhaps one of the jline contributors will know what to do to mend that?

This is at least enough to make me think it should be possible to resolve this issue successfully within jline. It is such a shame at the moment, because it does makes the status bar rather unusable.

@gnodet gnodet self-assigned this Mar 9, 2024
@gnodet gnodet added this to the 3.26.0 milestone Mar 9, 2024
@gnodet
Copy link
Member

gnodet commented Apr 19, 2024

@philiprichens could you give a try to the #969 PR to see if that improve things ? It's not perfect, but it fixes a bunch of problems I think.

@gnodet gnodet closed this as completed in 0028516 Apr 22, 2024
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

3 participants