From c8cc55e2bfdc8ac47967eeaaf8fa176ecc6850d1 Mon Sep 17 00:00:00 2001 From: Adam Demasi Date: Fri, 12 Mar 2021 23:21:38 +1030 Subject: [PATCH] [global] Some final fixing and cleanup --- Common/Controllers/SubProcess.swift | 2 +- Common/VT100/TerminalInputProtocol.swift | 3 +-- Mac/UI/Terminal/TerminalTextView.swift | 2 +- iOS/UI/Keyboard/TerminalKeyInput.swift | 2 +- iOS/UI/Keyboard/TextInputBase.h | 9 --------- iOS/UI/Terminal/TerminalSampleView.swift | 11 ++++++----- .../TerminalSessionViewController.swift | 10 ++++++++-- 7 files changed, 18 insertions(+), 21 deletions(-) diff --git a/Common/Controllers/SubProcess.swift b/Common/Controllers/SubProcess.swift index 9b9bf49..14d8eb1 100644 --- a/Common/Controllers/SubProcess.swift +++ b/Common/Controllers/SubProcess.swift @@ -19,7 +19,7 @@ enum SubProcessIOError: Error { case readFailed, writeFailed } -protocol SubProcessDelegate: NSObjectProtocol { +protocol SubProcessDelegate: AnyObject { func subProcessDidConnect() func subProcess(didReceiveData data: Data) diff --git a/Common/VT100/TerminalInputProtocol.swift b/Common/VT100/TerminalInputProtocol.swift index c950e3d..1dbbe0f 100644 --- a/Common/VT100/TerminalInputProtocol.swift +++ b/Common/VT100/TerminalInputProtocol.swift @@ -5,10 +5,9 @@ // Created by Adam Demasi on 20/6/19. // -public protocol TerminalInputProtocol { +public protocol TerminalInputProtocol: AnyObject { func receiveKeyboardInput(data: Data) - func openSettings() var applicationCursor: Bool { get } diff --git a/Mac/UI/Terminal/TerminalTextView.swift b/Mac/UI/Terminal/TerminalTextView.swift index ded985b..4542efb 100644 --- a/Mac/UI/Terminal/TerminalTextView.swift +++ b/Mac/UI/Terminal/TerminalTextView.swift @@ -9,7 +9,7 @@ import AppKit class TerminalTextView: NSTextView { - var terminalInputDelegate: TerminalInputProtocol? + weak var terminalInputDelegate: TerminalInputProtocol? override func keyDown(with event: NSEvent) { super.keyDown(with: event) diff --git a/iOS/UI/Keyboard/TerminalKeyInput.swift b/iOS/UI/Keyboard/TerminalKeyInput.swift index 38b7375..5ec246f 100644 --- a/iOS/UI/Keyboard/TerminalKeyInput.swift +++ b/iOS/UI/Keyboard/TerminalKeyInput.swift @@ -10,7 +10,7 @@ import UIKit class TerminalKeyInput: TextInputBase { - var terminalInputDelegate: TerminalInputProtocol? + weak var terminalInputDelegate: TerminalInputProtocol? weak var textView: UITextView! { didSet { textView.frame = bounds diff --git a/iOS/UI/Keyboard/TextInputBase.h b/iOS/UI/Keyboard/TextInputBase.h index 6e45879..d336fa3 100644 --- a/iOS/UI/Keyboard/TextInputBase.h +++ b/iOS/UI/Keyboard/TextInputBase.h @@ -7,15 +7,6 @@ #import -#ifndef __IPHONE_11_0 -#define UITextSmartQuotesType NSInteger -#define UITextSmartDashesType NSInteger -#define UITextSmartInsertDeleteType NSInteger -#define UITextSmartQuotesTypeNo 1 -#define UITextSmartDashesTypeNo 1 -#define UITextSmartInsertDeleteTypeNo 1 -#endif - @interface TextPosition : UITextPosition @property (nonatomic, strong) NSNumber *position; diff --git a/iOS/UI/Terminal/TerminalSampleView.swift b/iOS/UI/Terminal/TerminalSampleView.swift index 8cb4839..eb3156e 100644 --- a/iOS/UI/Terminal/TerminalSampleView.swift +++ b/iOS/UI/Terminal/TerminalSampleView.swift @@ -9,9 +9,9 @@ @objc(TerminalSampleView) class TerminalSampleView: UIView { - let textView = TerminalTextView(frame: .zero) - let buffer = VT100()! - let stringSupplier = VT100StringSupplier() + private let textView = TerminalTextView(frame: .zero) + private let buffer = VT100()! + private let stringSupplier = VT100StringSupplier() override init(frame: CGRect) { super.init(frame: frame) @@ -25,8 +25,9 @@ class TerminalSampleView: UIView { textView.isSelectable = false addSubview(textView) - let colorTest = try? Data(contentsOf: Bundle.main.url(forResource: "colortest", withExtension: "txt")!) - buffer.readInputStream(colorTest) + if let colorTest = try? Data(contentsOf: Bundle.main.url(forResource: "colortest", withExtension: "txt")!) { + buffer.readInputStream(colorTest) + } NotificationCenter.default.addObserver(self, selector: #selector(self.preferencesUpdated), name: Preferences.didChangeNotification, object: nil) preferencesUpdated() diff --git a/iOS/View Controllers/TerminalSessionViewController.swift b/iOS/View Controllers/TerminalSessionViewController.swift index 6d4e798..2b86f56 100644 --- a/iOS/View Controllers/TerminalSessionViewController.swift +++ b/iOS/View Controllers/TerminalSessionViewController.swift @@ -315,9 +315,15 @@ extension TerminalSessionViewController: TerminalControllerDelegate { // Display the bell HUD, lazily initialising it if it hasn’t been yet if bellHUDView.superview == nil { view.addSubview(bellHUDView) + let safeArea: String + if #available(iOS 11, *) { + safeArea = "safe" + } else { + safeArea = "self" + } view.addCompactConstraints([ - "hudView.centerX = self.centerX", - "hudView.centerY = self.centerY / 3" + "hudView.centerX = \(safeArea).centerX", + "hudView.centerY = \(safeArea).centerY / 3" ], metrics: nil, views: [ "self": view!, "hudView": bellHUDView