mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-17 21:12:39 +00:00
29 lines
805 B
Swift
29 lines
805 B
Swift
#if canImport(AppKit)
|
|
import AppKit
|
|
#elseif canImport(UIKit)
|
|
import UIKit
|
|
#endif
|
|
|
|
extension Ghostty.SurfaceView {
|
|
#if canImport(AppKit)
|
|
/// A snapshot image of the current surface view.
|
|
var asImage: NSImage? {
|
|
guard let bitmapRep = bitmapImageRepForCachingDisplay(in: bounds) else {
|
|
return nil
|
|
}
|
|
cacheDisplay(in: bounds, to: bitmapRep)
|
|
let image = NSImage(size: bounds.size)
|
|
image.addRepresentation(bitmapRep)
|
|
return image
|
|
}
|
|
#elseif canImport(UIKit)
|
|
/// A snapshot image of the current surface view.
|
|
var asImage: UIImage? {
|
|
let renderer = UIGraphicsImageRenderer(bounds: bounds)
|
|
return renderer.image { _ in
|
|
drawHierarchy(in: bounds, afterScreenUpdates: true)
|
|
}
|
|
}
|
|
#endif
|
|
}
|