Skip to content

aio(fix[wait]): Match soft-wrapped text - #152

Open
tony wants to merge 5 commits into
masterfrom
fix/147-unwrapped-text-wait-for
Open

tony wants to merge 5 commits into
masterfrom
fix/147-unwrapped-text-wait-for

Conversation

@tony

@tony tony commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Fixes #147

Summary

  • Match str predicates in AsyncTerminalStream.wait_for() and PtySession.wait_for() strictly against Snapshot.unwrapped_text across DECAWM soft-wrapped rows while preserving hard linebreaks ("\n").
  • Add unwrapped_text on Snapshot, Screen, Terminal, and RegionView. A slice joins a wrap only where the relevant margins remain visible.
  • Add unwrap=False to Formatter, Snapshot.format(), and libvt.render() for unwrapped PLAIN and HTML output.
  • Preserve unwritten column gaps before continuation content while skipping SPACER_HEAD padding and trailing blanks.

Changes

Screen and Terminal Export

  • src/libvt/screen.py: add unwrap=False to format_rows_text() and expose Screen.unwrapped_text and RegionView.unwrapped_text.
  • src/libvt/terminal.py: add cached Snapshot.text and Snapshot.unwrapped_text, Terminal.unwrapped_text, and unwrap=False on Formatter, Snapshot.format(), and render().

Asyncio Transports

  • src/libvt/aio.py: match str predicates in AsyncTerminalStream.wait_for() and PtySession.wait_for() strictly against snapshot.unwrapped_text.

Tests and Documentation

  • tests/test_aio.py: test soft-wrapped substrings and hard-linebreak isolation across AsyncTerminalStream and POSIX open_pty().
  • tests/test_terminal.py: test unwrapped_text, Snapshot text caching, RegionView.unwrapped_text, libvt.render(..., unwrap=True), and Formatter(unwrap=True) across mid-word wraps, wide SPACER_HEAD wraps, CUP gaps, tmux capture-pane trimmed rows, and BCE continuation rows.
  • docs/topics/snapshots.md: document Snapshot.unwrapped_text, RegionView.unwrapped_text, and Snapshot.format(..., unwrap=True).
  • docs/topics/sync-and-asyncio.md and MIGRATION: document logical string predicates and show a callable that checks physical rows through Snapshot.text.
  • CHANGES: document logical string predicates and text export across Snapshot, Screen, Terminal, RegionView, Formatter, and render.

Test plan

  • test_async_terminal_stream_wait_for_soft_wrapped_substring and test_open_pty_wait_for_soft_wrapped_substring in tests/test_aio.py
  • Logical text, styled gaps, held frames, and visible margins in tests/test_terminal.py
  • uv run ruff format --check . and uv run ruff check .
  • uv run ty check on Linux across Python 3.12–3.15
  • uv run pytest -q including docstring and Markdown doctests
  • just -f docs/justfile sphinxopts="-W --keep-going" html

tony pushed a commit that referenced this pull request Dec 2, 2026
why: Preserve HTML gap spaces before BCE-styled continuation rows, keep
multi-line wait_for(str) predicates compatible, avoid re-allocating
Snapshot text strings, and align RegionView and render() with Screen.

what:
- Check row.used alongside text_used for HTML unwrap gap materialization
- Fall back to snap.text in wait_for(str) when predicate contains "\n"
- Cache Snapshot.text and Snapshot.unwrapped_text lazily on first read
- Add RegionView.unwrapped_text and libvt.render(..., unwrap=False)
- Update CHANGES (#152) under What's new using public API roles only
why: Long diagnostics must match string predicates even when terminal
     width wraps a word.

what:
- Expose soft-wrap-aware text in the screen and formatter
- Check logical substrings in async stream and PTY waits
- Cover wide wrapping and visible column gaps
temp-merge and others added 4 commits December 2, 2026 20:43
why: Logical text and HTML must preserve gaps that occupy display
     columns.

what:
- Preserve BCE gaps and support region and render exports
- Cache captured text and cover multi-row wait predicates
why: String waits need to follow hard line breaks independently of
     viewport width.

what:
- Use unwrapped snapshot text for string predicates
- Document and test logical stream and PTY waits
why: Logical text must join actual continuation rows and preserve gaps
     without pulling clipped cells into waits or output.

what:
- Reuse the logical text contract for stream and PTY waits
- Respect slice bounds and styled gaps in plain and HTML output
- Exercise partial regions, held wraps, and hard newline predicates
- Document physical row matching for existing string predicates
why: Record the branch's user-visible change in the unreleased notes.

what:
- Add the #152 entry under Breaking changes in CHANGES
- Add the #152 entry under What's new in CHANGES
@tony
tony force-pushed the fix/147-unwrapped-text-wait-for branch from 8b3c4e8 to 9aea65b Compare December 3, 2026 02:56

This branch was successfully deployed

1 active deployment
docs — 9aea65be Deployed Dec 3, 2026 by tony via build (3.14) #299
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wait_for misses string predicates split across soft-wrapped rows

1 participant