use crate::{
com::{send::{sendc, sendstr}, receive::receive},
error::InternalError
};
use std::ffi::CStr;
impl super::Console {
pub fn read_line(&self, target: &mut String) -> Result<usize, crate::Error> {
unsafe {
sendc(self.pipe, 3)?;
sendstr(self.pipe, String::new())?;
let mut buffer = [0i8; 1024];
let len = receive(self.pipe, buffer.as_mut_ptr(), 1024)?;
match CStr::from_ptr(buffer.as_ptr()).to_str() {
Ok(v) => target.push_str(v),
Err(_) => return Err( InternalError::StringError.into() )
};
Ok(len as usize)
}
}
}