diff --git a/ShhShell/SSH/SSHHandler.swift b/ShhShell/SSH/SSHHandler.swift index 18a3c3a..2f88714 100644 --- a/ShhShell/SSH/SSHHandler.swift +++ b/ShhShell/SSH/SSHHandler.swift @@ -320,8 +320,8 @@ class SSHHandler: ObservableObject { guard ssh_channel_is_open(channel) != 0 else { return nil } guard ssh_channel_is_eof(channel) == 0 else { return nil } - var buffer: [CChar] = Array(repeating: 0, count: 256) - let nbytes = ssh_channel_read_nonblocking(channel, &buffer, UInt32(buffer.count), 0) + var buffer: [CChar] = Array(repeating: 0, count: 512) + let nbytes = ssh_channel_read(channel, &buffer, UInt32(buffer.count), 0) guard nbytes > 0 else { return nil } @@ -345,7 +345,10 @@ class SSHHandler: ObservableObject { guard ssh_channel_is_open(channel) != 0 else { return } guard ssh_channel_is_eof(channel) == 0 else { return } - var buffer: [CChar] = Array(string.utf8CString) + var buffer: [CChar] = [] + for byte in string.utf8 { + buffer.append(CChar(bitPattern: byte)) + } let nwritten = Int(ssh_channel_write(channel, &buffer, UInt32(buffer.count))) if nwritten != buffer.count { @@ -353,7 +356,7 @@ class SSHHandler: ObservableObject { } } - func resizeTTY(toRows: Int, toCols: Int) { + func resizePTY(toRows: Int, toCols: Int) { guard ssh_channel_is_open(channel) != 0 else { return } guard ssh_channel_is_eof(channel) == 0 else { return } diff --git a/ShhShell/Views/ConnectionView.swift b/ShhShell/Views/ConnectionView.swift index cd034dc..036f3f9 100644 --- a/ShhShell/Views/ConnectionView.swift +++ b/ShhShell/Views/ConnectionView.swift @@ -136,6 +136,10 @@ struct ConnectionView: View { .disabled(!(handler.connected && handler.authorized)) Button() { + if handler.authorized && handler.connected { + } else { + handler.go() + } withAnimation { handler.testExec() } } label: { if let testResult = handler.testSuceeded { diff --git a/ShhShell/Views/Terminal/SSHTerminalView.swift b/ShhShell/Views/Terminal/SSHTerminalView.swift index 956dc8c..ccf279a 100644 --- a/ShhShell/Views/Terminal/SSHTerminalView.swift +++ b/ShhShell/Views/Terminal/SSHTerminalView.swift @@ -31,8 +31,9 @@ class SSHTerminalView: TerminalView, TerminalViewDelegate { if let read = handler.readFromChannel() { DispatchQueue.main.async { self?.feed(text: read) } } else { - usleep(1_000) + usleep(1_000_000) } +// self?.setNeedsDisplay() } } } @@ -50,7 +51,7 @@ class SSHTerminalView: TerminalView, TerminalViewDelegate { } public func sizeChanged(source: TerminalView, newCols: Int, newRows: Int) { - handler?.resizeTTY(toRows: newRows, toCols: newCols) + handler?.resizePTY(toRows: newRows, toCols: newCols) } public func send(source: TerminalView, data: ArraySlice) {