From 96b1a1c79c4fc64fe2b688c1fed4719bba58d7af Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Fri, 30 Oct 2020 14:11:27 +0200 Subject: [PATCH] Fixed an issue with a "wrong" timestamp in device monitor output using `"time" filter` // Resolve #3712 --- HISTORY.rst | 1 + platformio/commands/device/filters/time.py | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index d239b46e..80d24872 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -20,6 +20,7 @@ PlatformIO Core 5 - Fixed an "AssertionError: ensure_dir_exists" when checking library updates from simultaneous subprocesses (`issue #3677 `_) - Fixed an issue when `pio package publish `__ command removes original archive after submitting to the registry (`issue #3716 `_) - Fixed an issue when multiple `pio lib install `__ command with the same local library results in duplicates in ``lib_deps`` (`issue #3715 `_) +- Fixed an issue with a "wrong" timestamp in device monitor output using `"time" filter `__ (`issue #3712 `_) 5.0.1 (2020-09-10) ~~~~~~~~~~~~~~~~~~ diff --git a/platformio/commands/device/filters/time.py b/platformio/commands/device/filters/time.py index 203e6aa9..0c2d8884 100644 --- a/platformio/commands/device/filters/time.py +++ b/platformio/commands/device/filters/time.py @@ -22,13 +22,16 @@ class Timestamp(DeviceMonitorFilter): def __init__(self, *args, **kwargs): super(Timestamp, self).__init__(*args, **kwargs) - self._first_text_received = False + self._line_started = False def rx(self, text): - if self._first_text_received and "\n" not in text: + if self._line_started and "\n" not in text: return text timestamp = datetime.now().strftime("%H:%M:%S.%f")[:-3] - if not self._first_text_received: - self._first_text_received = True - return "%s > %s" % (timestamp, text) + if not self._line_started: + self._line_started = True + text = "%s > %s" % (timestamp, text) + if text.endswith("\n"): + self._line_started = False + return text[:-1].replace("\n", "\n%s > " % timestamp) + "\n" return text.replace("\n", "\n%s > " % timestamp)