Skip to content

PreserveStateAddon issues when using a prompt #50

@jdewaen

Description

@jdewaen

I have found another issue, this time with the PreserveStateAddon. The core issue seems to be that the last (unsubmitted) prompt is also kept in the buffer. This looks visually fine, but for some reason it is considered part of the user input, even if the correct prompt is set before the preserved state is applied. My hypothesis is that this is because that final prompt isn't actually written with the writePrompt function on the client side, but I can't really confirm that given the complexity of xterm.js.

I have made a fork with a modified demo view that illustrates this issue: https://github.com/datadobi/XTermConsoleAddon/tree/preserve_state_demo

I have two ways to reproduce the issue:

1:

  • Run the demo. The terminal should appear with a "toggle terminal" button at the top
  • Click toggle terminal. The terminal should disappear
  • Click toggle terminal again, the terminal will reappear.
  • Enter a command, or press enter directly. You'll get the following error: Unknown command: [user@xterm.

2:

  • Run the demo. The terminal should appear with a "toggle terminal" button at the top
  • Run a few commands to fill the history
  • Click toggle terminal. The terminal should disappear
  • Click toggle terminal again, the terminal will reappear.
  • Press the up button: the most recent command will apear
  • Press the down button: the prompt will appear twice

I will open a pull request for a potential fix for this issue. It basically avoids writing the prompt to the buffer immediately, but waits until a line gets submitted. This means that we don't have a dangling prompt at the end of the buffer to get misinterpreted. To show the prompt as expected, writePrompt is called after writing the buffer when reattaching xterm. As far as I can see, this matches the old behavior exactly minus the issue. You can merge the fix branch onto the demo branch to quickly see the fix in action.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions