Skip to content

Commit

Permalink
Merge pull request #324 from iOSappssolutions/main
Browse files Browse the repository at this point in the history
changes for visionos
  • Loading branch information
migueldeicaza authored Sep 10, 2023
2 parents 4df9211 + 6c7dac9 commit 495c7c1
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 18 deletions.
14 changes: 7 additions & 7 deletions Sources/SwiftTerm/Apple/AppleTerminalView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
//
// Created by Miguel de Icaza on 4/21/20.
//
#if os(macOS) || os(iOS)
#if os(macOS) || os(iOS) || os(visionOS)
import Foundation
import CoreGraphics
import CoreText

#if os(iOS)
#if os(iOS) || os(visionOS)
import UIKit
typealias TTColor = UIColor
typealias TTFont = UIFont
Expand Down Expand Up @@ -541,7 +541,7 @@ extension TerminalView {
}

// draw lines
#if os(iOS)
#if os(iOS) || os(visionOS)
// On iOS, we are drawing the exposed region
let cellHeight = cellDimension.height
let firstRow = Int (dirtyRect.minY/cellHeight)
Expand Down Expand Up @@ -745,7 +745,7 @@ extension TerminalView {
}
#endif

#if os(iOS)
#if os(iOS) || os(visionOS)
if selection.active {
let start, end: Position

Expand Down Expand Up @@ -859,7 +859,7 @@ extension TerminalView {
addSubview(caretView)
}
let doublePosition = buffer.lines [vy].renderMode == .single ? 1.0 : 2.0
#if os(iOS)
#if os(iOS) || os(visionOS)
let offset = (cellDimension.height * (CGFloat(buffer.y+(buffer.yBase))))
let lineOrigin = CGPoint(x: 0, y: offset)
#else
Expand Down Expand Up @@ -1228,7 +1228,7 @@ extension TerminalView {
let rows = Int (ceil (height/cellDimension.height))

let stripeSize = CGSize (width: width, height: cellDimension.height)
#if os(iOS)
#if os(iOS) || os(visionOS)
var srcY: CGFloat = 0
#else
var srcY: CGFloat = img.size.height
Expand All @@ -1242,7 +1242,7 @@ extension TerminalView {
guard let stripe = drawImageInStripe (image: img, srcY: srcY, width: width, srcHeight: cellDimension.height * heightRatio, dstHeight: cellDimension.height, size: stripeSize) else {
continue
}
#if os(iOS)
#if os(iOS) || os(visionOS)
srcY += cellDimension.height * heightRatio
#endif

Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftTerm/Apple/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// Created by Miguel de Icaza on 4/15/20.
//
#if os(macOS) || os(iOS)
#if os(macOS) || os(iOS) || os(visionOS)
import Foundation

extension NSAttributedString.Key {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftTerm/Apple/TerminalViewDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// Created by Miguel de Icaza on 4/15/20.
//
#if os(iOS) || os(macOS)
#if os(iOS) || os(visionOS) || os(macOS)
import Foundation

/// Delegate used by ``TerminalView`` to notify the user of events happening
Expand Down
17 changes: 14 additions & 3 deletions Sources/SwiftTerm/iOS/iOSAccessoryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//
// Created by Miguel de Icaza on 5/9/20.
//
#if os(iOS)
#if os(iOS) || os(visionOS)

import Foundation
import UIKit
Expand Down Expand Up @@ -53,12 +53,16 @@ public class TerminalAccessory: UIInputView, UIInputViewAudioFeedback {
fatalError("init(coder:) has not been implemented")
}

#if os(iOS)
// Override for UIInputViewAudioFeedback
public var enableInputClicksWhenVisible: Bool { true }

#endif

func clickAndSend (_ data: [UInt8])
{
#if os(iOS)
UIDevice.current.playInputClick()
#endif
terminalView?.send (data)
}

Expand Down Expand Up @@ -139,12 +143,19 @@ public class TerminalAccessory: UIInputView, UIInputViewAudioFeedback {
guard let tv = terminalView else { return }
let wasResponder = tv.isFirstResponder
if wasResponder { _ = tv.resignFirstResponder() }

if tv.inputView == nil {
#if os(visionOS)
tv.inputView = KeyboardView (frame: CGRect (origin: CGPoint.zero,
size: CGSize (width: 300,
height: 400)),
terminalView: terminalView)
#else
tv.inputView = KeyboardView (frame: CGRect (origin: CGPoint.zero,
size: CGSize (width: UIScreen.main.bounds.width,
height: max((UIScreen.main.bounds.height / 5),140))),
terminalView: terminalView)
#endif
} else {
tv.inputView = nil
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftTerm/iOS/iOSCaretView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Created by Miguel de Icaza on 3/20/20.
//

#if os(iOS)
#if os(iOS) || os(visionOS)
import Foundation
import UIKit
import CoreText
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftTerm/iOS/iOSDoubleButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// Created by Miguel de Icaza on 7/13/21.
//
#if os(iOS)
#if os(iOS) || os(visionOS)

import Foundation
import UIKit
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftTerm/iOS/iOSExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// Created by Miguel de Icaza on 6/29/21.
//
#if os(iOS)
#if os(iOS) || os(visionOS)
import Foundation
import UIKit

Expand Down
4 changes: 3 additions & 1 deletion Sources/SwiftTerm/iOS/iOSKeyboardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// Created by Miguel de Icaza on 7/15/21.
//
#if os(iOS)
#if os(iOS) || os(visionOS)
import Foundation
import UIKit

Expand All @@ -22,7 +22,9 @@ class KeyboardView: UIView {

func clickAndSend (_ data: [UInt8])
{
#if os(iOS)
UIDevice.current.playInputClick()
#endif
terminalView?.send (data)
}

Expand Down
8 changes: 7 additions & 1 deletion Sources/SwiftTerm/iOS/iOSTerminalView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// Created by Miguel de Icaza on 3/4/20.
//

#if os(iOS)
#if os(iOS) || os(visionOS)
import Foundation
import UIKit
import CoreText
Expand Down Expand Up @@ -964,7 +964,11 @@ open class TerminalView: UIScrollView, UITextInputTraits, UIKeyInput, UIScrollVi

func backingScaleFactor () -> CGFloat
{
#if os(visionOS)
1.0
#else
UIScreen.main.scale
#endif
}

override public func draw (_ dirtyRect: CGRect) {
Expand Down Expand Up @@ -1409,8 +1413,10 @@ open class TerminalView: UIScrollView, UITextInputTraits, UIKeyInput, UIScrollVi
extension TerminalViewDelegate {
public func bell (source: TerminalView)
{
#if os(iOS)
let generator = UINotificationFeedbackGenerator()
generator.notificationOccurred(.warning)
#endif
}

public func iTermContent (source: TerminalView, content: ArraySlice<UInt8>) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftTerm/iOS/iOSTextInput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
// Created by Miguel de Icaza on 1/28/21.
//

#if os(iOS)
#if os(iOS) || os(visionOS)
import Foundation
import UIKit
import CoreText
Expand Down

0 comments on commit 495c7c1

Please sign in to comment.