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 <noreply@anthropic.com>
This commit is contained in:
@@ -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}")
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user