Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
crabtree-michael committed Mar 16, 2024
2 parents 8691a7b + 93b9289 commit ff44b73
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
26 changes: 20 additions & 6 deletions Sources/SwiftTerm/Apple/AppleTerminalView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ extension TerminalView {
search.invalidate ()

terminalDelegate?.sizeChanged (source: self, newCols: newCols, newRows: newRows)

updateScroller()
return true
}
return false
Expand All @@ -152,7 +154,7 @@ extension TerminalView {
return CellDimension(width: max (1, cellWidth), height: max (min (cellHeight, 8192), 1))
}

func mapColor (color: Attribute.Color, isFg: Bool, isBold: Bool) -> TTColor
func mapColor (color: Attribute.Color, isFg: Bool, isBold: Bool, useBrightColors: Bool = true) -> TTColor
{
switch color {
case .defaultColor:
Expand All @@ -168,8 +170,14 @@ extension TerminalView {
return nativeBackgroundColor.inverseColor()
}
case .ansi256(let ansi):
// Ansi 8 to 16 are high-intensity colors, they are already treated as bold
let midx = ansi < 7 ? (Int (ansi) + (isBold ? 8 : 0)) : Int (ansi)
var midx: Int
// if high - bright colors are enabled we will represent bold text by using more intense colors
// otherwise we will reduce colors but use bold fonts
if useBrightColors {
midx = ansi < 7 ? (Int (ansi) + (isBold ? 8 : 0)) : Int (ansi)
} else {
midx = ansi > 7 ? (Int (ansi) - 8) : Int(ansi)
}
if let c = colors [midx] {
return c
}
Expand Down Expand Up @@ -323,9 +331,15 @@ extension TerminalView {
return result
}

var useBoldForBrightColor: Bool = false
// if high - bright colors are disabled in settings we will use bold font instead
if case .ansi256(let code) = fg, code > 7, !useBrightColors {
useBoldForBrightColor = true
}
var tf: TTFont
let isBold = flags.contains(.bold)
if isBold {

if isBold || useBoldForBrightColor {
if flags.contains (.italic) {
tf = fontSet.boldItalic
} else {
Expand All @@ -337,7 +351,7 @@ extension TerminalView {
tf = fontSet.normal
}

let fgColor = mapColor (color: fg, isFg: true, isBold: isBold)
let fgColor = mapColor (color: fg, isFg: true, isBold: isBold, useBrightColors: useBrightColors)
var nsattr: [NSAttributedString.Key:Any] = [
.font: tf,
.foregroundColor: fgColor,
Expand All @@ -351,6 +365,7 @@ extension TerminalView {
nsattr [.strikethroughColor] = fgColor
nsattr [.strikethroughStyle] = NSUnderlineStyle.single.rawValue
}

if withUrl {
nsattr [.underlineStyle] = NSUnderlineStyle.single.rawValue | NSUnderlineStyle.patternDash.rawValue
nsattr [.underlineColor] = fgColor
Expand Down Expand Up @@ -545,7 +560,6 @@ extension TerminalView {
func calcLineOffset (forRow: Int) -> CGFloat {
cellDimension.height * CGFloat (forRow-bufferOffset+1)
}

// draw lines
#if os(iOS) || os(visionOS)
// On iOS, we are drawing the exposed region
Expand Down
3 changes: 3 additions & 0 deletions Sources/SwiftTerm/Mac/MacTerminalView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ open class TerminalView: NSView, NSTextInputClient, NSUserInterfaceValidations,
}
}

/// Controls weather to use high ansi colors, if false terminal will use bold text instead of high ansi colors
public var useBrightColors: Bool = true

/// Controls the color for the caret
public var caretColor: NSColor {
get { caretView.caretColor }
Expand Down
10 changes: 10 additions & 0 deletions Sources/SwiftTerm/iOS/iOSTerminalView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,13 @@ open class TerminalView: UIScrollView, UITextInputTraits, UIKeyInput, UIScrollVi
return Int(topVisibleLine)...Int(bottomVisibleLine)
}

public func repositionVisibleFrame () {
let topVisibleLine = contentOffset.y/cellDimension.height
let bottomVisibleLine = (topVisibleLine+frame.height/cellDimension.height)-1
let lines = self.terminal.buffer.lines.count
contentOffset.y = max(0, CGFloat(lines) - bottomVisibleLine) * cellDimension.height
}

@objc func singleTap (_ gestureRecognizer: UITapGestureRecognizer)
{
if isFirstResponder {
Expand Down Expand Up @@ -844,6 +851,9 @@ open class TerminalView: UIScrollView, UITextInputTraits, UIKeyInput, UIScrollVi
get { caretView?.caretTextColor }
set { caretView?.caretTextColor = newValue }
}

/// Controls weather to use high ansi colors, if false terminal will use bold text instead of high ansi colors
public var useBrightColors: Bool = true

var _selectedTextBackgroundColor = UIColor (red: 204.0/255.0, green: 221.0/255.0, blue: 237.0/255.0, alpha: 1.0)
/// The color used to render the selection
Expand Down

0 comments on commit ff44b73

Please sign in to comment.