Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow with-style streaming APIs for communicating with a running program #71

Merged
merged 6 commits into from
Nov 8, 2024

Conversation

Joannis
Copy link
Member

@Joannis Joannis commented Sep 16, 2024

No description provided.

@giantrobotpilot
Copy link

This did not work for me. Can you give me a usage example? I implemented it like the following and I'm not sure it's correct.

do {
            try await client?.withExecutingCommand("calibration", inShell: false, perform: { inbound, outbound in
                var inboundStream = inbound.makeAsyncIterator()
                while let blob = try await inboundStream.next() {
                    switch blob {
                    case .stdout(let stdout):
                        let string = String(buffer: stdout)
                        print("stdout: \(string)")
                    case .stderr(let stderr):
                        print("stderr: \(String(buffer: stderr))")
                    }
                }
                 
                var buf = ByteBuffer()
                buf.setString("getCalibStatus", at: 0)
                try await outbound.write(buf)
            })
        } catch {
            self.error = error
            print("error: \(error)")
        }

One thing I noticed was that if I changed 'inShell' to 'true' I could see the command that was input and it was "calibration;exit" instead of "calibration." I'm not sure if that's relevant in this case.
ssh output

@Joannis
Copy link
Member Author

Joannis commented Sep 19, 2024

I've updated it to include a less invasive API. This should allow you to control the whole TTY now

@Joannis Joannis merged commit afe3204 into main Nov 8, 2024
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants