Эх сурвалжийг харах

Render images after the text, fixes sixel rendering inside SwiftTermApp that changes defaults colors, and also simplifies the TerminalImage protocol

Miguel de Icaza 4 жил өмнө
parent
commit
b7e6c6a216

+ 18 - 31
Sources/SwiftTerm/Apple/AppleTerminalView.swift

@@ -507,24 +507,6 @@ extension TerminalView {
 
 
         // draw lines
         // draw lines
         for row in terminal.buffer.yDisp..<terminal.rows + terminal.buffer.yDisp {
         for row in terminal.buffer.yDisp..<terminal.rows + terminal.buffer.yDisp {
-            // Render any sixel content first
-            if let images = attrStrBuffer [row].images {
-                let rowBase = frame.height - (CGFloat(row - terminal.buffer.yDisp) * cellDimension.height)
-                for basicImage in images {
-                    guard let image = basicImage as? AppleImage else {
-                        continue
-                    }
-                    let col = image.col
-                    let rect = CGRect(x: CGFloat (col)*cellDimension.width,
-                                      y: rowBase - CGFloat (image.pixelHeight),
-                                      width: CGFloat (image.pixelWidth),
-                                      height: CGFloat (image.pixelHeight))
-                    
-                    print ("row: \(row) Drawing image at \(rect)")
-                    context.draw (image.image, in: rect)
-                }
-            }
-            
             let lineOffset = cellDimension.height * (CGFloat(row - terminal.buffer.yDisp + 1))
             let lineOffset = cellDimension.height * (CGFloat(row - terminal.buffer.yDisp + 1))
             let lineOrigin = CGPoint(x: 0, y: frame.height - lineOffset)
             let lineOrigin = CGPoint(x: 0, y: frame.height - lineOffset)
             let ctline = CTLineCreateWithAttributedString(attrStrBuffer [row].attrStr)
             let ctline = CTLineCreateWithAttributedString(attrStrBuffer [row].attrStr)
@@ -603,13 +585,22 @@ extension TerminalView {
 
 
                 col += runGlyphsCount
                 col += runGlyphsCount
             }
             }
-
-
-
-//            // set caret position
-//            if terminal.buffer.y == row - terminal.buffer.yDisp {
-//                updateCursorPosition()
-//            }
+            // Render any sixel content last
+            if let images = attrStrBuffer [row].images {
+                let rowBase = frame.height - (CGFloat(row - terminal.buffer.yDisp) * cellDimension.height)
+                for basicImage in images {
+                    guard let image = basicImage as? AppleImage else {
+                        continue
+                    }
+                    let col = image.col
+                    let rect = CGRect(x: CGFloat (col)*cellDimension.width,
+                                      y: rowBase - CGFloat (image.pixelHeight),
+                                      width: CGFloat (image.pixelWidth),
+                                      height: CGFloat (image.pixelHeight))
+                    
+                    context.draw (image.image, in: rect)
+                }
+            }
         }
         }
     }
     }
     
     
@@ -977,16 +968,12 @@ extension TerminalView {
         var image: CGImage
         var image: CGImage
         var pixelWidth: Int
         var pixelWidth: Int
         var pixelHeight: Int
         var pixelHeight: Int
-        var cols: Int
-        var rows: Int
         var col: Int
         var col: Int
         
         
-        init (image: CGImage, width: Int, height: Int, cols: Int, rows: Int, onCol: Int) {
+        init (image: CGImage, width: Int, height: Int, onCol: Int) {
             self.image = image
             self.image = image
             self.pixelWidth = width
             self.pixelWidth = width
             self.pixelHeight = height
             self.pixelHeight = height
-            self.cols = cols
-            self.rows = rows
             self.col = onCol
             self.col = onCol
         }
         }
     }
     }
@@ -1039,7 +1026,7 @@ extension TerminalView {
                 return nil
                 return nil
             }
             }
             rowStart += rowSize
             rowStart += rowSize
-            let image = AppleImage (image: cgimage, width: Int (size.width), height: Int (cellDimension.height), cols: usedCols, rows: 1, onCol: terminal.buffer.x)
+            let image = AppleImage (image: cgimage, width: Int (size.width), height: Int (cellDimension.height), onCol: terminal.buffer.x)
             buffer.lines [buffer.y+buffer.yBase].attach(image: image)
             buffer.lines [buffer.y+buffer.yBase].attach(image: image)
             terminal.updateRange (buffer.y)
             terminal.updateRange (buffer.y)
             terminal.cmdLineFeed()
             terminal.cmdLineFeed()

+ 0 - 5
Sources/SwiftTerm/Terminal.swift

@@ -215,11 +215,6 @@ public protocol TerminalImage {
     /// The height of the image in pixels
     /// The height of the image in pixels
     var pixelHeight: Int { get }
     var pixelHeight: Int { get }
     
     
-    /// The number of columns used by the image, will be set on demand
-    var cols: Int { get set }
-    /// The number of rows used by the image, will be set on demand
-    var rows: Int { get set }
-    
     /// Column where the image was attached
     /// Column where the image was attached
     var col: Int { get set }
     var col: Int { get set }
 }
 }