feat: Handle CPR and colors in shell output#23
Merged
Conversation
Some platforms can use CPR (Cursor Position Report) to report the cursor position in the terminal. This can cause issues when processing shell output, as it may include CPR sequences. Additionally, some platforms may include color codes in the shell output, which can also interfere with processing. Signed-off-by: Lasota, Adrian <adrian.lasota@intel.com>
Contributor
|
We don't publish DEVs .whl. |
There was a problem hiding this comment.
Pull request overview
Improves Telnet login/prompt detection robustness by handling ANSI/VT control sequences (including CPR) and cleaning command output (ANSI + carriage returns), with corresponding test updates.
Changes:
- Add ANSI-aware shell prompt fallback matching and CPR-response recovery logic during login/prompt detection.
- Strip ANSI escape sequences and
\rfrom captured command output for cleaner logs/processing. - Update unit tests to reflect the new login/prompt flow and add coverage for ANSI stripping / recovery logic.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
mfd_connect/telnet/telnet.py |
Adds ANSI fallback prompt matching, CPR recovery during login, and output cleaning. |
mfd_connect/util/serial_utils.py |
Introduces shared regex/constants for ANSI escape handling, CPR detection/response, and login recovery tuning. |
mfd_connect/util/__init__.py |
Re-exports newly added serial/telnet-related constants for consumption across the package. |
tests/unit/test_mfd_connect/test_telnet/test_telnet.py |
Updates login/prompt tests and adds new tests for ANSI stripping, CPR recovery, and output cleaning. |
mfd_connect/serial.py |
Adjusts type hint for serial_logs_path to properly include None. |
Comments suppressed due to low confidence (1)
mfd_connect/telnet/telnet.py:181
- In _establish_telnet_connection(), the login is skipped when password is None (
self._password is not None). This conflicts with the new “optional password” flow: if a platform requires only a username (or a blank password), the code will never call_login()and will remain at the login prompt. Consider triggering_login()whenever a username is provided (and not in pre-OS), and let_enter_credentials()decide whether to wait for a password prompt based onself._password.
for _ in range(self._execution_retries):
try:
logger.log(level=log_levels.MODULE_DEBUG, msg="Trying to connect to target...")
self._connect()
if self.console.is_connected():
if not self._in_pre_os() and (self._username and self._password is not None):
logger.log(level=log_levels.MODULE_DEBUG, msg="Trying to login to console...")
self._login()
return
else:
logger.log(
level=log_levels.MODULE_DEBUG, msg="Credentials weren't provided. Skipping login part"
)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
mchromin
approved these changes
Apr 14, 2026
abaczek
approved these changes
Apr 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Some platforms can use CPR (Cursor Position Report) to report the cursor position in the terminal. This can cause issues when processing shell output, as it may include CPR sequences. Additionally, some platforms may include color codes in the shell output, which can also interfere with processing.
This pull request significantly improves the robustness and flexibility of Telnet login handling, especially for terminals emitting ANSI/VT control sequences in prompts. The changes introduce fallback prompt detection, enhanced handling of cursor position requests, and improved output cleaning. The test suite is updated to reflect the new logic and ensure reliability.
Telnet login and prompt handling improvements:
mfd_connect/telnet/telnet.py,mfd_connect/util/serial_utils.py,mfd_connect/util/__init__.py) [1] [2] [3]mfd_connect/telnet/telnet.py,mfd_connect/util/serial_utils.py) [1] [2]mfd_connect/telnet/telnet.py) [1] [2]Output cleaning and usability:
mfd_connect/telnet/telnet.py,mfd_connect/util/serial_utils.py) [1] [2]Test updates:
tests/unit/test_mfd_connect/test_telnet/test_telnet.py) [1] [2] [3] [4] [5]These changes make the Telnet connection process more robust against a wider variety of shell environments and improve maintainability and observability through better logging and test coverage.