akv_cli/pty/
mod.rs

1// Copyright 2024 Heath Stewart.
2// Licensed under the MIT License. See LICENSE.txt in the project root for license information.
3
4// cspell:ignore pseudoconsole
5#[cfg(not(windows))]
6mod posix;
7#[cfg(windows)]
8mod windows;
9
10#[cfg(not(windows))]
11use posix as inner;
12use std::{
13    fmt,
14    io::{self, Read},
15};
16#[cfg(windows)]
17use windows as inner;
18
19#[derive(Clone)]
20pub struct Pty<'a>(inner::Pty<'a>);
21
22impl fmt::Debug for Pty<'_> {
23    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24        // Format the inner directly instead of in a tuple.
25        self.0.fmt(f)
26    }
27}
28
29impl Read for Pty<'_> {
30    fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
31        self.0.read(buf)
32    }
33}
34
35pub trait CommandExt: __private::Sealed {
36    type Output;
37    fn spawn_pty<'a>(&mut self) -> crate::Result<(Self::Output, Pty<'a>)>;
38}
39
40mod __private {
41    pub trait Sealed {}
42    impl Sealed for std::process::Command {}
43}