Append ANSI reset on parse_log_message single-line fast path#1682
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1682 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 25 25
Lines 4156 4159 +3
=========================================
+ Hits 4156 4159 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
PR Review — Append ANSI reset on parse_log_message single-line fast pathClean, minimal, well-scoped fix. The single-line fast path now mirrors the multi-line first-line and Checklist
SummaryClean, minimal, well-scoped fix. The single-line fast path now mirrors the multi-line first-line and Automated review by Kōan7480f3f |
The single-line fast path returned the text with timestamp but skipped the trailing-reset check applied on the multi-line first-line path and in LogParser.parse_line. A single chunk like "\x1b[31mhello" (color without inline reset) therefore left the terminal in red, so the next print would inherit the colour — the same bleed bug fixed by esphome#1680 for multi-line first lines.
Rebase with requested adjustmentsBranch StatsActions performed
CI statusCI will be checked asynchronously. Automated by Kōan |
7480f3f to
e2ab484
Compare
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughThe PR fixes ANSI color bleed in single-line log messages by appending ChangesANSI Reset Bleed Prevention
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR fixes ANSI color “bleed” for single-line log messages by ensuring the parse_log_message single-line fast path appends an ANSI reset when a color code is present without a trailing reset, matching the behavior already applied in other parsing paths.
Changes:
- Update
parse_log_messagesingle-line fast path to appendANSI_RESETwhen_needs_reset(text)is true (andstrip_ansi_escapesis false). - Add targeted tests covering: reset appended, no double-reset, and no reset added when stripping ANSI escapes.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
aioesphomeapi/log_parser.py |
Appends ANSI reset in the single-line fast path when needed to prevent terminal color bleed. |
tests/test_log_parser.py |
Adds regression tests validating correct reset behavior for single-line messages and strip-ANSI mode. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
What does this implement/fix?
Append
ANSI_RESETon the single-line fast path ofparse_log_messagewhen the input text contains an ANSI colour codewithout a trailing reset.
Why
The fast path at
log_parser.py:159-160returned the text withtimestamp but skipped the
_needs_resetcheck that the multi-linefirst-line path (PR #1680) and
LogParser.parse_linealready apply.A single chunk like
"\x1b[31mhello"(colour, no inline reset)therefore left the terminal in red, so the next print inherited
the colour — the same bleed bug fixed for multi-line first lines.
How
Mirror the existing first-line handling: in the fast path, when
strip_ansi_escapesis off and_needs_reset(text)is true,append
ANSI_RESETbefore returning. No change to thestrip_ansipath (resets are stripped along with everything else) or to text
that already ends with a reset.
Testing
Three new assertions in
tests/test_log_parser.py:test_single_line_color_no_reset_bleed_prevention— reset appendedtest_single_line_color_with_reset_unchanged— no double-resettest_single_line_strip_ansi_no_reset— strip path stays cleanpytest tests/ -x -q→ 1069 passed.ruff check/ruff format --check→ clean.Types of changes
Checklist
api.protowas modified, a linked pull request has been made to esphome with the same changes.tests/folder).Quality Report
Changes: 2 files changed, 37 insertions(+), 1 deletion(-)
Code scan: clean
Tests: failed (FAILED)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline