Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Low-memory terminal state implementation #1584

Merged
merged 430 commits into from
Mar 27, 2024
Merged
Changes from 1 commit
Commits
Show all changes
430 commits
Select commit Hold shift + click to select a range
373462b
terminal2: starting to port kitty graphics
mitchellh Mar 5, 2024
9277df1
terminal2: delete kitty by intersecting cursor
mitchellh Mar 5, 2024
ad051cf
terminal2/kitty: tests pass
mitchellh Mar 6, 2024
7bcb982
terminal2: use new kitty stack
mitchellh Mar 6, 2024
e3778dd
terminal2: most imports
mitchellh Mar 6, 2024
c8803df
terminal2: more imports
mitchellh Mar 6, 2024
4055f8a
terminal2: more imports
mitchellh Mar 6, 2024
0f5841b
terminal2: start Selection
mitchellh Mar 6, 2024
2f92243
terminal2: pagelist cellIterator
mitchellh Mar 6, 2024
83af8d1
terminal2: PageList pageIterator reverse
mitchellh Mar 6, 2024
6dd88c2
terminal2: PageList iterators all support reverse
mitchellh Mar 6, 2024
1f01b2c
terminal2: selection adjust right
mitchellh Mar 6, 2024
8194cb7
terminal2: sel adjust left
mitchellh Mar 6, 2024
a303b76
terminal2: adjust down
mitchellh Mar 6, 2024
5c04ebe
terminal2: adjust down edges
mitchellh Mar 6, 2024
7afe2e1
terminal2: sel adjust home/end
mitchellh Mar 6, 2024
3f59f51
terminal2: selection adjust done
mitchellh Mar 6, 2024
3cc2b95
terminal2: promote Selection
mitchellh Mar 6, 2024
0494caf
terminal2: a selection can be tracked or untracked
mitchellh Mar 6, 2024
3b55af3
terminal2: Pin iterators
mitchellh Mar 6, 2024
7ffefc9
terminal2: selectLine
mitchellh Mar 6, 2024
f91624a
terminal2: selectAll
mitchellh Mar 6, 2024
201ad4d
terminal2: more selectLine tests
mitchellh Mar 6, 2024
d97f861
terminal2: selectLine fixes
mitchellh Mar 7, 2024
56fc4d7
terminal2: selectWord starts
mitchellh Mar 7, 2024
f03b9f9
terminal2: selectWord more tests
mitchellh Mar 7, 2024
d9d3aa3
terminal2: selectWord done
mitchellh Mar 7, 2024
48f0724
terminal2: selectOutput
mitchellh Mar 7, 2024
a5d23a0
terminal2: selectPrompt
mitchellh Mar 7, 2024
90e96e0
terminal2: selection start/endPTr
mitchellh Mar 7, 2024
5fc4a9c
terminal2: selection topLeft/bottomRight
mitchellh Mar 7, 2024
0b3c502
terminal2: Selection.ordered
mitchellh Mar 7, 2024
9f78ec5
terminal2: contains selection
mitchellh Mar 7, 2024
7ee6447
terminal2: promptPath
mitchellh Mar 7, 2024
44986a0
terminal2: selectionString beginning
mitchellh Mar 7, 2024
3c7c2c6
terminal2: selectionString more tests
mitchellh Mar 7, 2024
01ceb7b
terminal2: selectionString with wide spacer head
mitchellh Mar 7, 2024
016db43
terminal2: zwjs in selectionString
mitchellh Mar 7, 2024
0b2b565
terminal2: selectionString with rect
mitchellh Mar 7, 2024
17cfdc0
terminal2: better blank line handling
mitchellh Mar 7, 2024
7fd85bd
terminal2: resize cols blank row preservation
mitchellh Mar 8, 2024
6b364f8
terminal: todo for paged-terminal
mitchellh Mar 8, 2024
a972a88
terminal: remove new import
mitchellh Mar 8, 2024
0e62076
Revert "terminal: remove new import"
mitchellh Mar 8, 2024
312eb05
terminal2: add Pin.cells
mitchellh Mar 8, 2024
e3230cf
font/shaper: start converting run to new terminal
mitchellh Mar 8, 2024
34200a3
font/shaper: more tests passing
mitchellh Mar 8, 2024
efe037b
font/shaper: test with bg only cells
mitchellh Mar 8, 2024
05470bb
font/shaper: new API
mitchellh Mar 8, 2024
cc4b5df
terminal2: export CursorStyle
mitchellh Mar 8, 2024
9b4ab0e
zig build test with renamed terminal package
mitchellh Mar 8, 2024
33e5970
terminal: Screen can hold selection
mitchellh Mar 9, 2024
d5236bc
terminal: more selection tests
mitchellh Mar 9, 2024
3687145
terminal-old: note test we skipped
mitchellh Mar 9, 2024
25d84d6
termio/exec: get compiler errors gone
mitchellh Mar 9, 2024
4c4d5f5
terminal/kitty: graphics exec ported
mitchellh Mar 9, 2024
d966e74
core: surface compiles
mitchellh Mar 9, 2024
c61de49
renderer/metal: port
mitchellh Mar 9, 2024
ea51e9b
inspector: todo on render
mitchellh Mar 9, 2024
a1e8a59
terminal: correct cols/rows order
mitchellh Mar 9, 2024
3154686
terminal: proper cursor copy for alt screen
mitchellh Mar 9, 2024
6255ab7
terminal: PageList resize should set styled on row if style copy
mitchellh Mar 9, 2024
7c7e611
terminal: test to ensure grapheme flag is set on row when resizing
mitchellh Mar 9, 2024
ae19a42
terminal: pagelist verify erasing history resets to one page
mitchellh Mar 9, 2024
bf79c04
terminal: erase complete deletes kitty images again
mitchellh Mar 9, 2024
775049e
terminal: PageList updates page size accounting when erasing page
mitchellh Mar 9, 2024
fdbda53
terminal: do not set selection manually
mitchellh Mar 9, 2024
45c38c6
terminal: clone uses opts struct
mitchellh Mar 10, 2024
434f01e
terminal: PageList.Clone can remap tracked pins
mitchellh Mar 10, 2024
ef6bb1d
terminal: Screen clone preserves cursor
mitchellh Mar 10, 2024
ba4f2ee
terminal: Screen.clone preserves selection
mitchellh Mar 10, 2024
ff0e07a
renderer/metal: re-enable the cursor, it works
mitchellh Mar 10, 2024
cf885b8
font/shaper: fix style for runs
mitchellh Mar 10, 2024
21f09a9
remove point.Viewport
mitchellh Mar 10, 2024
9c2a5bc
terminal: page size should be accounted every creation
mitchellh Mar 10, 2024
9830aac
terminal: pagelist resize handles soft-wrap across pages
mitchellh Mar 10, 2024
36c93ac
terminal: Pagelist reflow cursor in blank cell wrapped properly
mitchellh Mar 10, 2024
48d4079
terminal: bring back clearPromptForResize, with tests!
mitchellh Mar 10, 2024
9d6f668
terminal: resize create new pages as necessary
mitchellh Mar 10, 2024
5b93aca
terminal: PageList more resize tests
mitchellh Mar 10, 2024
c0e6eb4
terminal: PageList resize fix spacer issues with tests
mitchellh Mar 10, 2024
27d2903
terminal: don't insert newline across page boundaries
mitchellh Mar 10, 2024
3caf677
terminal: PageList resize blank lines at start of page
mitchellh Mar 10, 2024
8ccc30d
core: surface now tracks left click pin
mitchellh Mar 10, 2024
7525578
renderer/metal: show selections
mitchellh Mar 11, 2024
4254dc9
core: single click selection is on the way
mitchellh Mar 11, 2024
361fdd2
core: checkResetSelSwitch converted
mitchellh Mar 11, 2024
4d0f210
core: double-click drag
mitchellh Mar 11, 2024
edc0864
core: drag triple click
mitchellh Mar 11, 2024
6de661b
core: remove completed todos
mitchellh Mar 11, 2024
bb42ade
update TODO.md
mitchellh Mar 11, 2024
7ff5577
terminal: PageSize adjustCapacity for non-standard pages
mitchellh Mar 12, 2024
98b1693
terminal: PageList adjustCapacity should return new node and fix pins
mitchellh Mar 12, 2024
5e68bc6
terminal: resize page on unique style per cell
mitchellh Mar 12, 2024
dc04cc1
terminal: handle style ID overflow
mitchellh Mar 12, 2024
ab1a302
terminal: PageList.clone must use createPageExt for non-std pages
mitchellh Mar 12, 2024
a2e97a8
terminal: PageList adjustCap should start from original cap
mitchellh Mar 12, 2024
9137f52
terminal: resize cols without reflow handles higher caps
mitchellh Mar 12, 2024
03abde6
terminal: resize handles increased styles/graphemes
mitchellh Mar 12, 2024
49e8acb
core: configurable scrollback limit
mitchellh Mar 12, 2024
3191081
terminal: page.cloneFrom graphemes
mitchellh Mar 12, 2024
65909df
terminal: commented log line to see active style count
mitchellh Mar 12, 2024
37251dc
fix bench compilation
mitchellh Mar 12, 2024
e018059
core: re-enable click to move cursor
mitchellh Mar 12, 2024
1c4fb96
terminal: fix page size calculations on Linux
mitchellh Mar 12, 2024
0a6735d
terminal: jump to prompt
mitchellh Mar 12, 2024
1cdeace
core: remove incorrect std.meta.eql on selection
mitchellh Mar 12, 2024
5813304
terminal: dumpString options
mitchellh Mar 13, 2024
992c736
terminal: dumpScreen handles wrap
mitchellh Mar 13, 2024
3e247ba
core: write scrollback file works again
mitchellh Mar 13, 2024
d805fdd
core: mouse untracks pin in right screen
mitchellh Mar 13, 2024
347c57f
terminal: Selection.containedRow
mitchellh Mar 13, 2024
9eeaa0d
renderer/metal: re-enable selection awareness for shaping
mitchellh Mar 13, 2024
0a3f431
renderer/metal: almost bring back kitty images, some bugs
mitchellh Mar 13, 2024
d7ee705
terminal/kitty: calculate cell height more efficiently
mitchellh Mar 13, 2024
a697e97
renderer/metal: fix kitty image offset on screen
mitchellh Mar 13, 2024
1527936
core: only adjust selection on keypress
mitchellh Mar 13, 2024
44d320a
terminal: selectionString should use proper ordered
mitchellh Mar 13, 2024
a3509f3
terminal: selection should use pin iterators
mitchellh Mar 13, 2024
9351cab
terminal: Screen clone should preserve selection order
mitchellh Mar 13, 2024
7ae9b0c
terminal: screen clone that doesn't have sel should set null sel
mitchellh Mar 13, 2024
5b2f624
update TODO
mitchellh Mar 13, 2024
522c282
terminal: remove TODO
mitchellh Mar 13, 2024
935063d
core: scroll to selection working
mitchellh Mar 13, 2024
d1faa37
renderer/opengl: convert
mitchellh Mar 13, 2024
5c7460a
prettier
mitchellh Mar 13, 2024
2fe68eb
terminal: bitmap allocator had off by one on extra bitmaps
mitchellh Mar 14, 2024
c0ed1fa
terminal: pagelist can adjust grapheme byte capacity
mitchellh Mar 14, 2024
a59d428
terminal: adjust page capacity for graphemes if necessary
mitchellh Mar 14, 2024
9015b75
inspector: support cell pinning again
mitchellh Mar 14, 2024
62932f3
inspector: cell selection works again
mitchellh Mar 14, 2024
172d62c
inspector: get mouse points working
mitchellh Mar 14, 2024
55b4e49
inspector: forgot the new file
mitchellh Mar 14, 2024
b677460
inspector: add page system details
mitchellh Mar 14, 2024
aadd0d3
config: increase default max scrollback to 10MB
mitchellh Mar 14, 2024
dae4c3e
inspector: forgot another new file
mitchellh Mar 14, 2024
f4fa549
terminal: selectLine can disable whitespace/sem prompt splitting
mitchellh Mar 15, 2024
e18a777
terminal: screen lineIterator
mitchellh Mar 16, 2024
2de86ce
core: converting more to new screen state
mitchellh Mar 16, 2024
bca51ee
terminal: selectionString takes a struct for opts
mitchellh Mar 16, 2024
d664840
terminal: add StringMap back
mitchellh Mar 16, 2024
5664c3e
core: enable link hovering
mitchellh Mar 16, 2024
7419794
renderer: convert link to new state
mitchellh Mar 16, 2024
fd92804
renderer: re-enable URL underlining
mitchellh Mar 16, 2024
9630c39
terminal/page: improved capacity adjust logic
qwerasd205 Mar 15, 2024
869b6b1
terminal/page: improve capacity adjust cols tests
qwerasd205 Mar 15, 2024
7ad3195
ci: create PR releases
mitchellh Mar 16, 2024
fd38278
ci: PR builds for macOS should be ReleaseSafe
mitchellh Mar 16, 2024
533a867
ci: release PR on sync
mitchellh Mar 16, 2024
1ac0980
terminal: pruned pages should keep tracked pins in top-left
mitchellh Mar 17, 2024
a69d950
build ghostty nix package with ReleaseSafe
jcollie Mar 17, 2024
f0e3516
terminal: fix off-by-one tracked pin issues when page is pruned
mitchellh Mar 17, 2024
bf34582
allow building nix package with different optimizations
jcollie Mar 17, 2024
c8a3040
terminal: resizing to lt rows should not trim blanks with tracked pin
mitchellh Mar 18, 2024
b76995b
terminal: resizing greater cols without reflow should preserve cols
mitchellh Mar 18, 2024
e8a2dc5
terminal: cleaner impl of getTopLeft(.active)
mitchellh Mar 18, 2024
7e010ca
terminal: handle resizing into increased implicit max size
mitchellh Mar 18, 2024
e7a2a9b
terminal: resize no reflow must do cols before rows
mitchellh Mar 18, 2024
07a2707
inspector: needs to call new PageList.maxSize func
mitchellh Mar 18, 2024
3f0607d
terminal: PageList rowIterator respects limit row
mitchellh Mar 19, 2024
22c181c
terminal: insertLines uses iterators to handle pages
mitchellh Mar 19, 2024
2b50bd5
terminal: deleteLines assertion for same page
mitchellh Mar 19, 2024
5e1f8b6
terminal: insertLines/deleteLines handle split across pages
mitchellh Mar 19, 2024
1f62284
terminal: delete/insertLines uses correct page for clearing
mitchellh Mar 19, 2024
d54d7cd
terminal: set PageList viewport to active area when cloned
gpanders Mar 18, 2024
06d944c
terminal: cloneFrom clears destination
mitchellh Mar 19, 2024
26321dc
termio/exec: only clear above cursor if cursor is not on y=0
mitchellh Mar 19, 2024
1c57bba
termio/exec: clear screen should erase rows and shift up
mitchellh Mar 19, 2024
56feeb2
terminal: fullReset should reset cursor style
mitchellh Mar 19, 2024
b8d88fd
terminal: deleteLines with zero count should do nothing
mitchellh Mar 19, 2024
631fdf0
terminal: style needs to be copied to new page on scroll
mitchellh Mar 19, 2024
a40899f
terminal: only reload style if we're on a new page on scroll
mitchellh Mar 19, 2024
77362d9
terminal: resize should preserve cursor style ref
mitchellh Mar 19, 2024
f67b951
terminal: in all cursor move cases, we need to account for page changes
mitchellh Mar 20, 2024
9e42ee0
terminal: all cursorReload scenarios should check style data
mitchellh Mar 20, 2024
29a9d09
terminal: when overwriting wide spacer tail, clear graphemes
mitchellh Mar 20, 2024
e64d8f5
terminal: handles eraseRows that erases our full pagelist
mitchellh Mar 20, 2024
91602a4
terminal: Screen scroll test and handle single row screens
mitchellh Mar 20, 2024
9d826d8
terminal: add assertion for trackPin as commented
mitchellh Mar 20, 2024
3f23de4
terminal: remove completed todo
mitchellh Mar 20, 2024
b0c0307
terminal: eraseDisplay complete needs to delete kitty images
mitchellh Mar 20, 2024
a7f74a9
terminal: remove unnecessary todo
mitchellh Mar 20, 2024
cc75cc9
terminal: deleteChars should not split wide char cursor x
mitchellh Mar 21, 2024
dfa5b2e
terminal: pagelist handle scenario where reflow erases all pages
mitchellh Mar 21, 2024
565a5a6
terminal: bitmap allocator handles 64-chunk sized allocs
mitchellh Mar 21, 2024
1949b2b
terminal: BitmapAllocator supports allocations across bitmaps
mitchellh Mar 21, 2024
3513b1c
terminal: properly clear style in error scenario
mitchellh Mar 21, 2024
2d8810b
terminal: clear styles properly for clearing wide spacers
mitchellh Mar 21, 2024
8142eb9
terminal: moveCell handles graphemes, clears source
mitchellh Mar 21, 2024
1be06e8
terminal: add page.verifyIntegrity function
mitchellh Mar 21, 2024
1649641
terminal: add some integrity assertions
mitchellh Mar 21, 2024
2e9cc75
terminal: add integrity checks throughout PageList
mitchellh Mar 22, 2024
731f917
terminal: add Screen integrity checks, pepper them through cursors
mitchellh Mar 22, 2024
3b6ae68
terminal: add more integrity assertions
mitchellh Mar 22, 2024
4c35f35
terminal: get rid of some verifications, comment why
mitchellh Mar 22, 2024
40cac97
terminal: insertChars/deleteChars needs to account properly
mitchellh Mar 22, 2024
65696c9
terminal: clearcells only decs cursor ref if same page
mitchellh Mar 22, 2024
71c04db
terminal: fix cursor style on deleteLines
mitchellh Mar 22, 2024
f848ed2
terminal: handle row wrap integrity issues on reflow
mitchellh Mar 22, 2024
0bc831d
terminal: relax grapheme integrity check for fast paths
mitchellh Mar 22, 2024
ee5be26
terminal: prevent false positive integrity check
mitchellh Mar 22, 2024
cd30534
terminal: no scrollback eraseRows needs to fix style
mitchellh Mar 22, 2024
8818e4d
terminal: bitmapallocator handles perfectly divisble chunk size
mitchellh Mar 22, 2024
06a8e4a
terminal: spacer heads should only exist w/o l/r margin
mitchellh Mar 23, 2024
9685a56
terminal: clear unprotected row should preserve row attrs
mitchellh Mar 23, 2024
a301f7d
terminal: undo accidental debug logs
mitchellh Mar 23, 2024
25a5e07
terminal: more accidental logging
mitchellh Mar 23, 2024
eb6536f
address latest zig changes
mitchellh Mar 23, 2024
8c148fc
terminal: use std.meta.eql for equality checks
mitchellh Mar 23, 2024
e433289
terminal: avoid memory fragmentation if possible on col grow
mitchellh Mar 24, 2024
6cbe699
terminal: remove problematic test on 4k pages, still working on it
mitchellh Mar 24, 2024
225cc64
terminal: allow growing beyond max size for active area to fit
mitchellh Mar 24, 2024
f719999
terminal: add assertion to page integrity that row/col count > 0
mitchellh Mar 24, 2024
be3749f
terminal: decaln accounts for styles across pages
mitchellh Mar 24, 2024
3d6ae29
terminal: when reflowing, set style to default to prevent integrity fail
mitchellh Mar 24, 2024
1b8dc0c
terminal: add a test for resize less cols across pages with cursor
mitchellh Mar 25, 2024
36240b8
terminal: many more assertions around spacer state
mitchellh Mar 25, 2024
d1a0149
terminal: deleteChars must not shift a spacer head
mitchellh Mar 25, 2024
db3ab4b
terminal: pause page integrity can be nested
mitchellh Mar 25, 2024
3e84591
terminal: insertBlanks doesn't split spacer tail
mitchellh Mar 25, 2024
33ede13
terminal: fix release builds
mitchellh Mar 25, 2024
9ee0b23
terminal: clear spacer heads on growing cols w/o reflow
mitchellh Mar 25, 2024
dc85898
terminal: deleteChars resets row wrap state
mitchellh Mar 25, 2024
a58b03c
terminal: insertLines clears row wrap state
mitchellh Mar 25, 2024
62abecd
terminal: deleteLines resets line wrap
mitchellh Mar 25, 2024
705bd21
terminal: PageList trim blanks erases empty pages
mitchellh Mar 25, 2024
5904866
ci: try PR builds on Namespace
mitchellh Mar 25, 2024
41720b3
terminal: PageList support initialization of multi-page viewports
mitchellh Mar 25, 2024
efa18d6
Revert "ci: try PR builds on Namespace"
mitchellh Mar 25, 2024
fe43462
terminal: address todo to re-resolve 905
mitchellh Mar 25, 2024
e337ebe
terminal: add clonePartialRowFrom
mitchellh Mar 26, 2024
ad5d7b6
terminal: insert/deleteLines with L/R region across pages
mitchellh Mar 26, 2024
fcc0ea0
terminal: explicit error set for page clone
mitchellh Mar 26, 2024
7f1af89
terminal: turn unreachable into todo
mitchellh Mar 26, 2024
6c0609d
terminal: reset alt screen kitty keyboard state on full reset
gpanders Mar 25, 2024
1ad973b
Merge pull request #1609 from gpanders/kitty-alt-reset
mitchellh Mar 26, 2024
0a6ef3f
wip(terminal): Fast path for scroll regions
qwerasd205 Mar 25, 2024
9df9c99
fix(terminal): clear erased rows
qwerasd205 Mar 25, 2024
ddd7f3e
comments
qwerasd205 Mar 25, 2024
d74ea89
fastmem: rotateOnce
qwerasd205 Mar 26, 2024
23d32e2
perf(terminal): fast-paths for scrolling regions
qwerasd205 Mar 26, 2024
aadf795
fix(terminal): correctly use slow path for left/right scroll margin
qwerasd205 Mar 26, 2024
2274b8a
fix(terminal): don't reset x when indexing in scroll region
qwerasd205 Mar 26, 2024
492e147
terminal: clean up some code and comments
qwerasd205 Mar 26, 2024
d72eb30
fastmem: fix doc comment
qwerasd205 Mar 26, 2024
d17344b
perf(terminal/page): @memset micro-optimization
qwerasd205 Mar 26, 2024
ff30890
Merge pull request #1612 from qwerasd205/scroll-regions
mitchellh Mar 26, 2024
a416d42
remove old terminal implementation
mitchellh Mar 26, 2024
e639ca1
ci: try namespace again
mitchellh Mar 26, 2024
c2053cb
ci: release tip moves to namespace
mitchellh Mar 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
terminal2: delete kitty by intersecting cursor
mitchellh committed Mar 23, 2024
commit 9277df11272ad77dc36d60a7cf5947ba55ac2522
45 changes: 43 additions & 2 deletions src/terminal2/PageList.zig
Original file line number Diff line number Diff line change
@@ -1765,6 +1765,47 @@ pub const Pin = struct {
return .{ .row = rac.row, .cell = rac.cell };
}

/// Returns true if this pin is between the top and bottom, inclusive.
//
// Note: this is primarily unit tested as part of the Kitty
// graphics deletion code.
pub fn isBetween(self: Pin, top: Pin, bottom: Pin) bool {
if (comptime std.debug.runtime_safety) {
if (top.page == bottom.page) {
// If top is bottom, must be ordered.
assert(top.y <= bottom.y);
if (top.y == bottom.y) {
assert(top.x <= bottom.x);
}
} else {
// If top is not bottom, top must be before bottom.
var page = top.page.next;
while (page) |p| : (page = p.next) {
if (p == bottom.page) break;
} else assert(false);
}
}

if (self.page == top.page) {
if (self.y < top.y) return false;
if (self.y > top.y) return true;
return self.x >= top.x;
}
if (self.page == bottom.page) {
if (self.y > bottom.y) return false;
if (self.y < bottom.y) return true;
return self.x <= bottom.x;
}

var page = top.page.next;
while (page) |p| : (page = p.next) {
if (p == bottom.page) break;
if (p == self.page) return true;
}

return false;
}

/// Move the pin down a certain number of rows, or return null if
/// the pin goes beyond the end of the screen.
pub fn down(self: Pin, n: usize) ?Pin {
@@ -1785,7 +1826,7 @@ pub const Pin = struct {

/// Move the offset down n rows. If the offset goes beyond the
/// end of the screen, return the overflow amount.
fn downOverflow(self: Pin, n: usize) union(enum) {
pub fn downOverflow(self: Pin, n: usize) union(enum) {
offset: Pin,
overflow: struct {
end: Pin,
@@ -1823,7 +1864,7 @@ pub const Pin = struct {

/// Move the offset up n rows. If the offset goes beyond the
/// start of the screen, return the overflow amount.
fn upOverflow(self: Pin, n: usize) union(enum) {
pub fn upOverflow(self: Pin, n: usize) union(enum) {
offset: Pin,
overflow: struct {
end: Pin,
13 changes: 3 additions & 10 deletions src/terminal2/kitty/graphics_image.zig
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ const ArenaAllocator = std.heap.ArenaAllocator;

const command = @import("graphics_command.zig");
const point = @import("../point.zig");
const PageList = @import("../PageList.zig");
const internal_os = @import("../../os/main.zig");
const stb = @import("../../stb/main.zig");

@@ -451,16 +452,8 @@ pub const Image = struct {
/// be rounded up to the nearest grid cell since we can't place images
/// in partial grid cells.
pub const Rect = struct {
top_left: point.ScreenPoint = .{},
bottom_right: point.ScreenPoint = .{},

/// True if the rect contains a given screen point.
pub fn contains(self: Rect, p: point.ScreenPoint) bool {
return p.y >= self.top_left.y and
p.y <= self.bottom_right.y and
p.x >= self.top_left.x and
p.x <= self.bottom_right.x;
}
top_left: PageList.Pin,
bottom_right: PageList.Pin,
};

/// Easy base64 encoding function.
116 changes: 65 additions & 51 deletions src/terminal2/kitty/graphics_storage.zig
Original file line number Diff line number Diff line change
@@ -242,12 +242,17 @@ pub const ImageStorage = struct {
},

.intersect_cursor => |delete_images| {
if (true) @panic("TODO");
const target = (point.Viewport{
.x = t.screen.cursor.x,
.y = t.screen.cursor.y,
}).toScreen(&t.screen);
self.deleteIntersecting(alloc, t, target, delete_images, {}, null);
self.deleteIntersecting(
alloc,
t,
.{ .active = .{
.x = t.screen.cursor.x,
.y = t.screen.cursor.y,
} },
delete_images,
{},
null,
);
},

.intersect_cell => |v| {
@@ -378,18 +383,22 @@ pub const ImageStorage = struct {
fn deleteIntersecting(
self: *ImageStorage,
alloc: Allocator,
t: *const terminal.Terminal,
p: point.ScreenPoint,
t: *terminal.Terminal,
p: point.Point,
delete_unused: bool,
filter_ctx: anytype,
comptime filter: ?fn (@TypeOf(filter_ctx), Placement) bool,
) void {
// Convert our target point to a pin for comparison.
const target_pin = t.screen.pages.pin(p) orelse return;

var it = self.placements.iterator();
while (it.next()) |entry| {
const img = self.imageById(entry.key_ptr.image_id) orelse continue;
const rect = entry.value_ptr.rect(img, t);
if (rect.contains(p)) {
if (target_pin.isBetween(rect.top_left, rect.bottom_right)) {
if (filter) |f| if (!f(filter_ctx, entry.value_ptr.*)) continue;
entry.value_ptr.deinit(t);
self.placements.removeByPtr(entry.key_ptr);
if (delete_unused) self.deleteIfUnused(alloc, img.id);
}
@@ -547,13 +556,13 @@ pub const ImageStorage = struct {
) Rect {
// If we have columns/rows specified we can simplify this whole thing.
if (self.columns > 0 and self.rows > 0) {
return .{
.top_left = self.point,
.bottom_right = .{
.x = @min(self.point.x + self.columns, t.cols - 1),
.y = self.point.y + self.rows,
},
var br = switch (self.pin.downOverflow(self.rows)) {
.offset => |v| v,
.overflow => |v| v.end,
};
br.x = @min(self.pin.x + self.columns, t.cols - 1);

return .{ .top_left = self.pin.*, .bottom_right = br };
}

// Calculate our cell size.
@@ -574,12 +583,16 @@ pub const ImageStorage = struct {
const width_cells: u32 = @intFromFloat(@ceil(width_f64 / cell_width_f64));
const height_cells: u32 = @intFromFloat(@ceil(height_f64 / cell_height_f64));

// TODO(paged-terminal): clean this logic up above
var br = switch (self.pin.downOverflow(height_cells)) {
.offset => |v| v,
.overflow => |v| v.end,
};
br.x = @min(self.pin.x + width_cells, t.cols - 1);

return .{
.top_left = self.point,
.bottom_right = .{
.x = @min(self.point.x + width_cells, t.cols - 1),
.y = self.point.y + height_cells,
},
.top_left = self.pin.*,
.bottom_right = br,
};
}
};
@@ -769,37 +782,38 @@ test "storage: delete placement by specific id" {
try testing.expectEqual(tracked + 2, t.screen.pages.countTrackedPins());
}

// test "storage: delete intersecting cursor" {
// const testing = std.testing;
// const alloc = testing.allocator;
// var t = try terminal.Terminal.init(alloc, 100, 100);
// defer t.deinit(alloc);
// t.width_px = 100;
// t.height_px = 100;
//
// var s: ImageStorage = .{};
// defer s.deinit(alloc);
// try s.addImage(alloc, .{ .id = 1, .width = 50, .height = 50 });
// try s.addImage(alloc, .{ .id = 2, .width = 25, .height = 25 });
// try s.addPlacement(alloc, 1, 1, .{ .point = .{ .x = 0, .y = 0 } });
// try s.addPlacement(alloc, 1, 2, .{ .point = .{ .x = 25, .y = 25 } });
//
// t.screen.cursor.x = 12;
// t.screen.cursor.y = 12;
//
// s.dirty = false;
// s.delete(alloc, &t, .{ .intersect_cursor = false });
// try testing.expect(s.dirty);
// try testing.expectEqual(@as(usize, 1), s.placements.count());
// try testing.expectEqual(@as(usize, 2), s.images.count());
//
// // verify the placement is what we expect
// try testing.expect(s.placements.get(.{
// .image_id = 1,
// .placement_id = .{ .tag = .external, .id = 2 },
// }) != null);
// }
//
test "storage: delete intersecting cursor" {
const testing = std.testing;
const alloc = testing.allocator;
var t = try terminal.Terminal.init(alloc, 100, 100);
defer t.deinit(alloc);
t.width_px = 100;
t.height_px = 100;
const tracked = t.screen.pages.countTrackedPins();

var s: ImageStorage = .{};
defer s.deinit(alloc, &t);
try s.addImage(alloc, .{ .id = 1, .width = 50, .height = 50 });
try s.addImage(alloc, .{ .id = 2, .width = 25, .height = 25 });
try s.addPlacement(alloc, 1, 1, .{ .pin = try trackPin(&t, .{ .x = 0, .y = 0 }) });
try s.addPlacement(alloc, 1, 2, .{ .pin = try trackPin(&t, .{ .x = 25, .y = 25 }) });

t.screen.cursorAbsolute(12, 12);

s.dirty = false;
s.delete(alloc, &t, .{ .intersect_cursor = false });
try testing.expect(s.dirty);
try testing.expectEqual(@as(usize, 1), s.placements.count());
try testing.expectEqual(@as(usize, 2), s.images.count());
try testing.expectEqual(tracked + 1, t.screen.pages.countTrackedPins());

// verify the placement is what we expect
try testing.expect(s.placements.get(.{
.image_id = 1,
.placement_id = .{ .tag = .external, .id = 2 },
}) != null);
}

// test "storage: delete intersecting cursor plus unused" {
// const testing = std.testing;
// const alloc = testing.allocator;