Merge remote-tracking branch 'upstream/inline-ansi-reset' into integration

This commit is contained in:
J. Nick Koston
2026-03-15 20:34:53 -10:00
+13 -3
View File
@@ -128,12 +128,22 @@ struct LogBuffer {
}
}
void finalize_() {
// Write color reset sequence
static constexpr uint16_t RESET_COLOR_LEN = sizeof(ESPHOME_LOG_RESET_COLOR) - 1;
this->write_(ESPHOME_LOG_RESET_COLOR, RESET_COLOR_LEN);
this->write_ansi_reset_();
// Null terminate
this->data[this->full_() ? this->size - 1 : this->pos] = '\0';
}
// Write ANSI reset sequence inline ("\033[0m") - avoids write_() call overhead
static constexpr uint16_t ANSI_RESET_LEN = 4; // "\033[0m"
void write_ansi_reset_() {
if (this->remaining_() >= ANSI_RESET_LEN) {
char *p = this->current_();
*p++ = '\033';
*p++ = '[';
*p++ = '0';
*p++ = 'm';
this->pos += ANSI_RESET_LEN;
}
}
void strip_trailing_newlines_() {
while (this->pos > 0 && this->data[this->pos - 1] == '\n')
this->pos--;