Bladeren bron

Report back colors on OSC sequences

Miguel de Icaza 3 jaren geleden
bovenliggende
commit
c55336cb1b
2 gewijzigde bestanden met toevoegingen van 45 en 3 verwijderingen
  1. 25 2
      Sources/SwiftTerm/Terminal.swift
  2. 20 1
      Tests/SwiftTermTests/SwiftTermTests.swift

+ 25 - 2
Sources/SwiftTerm/Terminal.swift

@@ -826,7 +826,7 @@ open class Terminal {
         //  11 - Change VT100 text background color to Pt.
         //  11 - Change VT100 text background color to Pt.
         parser.oscHandlers [11] = { [unowned self] data in oscSetTextBackground (data) }
         parser.oscHandlers [11] = { [unowned self] data in oscSetTextBackground (data) }
         //  12 - Change text cursor color to Pt.
         //  12 - Change text cursor color to Pt.
-        parser.oscHandlers [11] = { [unowned self] data in oscSetCursorColor (data) }
+        parser.oscHandlers [12] = { [unowned self] data in oscSetCursorColor (data) }
         
         
         //  13 - Change mouse foreground color to Pt.
         //  13 - Change mouse foreground color to Pt.
         //  14 - Change mouse background color to Pt.
         //  14 - Change mouse background color to Pt.
@@ -1588,6 +1588,10 @@ open class Terminal {
         //log ("Attempt to set the text Foreground color \(str)")
         //log ("Attempt to set the text Foreground color \(str)")
     }
     }
     
     
+    func reportColor (oscCode: Int, color: Color) {
+        sendResponse(cc.OSC, "\(oscCode);\(color.formatAsXcolor ())", cc.ST)
+    }
+    
     // This handles both setting the foreground, but spill into background and cursor color
     // This handles both setting the foreground, but spill into background and cursor color
     // if more parameters are provided (ie, sending OSC 10 with #ffffff,#000000,#ff0000
     // if more parameters are provided (ie, sending OSC 10 with #ffffff,#000000,#ff0000
     // sets the foreground to #ffffff, background to #000000 and cursor to ff0000
     // sets the foreground to #ffffff, background to #000000 and cursor to ff0000
@@ -1597,8 +1601,22 @@ open class Terminal {
         var next = 0
         var next = 0
         while next < groups.count {
         while next < groups.count {
             defer { next += 1 }
             defer { next += 1 }
+            let text = groups [next]
+            
+            if text.first == UInt8 (ascii: "?") {
+                switch next {
+                case 0:
+                    reportColor (oscCode: 10, color: foregroundColor)
+                case 1:
+                    reportColor (oscCode: 11, color: backgroundColor)
+                default:
+                    break
+                }
+                
+                continue
+            }
 
 
-            guard let color = Color.parseColor(groups [next]) else {
+            guard let color = Color.parseColor(text) else {
                 continue
                 continue
             }
             }
             switch next {
             switch next {
@@ -1620,6 +1638,11 @@ open class Terminal {
 
 
     func oscSetTextBackground (_ data: ArraySlice<UInt8>)
     func oscSetTextBackground (_ data: ArraySlice<UInt8>)
     {
     {
+        if data.first == UInt8 (ascii: "?") {
+            reportColor (oscCode: 11, color: backgroundColor)
+            return
+        }
+
         if let background = Color.parseColor(data) {
         if let background = Color.parseColor(data) {
             backgroundColor = background
             backgroundColor = background
             tdel?.setBackgroundColor(source: self, color: background)
             tdel?.setBackgroundColor(source: self, color: background)

+ 20 - 1
Tests/SwiftTermTests/SwiftTermTests.swift

@@ -257,6 +257,23 @@ final class SwiftTermTests: XCTestCase {
                 // ChangeColor_CIEuvY
                 // ChangeColor_CIEuvY
                 // ChangeColor_CIExyY
                 // ChangeColor_CIExyY
                 // ChangeColor_TekHVC
                 // ChangeColor_TekHVC
+            
+            "ChangeDynamicColor_Multiple",
+            "ChangeDynamicColor_RGB$",
+            "ChangeDynamicColor_Hash3",
+            "ChangeDynamicColor_Hash6",
+            "ChangeDynamicColor_Hash9",
+            
+            // Failing:
+                // ChangeDynamicColor_CIELab
+                // ChangeDynamicColor_CIELuv
+                // ChangeDynamicColor_CIEXYZ
+                // ChangeDynamicColor_CIEuvY
+                // ChangeDynamicColor_CIExyY
+                // ChangeDynamicColor_Hash12
+                // ChangeDynamicColor_RGBI
+                // ChangeDynamicColor_TekHVC
+
         ]
         ]
         
         
         let expr = "test_(\(good.joined(separator: "|")))"
         let expr = "test_(\(good.joined(separator: "|")))"
@@ -264,10 +281,12 @@ final class SwiftTermTests: XCTestCase {
         XCTAssertNil(runTester (expr))
         XCTAssertNil(runTester (expr))
     }
     }
     
     
+    // Use this test to run a single test
     func testSingle ()
     func testSingle ()
     {
     {
-        //XCTAssertNil(runTester ("test_DL_ClearOutLeftRightAndTopBottomScrollRegion"))
+        XCTAssertNil(runTester ("test_ChangeColor_Hash3"))
     }
     }
+    
     func xtestFailuresOnHeadless ()
     func xtestFailuresOnHeadless ()
     {
     {
         XCTAssertNil(runTester ("test_DECCRA"))
         XCTAssertNil(runTester ("test_DECCRA"))