feat(graphics): expose immutable screen snapshot capture
- commit
- a67ed127d9dfc4faf6be8cd27e4bd969acc3fd64
- author
- brice · · 2026-08-20 15:11 UTC
- parent
- 35da577
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
2 files · +8 -0
M graphics_state.go +7 -0
| @@ -84,3 +84,10 @@ func (s *Screen) GraphicsSnapshot() *graphics.Snapshot { | |||
| 84 | 84 | } | |
| 85 | 85 | return s.graphics.snapshot() | |
| 86 | 86 | } | |
| 87 | + | ||
| 88 | + | // CaptureGraphicsSnapshot names the ownership boundary used by renderers that | |
| 89 | + | // retain graphics independently of the text frame. The returned reference is | |
| 90 | + | // immutable and remains valid after subsequent Screen mutations. | |
| 91 | + | func (s *Screen) CaptureGraphicsSnapshot() *graphics.Snapshot { | |
| 92 | + | return s.GraphicsSnapshot() | |
| 93 | + | } | |
| @@ -84,3 +84,10 @@ func (s *Screen) GraphicsSnapshot() *graphics.Snapshot { | |||||
| 84 | } | 84 | } | ||
| 85 | return s.graphics.snapshot() | 85 | return s.graphics.snapshot() | ||
| 86 | } | 86 | } | ||
| 87 | + | ||||
| 88 | + | // CaptureGraphicsSnapshot names the ownership boundary used by renderers that | |||
| 89 | + | // retain graphics independently of the text frame. The returned reference is | |||
| 90 | + | // immutable and remains valid after subsequent Screen mutations. | |||
| 91 | + | func (s *Screen) CaptureGraphicsSnapshot() *graphics.Snapshot { | |||
| 92 | + | return s.GraphicsSnapshot() | |||
| 93 | + | } | |||
M screen_graphics_test.go +1 -0
| @@ -90,6 +90,7 @@ func TestScreenSnapshotCapturesOwnedActiveGraphicsSnapshot(t *testing.T) { | |||
| 90 | 90 | captured := screen.Snapshot() | |
| 91 | 91 | require.NotNil(t, captured.Graphics()) | |
| 92 | 92 | require.Equal(t, uint64(1), captured.Graphics().Usage().Placements) | |
| 93 | + | require.Equal(t, captured.Graphics().Usage(), screen.CaptureGraphicsSnapshot().Usage(), "capture returns the immutable active-scene reference") | |
| 93 | 94 | ||
| 94 | 95 | screen.Write([]byte("\x1b[2J")) | |
| 95 | 96 | require.Equal(t, uint64(1), captured.Graphics().Usage().Placements) | |
| @@ -90,6 +90,7 @@ func TestScreenSnapshotCapturesOwnedActiveGraphicsSnapshot(t *testing.T) { | |||||
| 90 | captured := screen.Snapshot() | 90 | captured := screen.Snapshot() | ||
| 91 | require.NotNil(t, captured.Graphics()) | 91 | require.NotNil(t, captured.Graphics()) | ||
| 92 | require.Equal(t, uint64(1), captured.Graphics().Usage().Placements) | 92 | require.Equal(t, uint64(1), captured.Graphics().Usage().Placements) | ||
| 93 | + | require.Equal(t, captured.Graphics().Usage(), screen.CaptureGraphicsSnapshot().Usage(), "capture returns the immutable active-scene reference") | |||
| 93 | 94 | ||||
| 94 | screen.Write([]byte("\x1b[2J")) | 95 | screen.Write([]byte("\x1b[2J")) | ||
| 95 | require.Equal(t, uint64(1), captured.Graphics().Usage().Placements) | 96 | require.Equal(t, uint64(1), captured.Graphics().Usage().Placements) | ||