made read blocking, adnd up to 1024 bytes

request env vars before opeing shell
cleanup
This commit is contained in:
neon443
2025-06-26 11:32:45 +01:00
parent e8ca091d0d
commit d9154458fa
4 changed files with 25 additions and 28 deletions

View File

@@ -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 }

View File

@@ -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<UInt8>) {

View File

@@ -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()
}
}