Skip to content

Commit 05a49d7

Browse files
Merge pull request #623 from hassekf/fix/reverse-video-swaps-instead-of-inverting
Draw reverse video by swapping the default colors, opaquely
2 parents db0a567 + 61ce40f commit 05a49d7

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

Sources/SwiftTerm/Apple/AppleTerminalView.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,10 +462,21 @@ extension TerminalView {
462462
return nativeBackgroundColor
463463
}
464464
case .defaultInvertedColor:
465+
// Reverse video *swaps* the default pair, it does not invert its RGB. Inverting
466+
// produced the expected pixels only for a pure black/white pair; with any other
467+
// palette it produced a color that belongs to neither side (inverting Solarized's
468+
// base03 background yields a pink block), and over a translucent background it
469+
// produced an unreadable highlight: the block inherited the background's alpha and
470+
// vanished, leaving text painted in the inverse of the foreground over whatever the
471+
// window showed through.
472+
//
473+
// The swapped colors are forced opaque, the way Terminal.app draws reverse video
474+
// over a translucent background: the highlight is the one thing that must stay
475+
// readable at any `backgroundOpacity`.
465476
if isFg {
466-
return nativeForegroundColor.inverseColor()
477+
return nativeBackgroundColor.withAlphaComponent(1)
467478
} else {
468-
return nativeBackgroundColor.inverseColor()
479+
return nativeForegroundColor.withAlphaComponent(1)
469480
}
470481
case .ansi256(let ansi):
471482
var midx: Int

0 commit comments

Comments
 (0)