From 7703b638f3350b8b58af8a6616267f1daf7026a3 Mon Sep 17 00:00:00 2001 From: michael Date: Tue, 14 Jul 2026 12:52:33 -0700 Subject: [PATCH] fix(rawcli): drop extra blank line between trace lines The trace formatter's line now carries a trailing newline; rawcli was stripping only a leading one (.lstrip), so the trailing \n survived and the printer added another -> a blank line between every trace line (and a \n\n join inside render_exchange). Use .strip("\n") so it's correct whether the formatter emits a leading or trailing newline. Co-Authored-By: Claude Opus 4.8 --- pm3py/cli/rawcli/identify.py | 6 +++--- pm3py/cli/rawcli/trace_view.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pm3py/cli/rawcli/identify.py b/pm3py/cli/rawcli/identify.py index 08fc19d..6361151 100644 --- a/pm3py/cli/rawcli/identify.py +++ b/pm3py/cli/rawcli/identify.py @@ -150,7 +150,7 @@ def identify(session, emit=None) -> dict: # always emit ANSI; the app's printer renders it (and strips it off a non-terminal) fmt = TraceFormatter(mode="reader", decoder=_ident_decode, crc_len=0, is_tty=True) for direction, data in _activation_frames(scan): - emit(fmt.format(direction, data).lstrip("\n")) + emit(fmt.format(direction, data).strip("\n")) model, version = None, None if scan.get("sak") == 0x00: # UL/NTAG family — ask GET_VERSION model, version = _probe_version(dev, fmt, emit) @@ -180,14 +180,14 @@ def identify(session, emit=None) -> dict: def _probe_version(dev, fmt, emit) -> tuple[str | None, bytes | None]: """Send a real GET_VERSION (0x60 +CRC), trace the exchange, decode the exact model.""" cmd = b"\x60" - emit(fmt.format(0, cmd).lstrip("\n")) + emit(fmt.format(0, cmd).strip("\n")) resp = _try(lambda: dev.hf.iso14a.raw(cmd, flags=ISO14A_APPEND_CRC), None) raw = resp.get("raw") if isinstance(resp, dict) else None if not raw: return None, None version = bytes(raw[:8]) display = bytes(raw).rstrip(b"\x00") or version # drop the firmware buffer padding - emit(fmt.format(1, display).lstrip("\n")) + emit(fmt.format(1, display).strip("\n")) model = decode_version(version) if model: emit(f" → {model}") diff --git a/pm3py/cli/rawcli/trace_view.py b/pm3py/cli/rawcli/trace_view.py index 1b009fe..8f8b6ab 100644 --- a/pm3py/cli/rawcli/trace_view.py +++ b/pm3py/cli/rawcli/trace_view.py @@ -18,7 +18,7 @@ def render_exchange(command: bytes, response: bytes | None, *, if present, a ``Tag → Reader`` line for ``response``. ``is_tty`` forces/suppresses ANSI.""" decoder, crc_len = _PROTOCOLS.get(protocol, (None, 0)) fmt = TraceFormatter(mode="reader", decoder=decoder, crc_len=crc_len, is_tty=is_tty) - lines = [fmt.format(0, bytes(command)).lstrip("\n")] + lines = [fmt.format(0, bytes(command)).strip("\n")] if response: - lines.append(fmt.format(1, bytes(response)).lstrip("\n")) + lines.append(fmt.format(1, bytes(response)).strip("\n")) return "\n".join(lines)