Skip to content

Commit 64e3b8d

Browse files
committed
Do not hardcode black as the text color when the cursor is over it, but instead
use caretTextColor. Also, made caretTextColor optional and default when not set to the foregroundColor. The reason for this choice is that there is no escape sequence defined for setting this attribute, but it can be set via the API that we expose, and some color themes support this.
1 parent 673ab10 commit 64e3b8d

File tree

5 files changed

+13
-11
lines changed

5 files changed

+13
-11
lines changed

Sources/SwiftTerm/Apple/CaretView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ extension CaretView {
4444
guard style == .steadyBlock || style == .blinkBlock else {
4545
return
4646
}
47+
let caretFG = caretTextColor ?? terminal.nativeForegroundColor
4748
context.setFillColor(TTColor.black.cgColor)
4849
for run in CTLineGetGlyphRuns(ctline) as? [CTRun] ?? [] {
4950
let runGlyphsCount = CTRunGetGlyphCount(run)

Sources/SwiftTerm/Mac/MacCaretView.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class CaretView: NSView, CALayerDelegate {
3838
func setText (ch: CharData) {
3939
let res = NSAttributedString (
4040
string: String (ch.getCharacter()),
41-
attributes: terminal?.getAttributedValue(ch.attribute, usingFg: caretColor, andBg: caretTextColor))
41+
attributes: terminal?.getAttributedValue(ch.attribute, usingFg: caretColor, andBg: caretTextColor ?? terminal?.nativeForegroundColor ?? NSColor.black))
4242
ctline = CTLineCreateWithAttributedString(res)
4343

4444
setNeedsDisplay(bounds)
@@ -88,8 +88,8 @@ class CaretView: NSView, CALayerDelegate {
8888
}
8989
}
9090

91-
public var defaultCaretTextColor = NSColor.black
92-
public var caretTextColor: NSColor = NSColor.black {
91+
public var defaultCaretTextColor: NSColor? = nil
92+
public var caretTextColor: NSColor? = nil {
9393
didSet {
9494
updateView()
9595
}

Sources/SwiftTerm/Mac/MacTerminalView.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,9 @@ open class TerminalView: NSView, NSTextInputClient, NSUserInterfaceValidations,
235235
set { caretView.caretColor = newValue }
236236
}
237237

238-
/// Controls the color for the text in the caret when using a block cursor
239-
public var caretTextColor: NSColor {
238+
/// Controls the color for the text in the caret when using a block cursor, if not set
239+
/// the cursor will render with the foreground color
240+
public var caretTextColor: NSColor? {
240241
get { caretView.caretTextColor }
241242
set { caretView.caretTextColor = newValue }
242243
}

Sources/SwiftTerm/iOS/iOSCaretView.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class CaretView: UIView {
7979
func setText (ch: CharData) {
8080
let res = NSAttributedString (
8181
string: String (ch.getCharacter()),
82-
attributes: terminal?.getAttributedValue(ch.attribute, usingFg: caretColor, andBg: caretTextColor))
82+
attributes: terminal?.getAttributedValue(ch.attribute, usingFg: caretColor, andBg: caretTextColor ?? terminal?.nativeForegroundColor ?? TTColor.black))
8383
ctline = CTLineCreateWithAttributedString(res)
8484
setNeedsDisplay(bounds)
8585
}
@@ -107,8 +107,8 @@ class CaretView: UIView {
107107
}
108108
}
109109

110-
public var defaultCaretTextColor = UIColor.black
111-
public var caretTextColor: UIColor = UIColor.black {
110+
public var defaultCaretTextColor: UIColor? = nil
111+
public var caretTextColor: UIColor? = nil {
112112
didSet {
113113
updateView()
114114
}

Sources/SwiftTerm/iOS/iOSTerminalView.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -817,13 +817,13 @@ open class TerminalView: UIScrollView, UITextInputTraits, UIKeyInput, UIScrollVi
817817
set { caretView.caretColor = newValue }
818818
}
819819

820-
/// Controls the color for the caret
821-
public var caretTextColor: UIColor {
820+
/// Controls the color for the text in the caret when using a block cursor, if not set
821+
/// the cursor will render with the foreground color
822+
public var caretTextColor: UIColor? {
822823
get { caretView.caretTextColor }
823824
set { caretView.caretTextColor = newValue }
824825
}
825826

826-
827827
var _selectedTextBackgroundColor = UIColor (red: 204.0/255.0, green: 221.0/255.0, blue: 237.0/255.0, alpha: 1.0)
828828
/// The color used to render the selection
829829
public var selectedTextBackgroundColor: UIColor {

0 commit comments

Comments
 (0)