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

record user command correctly #236

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion terminado/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def open(self, url_component: Any = None) -> None: # type:ignore[override]
self.terminal.clients.append(self)
self.send_json_message(["setup", {}])
self._logger.info("TermSocket.open: Opened %s", self.term_name)
self.cursor_position = 0
# Now drain the preopen buffer, if reconnect.
buffered = ""
preopen_buffer = self.terminal.read_buffer.copy()
Expand Down Expand Up @@ -105,8 +106,31 @@ def on_message(self, message: str) -> None: # type:ignore[misc]
if command[1] == "\r":
self.log_terminal_output(f"STDIN: {self._user_command}")
self._user_command = ""
self.cursor_position = 0
elif command[1] == "\x7f":
# delete
if self.cursor_position > 0:
self._user_command = (
self._user_command[: self.cursor_position - 1]
+ self._user_command[self.cursor_position :]
)
self.cursor_position -= 1
elif command[1] == "\x1bOD":
# move left
if self.cursor_position > 0:
self.cursor_position -= 1
elif command[1] == "\x1bOC":
# move right
if self.cursor_position < len(self._user_command):
self.cursor_position += 1
else:
self._user_command += command[1]
# insert
self._user_command = (
self._user_command[: self.cursor_position]
+ command[1]
+ self._user_command[self.cursor_position :]
)
self.cursor_position += 1
elif msg_type == "set_size":
self.size = command[1:3]
self.terminal.resize_to_smallest()
Expand Down
Loading