diff --git a/src/device/device.rs b/src/device/device.rs index 7df3a90..71a90e6 100644 --- a/src/device/device.rs +++ b/src/device/device.rs @@ -1,6 +1,8 @@ +#![allow(dead_code)] + use std::error::Error; -use crate::term::{serial::Serial, ssh::SshPass, tty::{DynTty, Tty}}; +use crate::term::{ssh::SshPass, tty::DynTty}; struct ShellOptions { diff --git a/src/pythonapi/shell_like.rs b/src/pythonapi/shell_like.rs index 43197bb..23b35e7 100644 --- a/src/pythonapi/shell_like.rs +++ b/src/pythonapi/shell_like.rs @@ -1,24 +1,15 @@ -use std::{ - any::TypeId, - ops::Deref, - ptr::{null, null_mut}, -}; +use std::ptr::null_mut; use pyo3::{exceptions::PyTypeError, prelude::*}; use serde::Deserialize; -use crate::{ - dyn_into, - exec::cli_api::{CliTestApi, SudoCliTestApi}, - term::{ - asciicast::Asciicast, - recorder::{self, Recorder, SimpleRecorder}, - serial::Serial, - shell::Shell, - ssh::Ssh, - tty::{DynTty, Tty, WrapperTty}, - }, - util::anybase::AnyBase, +use crate::term::{ + asciicast::Asciicast, + recorder::{Recorder, SimpleRecorder}, + serial::Serial, + shell::Shell, + ssh::Ssh, + tty::{DynTty, WrapperTty}, }; type TtyType = DynTty; @@ -368,6 +359,41 @@ impl PyTty { } fn swap(&mut self, other: &mut Self) -> PyResult<()> { - todo!() + let inner = self.inner.get_mut()?; + let inner = inner.as_any_mut(); + + if let Some(_) = inner.downcast_ref::() { + Err(PyTypeError::new_err("Can't convert to the type you want")) + } else if let Some(_) = inner.downcast_ref::() { + Err(PyTypeError::new_err("Can't convert to the type you want")) + } else if let Some(_) = inner.downcast_ref::() { + Err(PyTypeError::new_err("Can't convert to the type you want")) + } else if let Some(_) = inner.downcast_ref::() { + let inner = inner.downcast_mut::().unwrap(); + let target = other.inner.safe_take()?; + let target = Box::into_inner(target); + let target = inner.swap(target); + if let Err(e) = target { + return Err(PyTypeError::new_err(e.to_string())); + } + let target = target.unwrap(); + other.inner.tty = heap_raw(target); + Ok(()) + } else if let Some(_) = inner.downcast_ref::() { + let inner = inner.downcast_mut::().unwrap(); + let target = other.inner.safe_take()?; + let target = Box::into_inner(target); + let target = inner.swap(target); + if let Err(e) = target { + return Err(PyTypeError::new_err(e.to_string())); + } + let target = target.unwrap(); + other.inner.tty = heap_raw(target); + Ok(()) + } else { + Err(PyTypeError::new_err( + "What type is this? How do you get it?", + )) + } } } diff --git a/src/term/ssh.rs b/src/term/ssh.rs index 37fb4c2..4d2b770 100644 --- a/src/term/ssh.rs +++ b/src/term/ssh.rs @@ -9,7 +9,7 @@ use std::{ time::Duration, }; -use ssh2::{Channel, Session}; +use ssh2::Channel; use crate::{ consts::SHELL_DURATION,