diff --git a/ShhShell.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/ShhShell.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index a41539a..3c3e14b 100644 --- a/ShhShell.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/ShhShell.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -7,7 +7,7 @@ "location" : "https://github.com/migueldeicaza/SwiftTerm", "state" : { "branch" : "main", - "revision" : "f8e6e08b5a8c8eb0b18b9c250f36121e55c68f49" + "revision" : "bf476952af79b2458aac5b5297f1e00598e66007" } } ], diff --git a/ShhShell/SSH/SSHHandler.swift b/ShhShell/SSH/SSHHandler.swift index 798ee48..05c0cc1 100644 --- a/ShhShell/SSH/SSHHandler.swift +++ b/ShhShell/SSH/SSHHandler.swift @@ -83,6 +83,10 @@ class SSHHandler: @unchecked Sendable, ObservableObject { } } + ssh_channel_request_env(channel, "TERM", "xterm-256color") + ssh_channel_request_env(channel, "LANG", "en_US.UTF-8") + ssh_channel_request_env(channel, "LC_ALL", "en_US.UTF-8") + do { try openShell() } catch { @@ -90,9 +94,6 @@ class SSHHandler: @unchecked Sendable, ObservableObject { } setTitle("\(host.username)@\(host.address)") - ssh_channel_request_env(channel, "TERM", "xterm-256color") - ssh_channel_request_env(channel, "LANG", "en_US.UTF-8") - ssh_channel_request_env(channel, "LC_ALL", "en_US.UTF-8") } func connect() throws(SSHError) { @@ -380,8 +381,8 @@ class SSHHandler: @unchecked Sendable, ObservableObject { return nil } - var buffer: [CChar] = Array(repeating: 0, count: 16_384) - let nbytes = ssh_channel_read_nonblocking(channel, &buffer, UInt32(buffer.count), 0) + var buffer: [CChar] = Array(repeating: 0, count: 1024) + let nbytes = ssh_channel_read(channel, &buffer, UInt32(buffer.count), 0) guard nbytes > 0 else { return nil } diff --git a/ShhShell/Views/Terminal/SSHTerminalView.swift b/ShhShell/Views/Terminal/SSHTerminalView.swift index 2c0cbfb..7cd2cbb 100644 --- a/ShhShell/Views/Terminal/SSHTerminalView.swift +++ b/ShhShell/Views/Terminal/SSHTerminalView.swift @@ -24,6 +24,7 @@ final class SSHTerminalView: TerminalView, Sendable, @preconcurrency TerminalVie super.init(frame: frame) terminalDelegate = self + sshQueue.async { Task { guard let handler = await self.handler else { return } @@ -32,7 +33,12 @@ final class SSHTerminalView: TerminalView, Sendable, @preconcurrency TerminalVie if let read = handler.readFromChannel() { Task { [weak self] in guard let self else { return } - await self.feed(text: read) + await MainActor.run { + CATransaction.begin() + CATransaction.setDisableActions(true) + feed(text: read) + CATransaction.commit() + } } } else { try? await Task.sleep(nanoseconds: 10_000_000) //10ms @@ -42,31 +48,11 @@ final class SSHTerminalView: TerminalView, Sendable, @preconcurrency TerminalVie } } - public func resetTerminalView(handler: SSHHandler) { - self.handler = handler -// terminal.softReset() - self.setNeedsDisplay() - sshQueue.async { - while handler.connected { - if let read = handler.readFromChannel() { - Task { [weak self] in - guard let self else { return } - await self.feed(text: read) - } - } else { - Task{ try? await Task.sleep(nanoseconds: 10_000_000) } - } - } - } - } - required init?(coder: NSCoder) { fatalError("unimplemented") } - nonisolated public func scrolled(source: TerminalView, position: Double) { - - } + nonisolated public func scrolled(source: TerminalView, position: Double) {} nonisolated public func setTerminalTitle(source: TerminalView, title: String) { Task { @@ -76,6 +62,7 @@ final class SSHTerminalView: TerminalView, Sendable, @preconcurrency TerminalVie public func sizeChanged(source: TerminalView, newCols: Int, newRows: Int) { try? handler?.resizePTY(toRows: newRows, toCols: newCols) + setNeedsDisplay() } public func send(source: TerminalView, data: ArraySlice) { diff --git a/ShhShell/Views/Terminal/TerminalController.swift b/ShhShell/Views/Terminal/TerminalController.swift index c801d31..247511c 100644 --- a/ShhShell/Views/Terminal/TerminalController.swift +++ b/ShhShell/Views/Terminal/TerminalController.swift @@ -22,9 +22,18 @@ struct TerminalController: UIViewRepresentable { handler: handler ) + tv.translatesAutoresizingMaskIntoConstraints = false + tv.autoresizingMask = [.flexibleWidth, .flexibleHeight] + return tv } func updateUIView(_ tv: TerminalView, context: Context) { + tv.setNeedsLayout() + tv.layoutIfNeeded() + } + + static func dismantleUIView(_ uiView: SSHTerminalView, coordinator: ()) { + uiView.handler?.disconnect() } }