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

Conversation

Bastian-Krause
Copy link
Member

Description
bash >= 5.1 and readline >= 8.1 enable bracketed-paste mode by default, allowing the terminal emulator to tell a program whether input was typed or pasted. To achieve this, \e[?2004h is inserted when user input is expected enabling paste detection. \e[?2004l is inserted to disable it.

To handle the escape sequences, match the enable sequence between marker and prompt. The disable sequence is already stripped by the regex removing all VT100 codes.

See pexpect/pexpect#669

Tested with readline 8.1 and bash 5.1.16

Checklist

  • CHANGES.rst has been updated
  • PR has been tested

Fixes #969

bash >= 5.1 and readline >= 8.1 enable bracketed-paste mode by default,
allowing the terminal emulator to tell a program whether input was typed
or pasted. To achieve this, "\e[?2004h" is inserted when user input is
expected enabling paste detection. "\e[?2004l" is inserted to disable
it.

To handle the escape sequences, match the enable sequence between marker
and prompt. The disable sequence is already stripped by the regex
removing all VT100 codes.

Signed-off-by: Bastian Krause <bst@pengutronix.de>
@codecov
Copy link

codecov bot commented Aug 23, 2022

Codecov Report

Merging #975 (5e038e6) into master (f30264b) will not change coverage.
The diff coverage is n/a.

@@          Coverage Diff           @@
##           master    #975   +/-   ##
======================================
  Coverage    61.7%   61.7%           
======================================
  Files         150     150           
  Lines       11219   11219           
======================================
  Hits         6932    6932           
  Misses       4287    4287           
Impacted Files Coverage Δ
labgrid/driver/shelldriver.py 27.3% <ø> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Member

@jluebbe jluebbe left a comment

Choose a reason for hiding this comment

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

Isn't it possible to disable this feature?

_, _, 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.

@Bastian-Krause
Copy link
Member Author

Isn't it possible to disable this feature?

We could run bind 'set enable-bracketed-paste off' (right after dmesg -n 1) to disable it. But we would still need to relax the pattern in _check_prompt(), because that's expected before the commands can be issued.

@ynezz
Copy link
Contributor

ynezz commented May 9, 2024

(Was directed here from the discussion in #1397, so just my 2 cents)

On the one hand it feels a bit like a work-around

+2 (myself and @khilman #1397 (comment))

We could run bind 'set enable-bracketed-paste off' (right after dmesg -n 1) to disable it.

This feature is supposed to be functional on the DUT; therefore, disabling the feature and conducting the test without it contradicts the purpose of the testing, doesn't it?

but on the other you could probably argue that this belongs to the prompt somewhat

IMO it belongs to the underlying shell/terminal, not the prompt itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bracketed-paste mode makes ShellDriver prompt detection fail
3 participants