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

driver/shelldriver: handle bracketed-paste mode #975

Closed
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ New Features in 0.5.0
- Support for QEMU Q35 machine added.
- `UBootDriver` now handles idle console, allowing driver activation on
an interupted U-Boot.
- `ShellDriver` now handles bracketed-paste mode (default in bash >= 5.1,
readline >= 8.1)

Bug fixes in 0.5.0
~~~~~~~~~~~~~~~~~~
Expand Down
6 changes: 4 additions & 2 deletions labgrid/driver/shelldriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ def _run(self, cmd, *, timeout=30.0, codec="utf-8", decodeerrors="strict"):
# hide marker from expect
cmp_command = f'''MARKER='{marker[:4]}''{marker[4:]}' run {shlex.quote(cmd)}'''
self.console.sendline(cmp_command)
# match output by run function, bracketed-paste escape sequence (optionally), prompt
_, _, match, _ = self.console.expect(
rf'{marker}(.*){marker}\s+(\d+)\s+{self.prompt}',
rf'{marker}(.*){marker}\s+(\d+)\s+(\x1b\[\?2004h)?{self.prompt}',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only matches the escape sequence at a specific location, which seems fragile.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If (on a given system) this always appears at the start of the prompt, the user could add this to their prompt regex instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. On the one hand it feels a bit like a work-around, but on the other you could probably argue that this belongs to the prompt somewhat. So I agree that we consider this a valid solution.

timeout=timeout
)
# Remove VT100 Codes, split by newline and remove surrounding newline
Expand Down Expand Up @@ -200,8 +201,9 @@ def _check_prompt(self):
# hide marker from expect
self.console.sendline(f"echo '{marker[:4]}''{marker[4:]}'")
try:
# match marker, bracketed-paste escape sequence (optionally), prompt
self.console.expect(
rf"{marker}\s+{self.prompt}",
rf"{marker}\s+(\x1b\[\?2004h)?{self.prompt}",
timeout=5
)
self._status = 1
Expand Down