Skip to content

Commit 3c8310c

Browse files
committed
This change only queues the exposed region to be repainted on UIKit.
This works, but it exposes a problem: scrolling of text (ls -l on a large directory) will redraw the text on top of the old text - this is caused by the clear background that I allow using. So I need to account for that. This sadly also brings back the ugly bar at the bottom, because the UIScrollView allows for over-scroll, and I do not seem to have a way of painting there. The solutions on StackOverflow include "Append a view underneat with the color that you want" which is some ugly stuff. Will investigate later.
1 parent eefa5d1 commit 3c8310c

File tree

4 files changed

+34
-12
lines changed

4 files changed

+34
-12
lines changed

Sources/SwiftTerm/Apple/AppleTerminalView.swift

+12-10
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ extension TerminalView {
100100

101101
search = SearchService (terminal: terminal)
102102

103-
#if os(macOS)
103+
#if os(macOS)
104104
needsDisplay = true
105-
#else
105+
#else
106106
setNeedsDisplay(frame)
107-
#endif
107+
#endif
108108
}
109109

110110
/// Returns the underlying terminal emulator that the `TerminalView` is a view for
@@ -730,7 +730,7 @@ extension TerminalView {
730730
nativeBackgroundColor.setFill()
731731
context.fill ([box])
732732
}
733-
#elseif false
733+
#else
734734
// Currently the caller on iOS is clearing the entire dirty region due to the ordering of
735735
// font change sizes, but once we fix that, we should remove the clearing of the dirty
736736
// region in the calling code, and enable this code instead.
@@ -811,7 +811,7 @@ extension TerminalView {
811811

812812
terminal.clearUpdateRange ()
813813

814-
#if os(macOS)
814+
#if os(macOS)
815815
let baseLine = frame.height
816816
var region = CGRect (x: 0,
817817
y: baseLine - (cellDimension.height + CGFloat(rowEnd) * cellDimension.height),
@@ -826,11 +826,13 @@ extension TerminalView {
826826
region = CGRect (x: 0, y: 0, width: frame.width, height: oh + oy)
827827
}
828828
setNeedsDisplay(region)
829-
#else
830-
// TODO iOS: need to update the code above, but will do that when I get some real
831-
// life data being fed into it.
832-
setNeedsDisplay(bounds)
833-
#endif
829+
#else
830+
let region = CGRect (x: 0,
831+
y: CGFloat (rowStart)*cellDimension.height+contentOffset.y,
832+
width: frame.width,
833+
height: CGFloat (rowEnd-rowStart+1) * cellDimension.height)
834+
setNeedsDisplay(region)
835+
#endif
834836

835837
pendingDisplay = false
836838
updateDebugDisplay ()

Sources/SwiftTerm/iOS/iOSTerminalView.swift

+20-2
Original file line numberDiff line numberDiff line change
@@ -961,18 +961,36 @@ open class TerminalView: UIScrollView, UITextInputTraits, UIKeyInput, UIScrollVi
961961
guard let context = getCurrentGraphicsContext() else {
962962
return
963963
}
964-
964+
965+
//print (dirtyRect)
965966
// Without these two lines, on font changes, some junk is being displayed
966967
// Once we test the font change, we could disable these two lines, and
967968
// enable the #if false in drawterminalContents that should be coping with this now
968969
nativeBackgroundColor.set ()
969-
context.fill ([dirtyRect])
970+
//print (nativeBackgroundColor)
971+
//UIColor.black.set()
972+
context.clear (dirtyRect)
973+
//context.fill ([dirtyRect])
970974

975+
//context.saveGState()
971976
// drawTerminalContents and CoreText expect the AppKit coordinate system
972977
context.scaleBy (x: 1, y: -1)
973978
context.translateBy(x: 0, y: -frame.height)
974979

975980
drawTerminalContents (dirtyRect: dirtyRect, context: context, bufferOffset: 0)
981+
// context.restoreGState()
982+
//
983+
// switch Int.random(in: 0..<3) {
984+
// case 0:
985+
// context.setFillColor(red: 1.0, green: 0, blue: 0, alpha: 0.3)
986+
// case 1:
987+
// context.setFillColor(red: 0, green: 1.0, blue: 0, alpha: 0.3)
988+
// case 2:
989+
// context.setFillColor(red: 0, green: 0, blue: 1.0, alpha: 0.3)
990+
// default:
991+
// context.setFillColor(red: 0.4, green: 0, blue: 1.0, alpha: 0.3)
992+
// }
993+
// context.fill ([dirtyRect])
976994
}
977995

978996
open override var bounds: CGRect {

TerminalApp/MacTerminal/ViewController.swift

+1
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ class ViewController: NSViewController, LocalProcessTerminalViewDelegate, NSUser
124124
terminal = LocalProcessTerminalView(frame: view.frame)
125125
zoomGesture = NSMagnificationGestureRecognizer(target: self, action: #selector(zoomGestureHandler))
126126
terminal.addGestureRecognizer(zoomGesture!)
127+
terminal.getTerminal().backgroundColor = SwiftTerm.Color(red: 0, green: 0x8000, blue: 0)
127128
ViewController.lastTerminal = terminal
128129
terminal.processDelegate = self
129130
terminal.feed(text: "Welcome to SwiftTerm")

TerminalApp/iOSTerminal/ViewController.swift

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class ViewController: UIViewController {
9292
}
9393

9494
view.addSubview(tv)
95+
tv.getTerminal().backgroundColor = SwiftTerm.Color.init(red: 0x8080, green: 0, blue: 0)
9596
setupKeyboardMonitor()
9697
tv.becomeFirstResponder()
9798
self.tv.feed(text: "Welcome to SwiftTerm - connecting to my localhost\r\n\n")

0 commit comments

Comments
 (0)