|
8 | 8 | import Foundation |
9 | 9 | import Testing |
10 | 10 |
|
| 11 | +#if os(macOS) |
| 12 | +import AppKit |
| 13 | +#endif |
| 14 | + |
11 | 15 | @testable import SwiftTerm |
12 | 16 |
|
13 | 17 | final class SelectionTests: TerminalDelegate { |
@@ -107,6 +111,30 @@ final class SelectionTests: TerminalDelegate { |
107 | 111 | #expect(view.terminal.cols == originalCols) |
108 | 112 | #expect(view.terminal.rows == originalRows) |
109 | 113 | } |
| 114 | + |
| 115 | + @Test func testSelectionColorsOverrideCellAndDecorationColors() { |
| 116 | + let view = TerminalView(frame: CGRect(origin: .zero, size: .init(width: 320, height: 160))) |
| 117 | + let selectionBackground = NSColor(srgbRed: 0, green: 166.0 / 255.0, blue: 178.0 / 255.0, alpha: 1.0) |
| 118 | + let selectionForeground = NSColor.black |
| 119 | + |
| 120 | + #expect(view.selectedTextBackgroundColor.isEqual(selectionBackground)) |
| 121 | + #expect(view.selectedTextForegroundColor.isEqual(selectionForeground)) |
| 122 | + |
| 123 | + view.terminal.feed(text: "\u{001B}[31;44;4;9mX") |
| 124 | + view.selection.setSelection(start: Position(col: 0, row: 0), end: Position(col: 1, row: 0)) |
| 125 | + |
| 126 | + let renderedLine = view.buildAttributedString( |
| 127 | + row: 0, |
| 128 | + line: view.terminal.displayBuffer.lines[0], |
| 129 | + cols: view.terminal.cols |
| 130 | + ) |
| 131 | + let attributes = renderedLine.segments[0].attributedString.attributes(at: 0, effectiveRange: nil) |
| 132 | + |
| 133 | + #expect((attributes[.selectionBackgroundColor] as? NSColor)?.isEqual(selectionBackground) == true) |
| 134 | + #expect((attributes[.foregroundColor] as? NSColor)?.isEqual(selectionForeground) == true) |
| 135 | + #expect((attributes[.underlineColor] as? NSColor)?.isEqual(selectionForeground) == true) |
| 136 | + #expect((attributes[.strikethroughColor] as? NSColor)?.isEqual(selectionForeground) == true) |
| 137 | + } |
110 | 138 | #endif |
111 | 139 |
|
112 | 140 | // MARK: - Selection Tests Ported from Ghostty |
|
0 commit comments