1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use crate::io::{NcursesTerminalBridge, PipeError, ShellTerminalBridge, TerminalBridge};
use tokio::io::{split, AsyncRead, AsyncWrite};

impl<T: AsyncRead + AsyncWrite + Unpin + Send> PipeInteractiveExt for T {}

pub trait PipeInteractiveExt: AsyncRead + AsyncWrite + Unpin + Send {
    async fn interactive_shell(&mut self) -> Result<(), PipeError> {
        let (mut reader, mut writer) = split(self);
        ShellTerminalBridge::bridge(&mut reader, &mut writer).await;
        Ok(())
    }

    async fn interactive_ansi(&mut self) -> Result<(), PipeError> {
        let (mut reader, mut writer) = split(self);
        NcursesTerminalBridge::bridge(&mut reader, &mut writer).await;
        Ok(())
    }
}