1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use crate::{
com::{send::send, receive::receive},
error::InternalError
};
use std::ffi::CString;
impl super::Console {
pub fn read_line(&self, target: &mut String) -> Result<usize, crate::Error> {
unsafe {
send(self.pipe, "3".into())?;
let buffer = match CString::new([17 as u8; 1024]) {
Ok(v) => v.into_raw(),
Err(_) => return Err( InternalError::StringError.into() )
};
let bytes_read = receive(self.pipe, buffer, 1024)?;
match CString::from_raw(buffer).to_str() {
Ok(v) => target.push_str(&v.replace("\u{0011}", "")),
Err(_) => return Err( InternalError::StringError.into() )
};
Ok(bytes_read as usize)
}
}
}