Skip to content

how to save a history of previous input ? #20

Closed
@mokun

Description

@mokun

Thanks to #17 that I now have the autocomplete setup for my program.

There are times that I would like to reenter the same input that I made in the past.

Is there an elegant way to program the Left and Right arrow keys to scroll backward and forward the input ?

I come up with this in SwingHandler but fall short of what to do next ?

    private static final String KEY_STROKE_LEFT = "pressed LEFT";
    private static final String KEY_STROKE_RIGHT = "pressed RIGHT";
    private String historyInput = "";
    private int historyIndex = -1;
    private String[] history = {};

  public SwingHandler(SwingTextTerminal terminal) {
        this.terminal = terminal;
        terminal.registerHandler(KEY_STROKE_LEFT, t -> {
            if (historyIndex >= 0) {
                historyIndex--;
                String text = (historyIndex < 0) ? historyInput : choices[historyIndex ];
                t.replaceInput(text, false);
            }
            return new ReadHandlerData(ReadInterruptionStrategy.Action.CONTINUE);
        });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions