|
|
@@ -1,10 +1,14 @@
|
|
1
|
|
-use std::io::BufRead;
|
|
2
|
|
-use std::io::Write;
|
|
|
1
|
+use std::io::{BufRead,Write,Read, StdinLock, StdoutLock};
|
|
|
2
|
+use std::io;
|
|
|
3
|
+
|
|
3
|
4
|
use command::*;
|
|
4
|
5
|
use std::str::FromStr;
|
|
5
|
6
|
use std::env;
|
|
6
|
7
|
|
|
7
|
|
-pub struct Shell<R:BufRead, W:Write> {
|
|
|
8
|
+pub struct R<'a>(pub StdinLock<'a>);
|
|
|
9
|
+pub struct W<'a>(pub StdoutLock<'a>);
|
|
|
10
|
+
|
|
|
11
|
+pub struct Shell<R, W> {
|
|
8
|
12
|
pub reader: R,
|
|
9
|
13
|
pub writer: W,
|
|
10
|
14
|
pub should_exit: bool,
|
|
|
@@ -74,3 +78,30 @@ impl <R:BufRead, W:Write> Shell<R, W> {
|
|
74
|
78
|
|
|
75
|
79
|
}
|
|
76
|
80
|
|
|
|
81
|
+impl <'a>Read for R<'a> {
|
|
|
82
|
+ fn read(&mut self, buf: &mut [u8]) -> Result<usize, io::Error> {
|
|
|
83
|
+ self.0.read(buf)
|
|
|
84
|
+ }
|
|
|
85
|
+}
|
|
|
86
|
+
|
|
|
87
|
+impl <'a>BufRead for R<'a> {
|
|
|
88
|
+
|
|
|
89
|
+ fn fill_buf(&mut self) -> Result<&[u8], io::Error> {
|
|
|
90
|
+ self.0.fill_buf()
|
|
|
91
|
+ }
|
|
|
92
|
+
|
|
|
93
|
+ fn consume(&mut self, amt: usize) {
|
|
|
94
|
+ self.0.consume(amt)
|
|
|
95
|
+ }
|
|
|
96
|
+}
|
|
|
97
|
+
|
|
|
98
|
+impl <'a>Write for W<'a> {
|
|
|
99
|
+ fn write(&mut self, buf: &[u8]) -> Result<usize, io::Error> {
|
|
|
100
|
+ self.0.write(buf)
|
|
|
101
|
+ }
|
|
|
102
|
+
|
|
|
103
|
+ fn flush(&mut self) -> Result<(), io::Error> {
|
|
|
104
|
+ self.0.flush()
|
|
|
105
|
+ }
|
|
|
106
|
+}
|
|
|
107
|
+
|