mirror of
https://github.com/neon443/ShhShell.git
synced 2026-03-11 13:26:16 +00:00
improved how the terminal is updated, now just async reads aytomatically and will js not do anything if nothing recieved
terminal also starts at the top and doesnt have th wierd scroll artifacting
This commit is contained in:
@@ -311,21 +311,21 @@ class SSHHandler: ObservableObject {
|
||||
// RunLoop.main.add(self.readTimer!, forMode: .common)
|
||||
}
|
||||
|
||||
func readFromChannel() -> String {
|
||||
guard ssh_channel_is_open(channel) != 0 else { return "" }
|
||||
guard ssh_channel_is_eof(channel) == 0 else { return "" }
|
||||
func readFromChannel() -> String? {
|
||||
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)
|
||||
var buffer: [CChar] = Array(repeating: 0, count: 16)
|
||||
let nbytes = ssh_channel_read_nonblocking(channel, &buffer, UInt32(buffer.count), 0)
|
||||
|
||||
guard nbytes > 0 else { return "" }
|
||||
guard nbytes > 0 else { return nil }
|
||||
write(1, buffer, Int(nbytes))
|
||||
|
||||
let data = Data(bytes: buffer, count: buffer.count)
|
||||
if let string = String(data: data, encoding: .utf8) {
|
||||
return string
|
||||
}
|
||||
return ""
|
||||
return nil
|
||||
}
|
||||
|
||||
private func logSshGetError() {
|
||||
|
||||
@@ -22,6 +22,16 @@ class SSHTerminalView: TerminalView, TerminalViewDelegate {
|
||||
|
||||
super.init(frame: frame)
|
||||
terminalDelegate = self
|
||||
sshQueue.async {
|
||||
guard let handler = self.handler else { return }
|
||||
while handler.connected {
|
||||
guard let handler = self.handler else { break }
|
||||
guard let read = handler.readFromChannel() else { return }
|
||||
DispatchQueue.main.async {
|
||||
self.feed(text: read)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
|
||||
@@ -23,11 +23,9 @@ struct TerminalController: UIViewRepresentable {
|
||||
)
|
||||
// tv.terminalDelegate = terminalDelegate
|
||||
|
||||
tv.getTerminal().feed(text: handler.readFromChannel())
|
||||
return tv
|
||||
}
|
||||
|
||||
func updateUIView(_ tv: TerminalView, context: Context) {
|
||||
tv.getTerminal().feed(text: handler.readFromChannel())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user