From 270cc179c882f4d95bba78fe296a2e812b655cd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=9B=BD=E6=94=BF?= Date: Tue, 12 Nov 2024 15:48:01 +0800 Subject: [PATCH] [mod]Fixed readme description Make TTYStdinWriter.ChangeSize function is available --- README.md | 24 +++++++++++++++++++++++- Sources/Citadel/TTY/Client/TTY.swift | 10 +++++----- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b34244b..be47a51 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,29 @@ while let blob = try await asyncStreams.next() { } ``` -Citadel currently does not expose APIs for streaming into a process' `stdin`. If you want this, please create an issue. +Citadel currently expose APIs for streaming into a process' `stdin`. only withPTY and withTTY. + +An example of how pty model can be used: + +```swift +try await client.withPTY( + SSHChannelRequestEvent.PseudoTerminalRequest( + wantReply: true, + term: "xterm", + terminalCharacterWidth: 80, + terminalRowHeight: 24, + terminalPixelWidth: 0, + terminalPixelHeight: 0, + terminalModes: .init([.ECHO: 1]) + ), + environment: [SSHChannelRequestEvent.EnvironmentRequest(wantReply: true, name: "LANG", value: "en_US.UTF-8")]) { + + ttyOutput, ttyStdinWriter in + + ...do something... +} +``` + ### SFTP Client diff --git a/Sources/Citadel/TTY/Client/TTY.swift b/Sources/Citadel/TTY/Client/TTY.swift index 0b73abd..9acf5fd 100644 --- a/Sources/Citadel/TTY/Client/TTY.swift +++ b/Sources/Citadel/TTY/Client/TTY.swift @@ -80,13 +80,13 @@ public struct TTYStdinWriter { try await channel.writeAndFlush(SSHChannelData(type: .channel, data: .byteBuffer(buffer))) } - public func changeSize(cols: Int, rows: Int) async throws { + public func changeSize(cols: Int, rows: Int, pixelWidth:Int, pixelHeight:Int) async throws { try await channel.triggerUserOutboundEvent( SSHChannelRequestEvent.WindowChangeRequest( - terminalCharacterWidth: 0, - terminalRowHeight: 0, - terminalPixelWidth: 0, - terminalPixelHeight: 0 + terminalCharacterWidth: cols, + terminalRowHeight: rows, + terminalPixelWidth: pixelWidth, + terminalPixelHeight: pixelHeight ) ) }