Skip to content

Support for prompt #12

@mvysny

Description

@mvysny

Hi! Currently the XTerm class doesn't have support for setting the prompt string, e.g. $ . When I try to emulate the prompt by using write("$ "), there are two flaws:

  • The user is able to press backspace and delete the prompt
  • If the user types in something and presses Enter, the LineEvent line will start with the prompt itself.

Example code

@Route("")
public class MainView extends VerticalLayout {

    public MainView() {
        final XTerm xterm = new XTerm();
        add(xterm);
        xterm.setWidthFull();
        xterm.setHeight("500px");
        xterm.writeln("Hello!");
        xterm.setCursorStyle(ITerminalOptions.CursorStyle.UNDERLINE);
        xterm.setCursorBlink(true);
        xterm.write("$ ");
        xterm.addLineListener(e -> {
            System.out.println(e.getLine());
            xterm.writeln(e.getLine());
            xterm.write("$ ");
        });
    }
}

The first issue is easy to be reproduced, simply press Backspace right away and see the prompt being deleted.

The second issue is also easy to reproduce, simply type in bbb and press Enter. I expect that e.getLine() would only contain bbb (since that's what the user typed) but it contains $ bbb instead.

This issue can be observed on the 2.0 branch of the addon.

Expected behavior

  • I should be able to display a prompt using write() function
  • the arrow keys, home key or backspace/delete keys should not move cursor over the prompt
  • The prompt should not be returned as a part of the LineEvent.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions