#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 }