Skip to content

Commit 4fe5b21

Browse files
committed
Implement Kitty graphics protocol, except animation.
1 parent dc82361 commit 4fe5b21

72 files changed

Lines changed: 4614 additions & 379 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎iTerm2.xcodeproj/project.pbxproj‎

Lines changed: 245 additions & 187 deletions
Large diffs are not rendered by default.

‎iTerm2SandboxedWorker/iTermImage+ImageWithData.m‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ - (instancetype)initWithData:(NSData *)data {
6262
NSImage *image = [[NSImage alloc] initWithData:data];
6363
NSImageRep *rep = [[image representations] firstObject];
6464
NSSize imageSize = NSMakeSize(rep.pixelsWide, rep.pixelsHigh);
65-
65+
self.scaledSize = image.size;
66+
6667
if (imageSize.width == 0 && imageSize.height == 0) {
6768
// PDFs can hit this case.
6869
if (image.size.width != 0 && image.size.height != 0) {

‎iTerm2SandboxedWorker/iTermImage+Sixel.m‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ - (instancetype)initWithSixelData:(NSData *)data {
124124
}
125125
[self.images addObject:image];
126126
self.size = image.size;
127+
self.scaledSize = image.size;
127128
}
128129
return self;
129130
}

‎sources/CommandInfoViewController.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ class DraggableImageView: NSImageView {
503503
case .pending(let draggingStart):
504504
let windowPoint = event.locationInWindow
505505
let point = convert(windowPoint, from: nil)
506-
let distance = draggingStart.distance(point)
506+
let distance = draggingStart.distance(to: point)
507507
return distance > 2
508508
}
509509
}

‎sources/ComplexCharRegistry.swift‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ class ComplexCharRegistry: NSObject {
8282
isSpacingCombiningMark: isSpacingCombiningMark) }
8383
}
8484

85+
@objc
86+
func charToKittyPlaceholder(_ char: screen_char_t) -> NSString? {
87+
if char.image == 0 || char.virtualPlaceholder == 0 {
88+
return ""
89+
}
90+
return string(for: char.code, isComplex: char.complexChar != 0)
91+
}
92+
8593
@objc
8694
func charToString(_ char: screen_char_t) -> NSString? {
8795
if char.image != 0 {

‎sources/CompressibleCharacterBuffer.swift‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ extension screen_char_t: DefaultInitializable {
137137
invisible: 0,
138138
inverse: 0,
139139
guarded: 0,
140+
virtualPlaceholder: 0,
140141
unused: 0)
141142
}
142143
}

‎sources/ContentNavigationShortcut.swift‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -365,14 +365,3 @@ class ContentNavigationShortcutLayerOuter: NSObject {
365365
}
366366
}
367367

368-
extension NSRect {
369-
var center: NSPoint {
370-
return NSPoint(x: midX, y: midY)
371-
}
372-
}
373-
374-
extension NSPoint {
375-
func distance(_ point: NSPoint) -> CGFloat {
376-
return sqrt(pow(point.x - x, 2) + pow(point.y - y, 2))
377-
}
378-
}

‎sources/DoublyLinkedList.swift‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//
2+
// DoublyLinkedList.swift
3+
// iTerm2SharedARC
4+
//
5+
// Created by George Nachman on 8/27/24.
6+
//
7+
8+
import Foundation
9+
10+
class DLLNode<T> {
11+
var value: T
12+
fileprivate var prev: DLLNode?
13+
fileprivate var next: DLLNode?
14+
15+
init(value: T) {
16+
self.value = value
17+
}
18+
}
19+
20+
class DoublyLinkedList<T> {
21+
private var head: DLLNode<T>?
22+
private var tail: DLLNode<T>?
23+
24+
var first: DLLNode<T>? { head }
25+
26+
func append(_ value: T) -> DLLNode<T> {
27+
let newNode = DLLNode(value: value)
28+
if let tailNode = tail {
29+
newNode.prev = tailNode
30+
tailNode.next = newNode
31+
} else {
32+
head = newNode
33+
}
34+
tail = newNode
35+
return newNode
36+
}
37+
38+
func remove(_ node: DLLNode<T>) {
39+
let prevNode = node.prev
40+
let nextNode = node.next
41+
42+
if let prevNode = prevNode {
43+
prevNode.next = nextNode
44+
} else {
45+
head = nextNode
46+
}
47+
48+
if let nextNode = nextNode {
49+
nextNode.prev = prevNode
50+
} else {
51+
tail = prevNode
52+
}
53+
54+
node.prev = nil
55+
node.next = nil
56+
}
57+
}

‎sources/HueVisualizationView.swift‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,3 @@ class HueVisualizationView: NSView {
322322
}
323323
}
324324

325-
extension NSPoint {
326-
func distance(to other: NSPoint) -> CGFloat {
327-
return sqrt(pow(x - other.x, 2) + pow(y - other.y, 2))
328-
}
329-
}

‎sources/Int+iTerm.swift‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//
2+
// Int+iTerm.swift
3+
// iTerm2SharedARC
4+
//
5+
// Created by George Nachman on 8/27/24.
6+
//
7+
8+
import Foundation
9+
10+
extension Int {
11+
init(clamping value: CGFloat) {
12+
if value > CGFloat(Int.max) {
13+
self = Int.max
14+
} else if value < CGFloat(Int.min) {
15+
self = Int.min
16+
} else {
17+
self = Int(value)
18+
}
19+
}
20+
}
21+
22+
extension Int32 {
23+
init(clamping value: CGFloat) {
24+
if value > CGFloat(Int.max) {
25+
self = Int32.max
26+
} else if value < CGFloat(Int.min) {
27+
self = Int32.min
28+
} else {
29+
self = Int32(value)
30+
}
31+
}
32+
}
33+
34+
extension Int64 {
35+
init(clamping value: CGFloat) {
36+
if value > CGFloat(Int.max) {
37+
self = Int64.max
38+
} else if value < CGFloat(Int.min) {
39+
self = Int64.min
40+
} else {
41+
self = Int64(value)
42+
}
43+
}
44+
}
45+
46+
extension Int: CustomDebugStringConvertible {
47+
public var debugDescription: String {
48+
return String(self)
49+
}
50+
}
51+

0 commit comments

Comments
 (0)