Skip to content

Commit

Permalink
This change only queues the exposed region to be repainted on UIKit.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
migueldeicaza committed Apr 18, 2023
1 parent eefa5d1 commit 3c8310c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
22 changes: 12 additions & 10 deletions Sources/SwiftTerm/Apple/AppleTerminalView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ extension TerminalView {

search = SearchService (terminal: terminal)

#if os(macOS)
#if os(macOS)
needsDisplay = true
#else
#else
setNeedsDisplay(frame)
#endif
#endif
}

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

terminal.clearUpdateRange ()

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

pendingDisplay = false
updateDebugDisplay ()
Expand Down
22 changes: 20 additions & 2 deletions Sources/SwiftTerm/iOS/iOSTerminalView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -961,18 +961,36 @@ open class TerminalView: UIScrollView, UITextInputTraits, UIKeyInput, UIScrollVi
guard let context = getCurrentGraphicsContext() else {
return
}


//print (dirtyRect)
// Without these two lines, on font changes, some junk is being displayed
// Once we test the font change, we could disable these two lines, and
// enable the #if false in drawterminalContents that should be coping with this now
nativeBackgroundColor.set ()
context.fill ([dirtyRect])
//print (nativeBackgroundColor)
//UIColor.black.set()
context.clear (dirtyRect)
//context.fill ([dirtyRect])

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

drawTerminalContents (dirtyRect: dirtyRect, context: context, bufferOffset: 0)
// context.restoreGState()
//
// switch Int.random(in: 0..<3) {
// case 0:
// context.setFillColor(red: 1.0, green: 0, blue: 0, alpha: 0.3)
// case 1:
// context.setFillColor(red: 0, green: 1.0, blue: 0, alpha: 0.3)
// case 2:
// context.setFillColor(red: 0, green: 0, blue: 1.0, alpha: 0.3)
// default:
// context.setFillColor(red: 0.4, green: 0, blue: 1.0, alpha: 0.3)
// }
// context.fill ([dirtyRect])
}

open override var bounds: CGRect {
Expand Down
1 change: 1 addition & 0 deletions TerminalApp/MacTerminal/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class ViewController: NSViewController, LocalProcessTerminalViewDelegate, NSUser
terminal = LocalProcessTerminalView(frame: view.frame)
zoomGesture = NSMagnificationGestureRecognizer(target: self, action: #selector(zoomGestureHandler))
terminal.addGestureRecognizer(zoomGesture!)
terminal.getTerminal().backgroundColor = SwiftTerm.Color(red: 0, green: 0x8000, blue: 0)
ViewController.lastTerminal = terminal
terminal.processDelegate = self
terminal.feed(text: "Welcome to SwiftTerm")
Expand Down
1 change: 1 addition & 0 deletions TerminalApp/iOSTerminal/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class ViewController: UIViewController {
}

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

0 comments on commit 3c8310c

Please sign in to comment.