@@ -120,30 +120,6 @@ fn shell_exec(vm: &mut VirtualMachine, source: &str, scope: PyObjectRef) -> bool
120
120
true
121
121
}
122
122
123
- fn read_until_empty_line ( input : & mut String ) -> Result < i32 , std:: io:: Error > {
124
- loop {
125
- print ! ( "..... " ) ;
126
- io:: stdout ( ) . flush ( ) . expect ( "Could not flush stdout" ) ;
127
- let mut line = String :: new ( ) ;
128
- match io:: stdin ( ) . read_line ( & mut line) {
129
- Ok ( _) => {
130
- line = line
131
- . trim_right_matches ( |c| c == '\r' || c == '\n' )
132
- . to_string ( ) ;
133
- if line. len ( ) == 0 {
134
- return Ok ( 0 ) ; // DOne
135
- } else {
136
- input. push_str ( & line) ;
137
- input. push_str ( "\n " ) ;
138
- }
139
- }
140
- Err ( msg) => {
141
- return Err ( msg) ;
142
- }
143
- }
144
- }
145
- }
146
-
147
123
fn run_shell ( ) {
148
124
println ! (
149
125
"Welcome to the magnificent Rust Python {} interpreter" ,
@@ -156,7 +132,13 @@ fn run_shell() {
156
132
// Read a single line:
157
133
let mut input = String :: new ( ) ;
158
134
loop {
159
- print ! ( ">>>>> " ) ; // Use 5 items. pypy has 4, cpython has 3.
135
+ // TODO: modules dont support getattr / setattr yet
136
+ //let prompt = match vm.get_attribute(vm.sys_module.clone(), "ps1") {
137
+ // Ok(value) => objstr::get_value(&value),
138
+ // Err(_) => ">>>>> ".to_string(),
139
+ //};
140
+ print ! ( ">>>>> " ) ;
141
+
160
142
io:: stdout ( ) . flush ( ) . expect ( "Could not flush stdout" ) ;
161
143
match io:: stdin ( ) . read_line ( & mut input) {
162
144
Ok ( 0 ) => {
@@ -168,11 +150,32 @@ fn run_shell() {
168
150
// Line was complete.
169
151
input = String :: new ( ) ;
170
152
} else {
171
- match read_until_empty_line ( & mut input) {
172
- Ok ( _) => {
173
- shell_exec ( & mut vm, & input, vars. clone ( ) ) ;
153
+ loop {
154
+ // until an empty line is pressed AND the code is complete
155
+ //let prompt = match vm.get_attribute(vm.sys_module.clone(), "ps2") {
156
+ // Ok(value) => objstr::get_value(&value),
157
+ // Err(_) => "..... ".to_string(),
158
+ //};
159
+ print ! ( "..... " ) ;
160
+ io:: stdout ( ) . flush ( ) . expect ( "Could not flush stdout" ) ;
161
+ let mut line = String :: new ( ) ;
162
+ match io:: stdin ( ) . read_line ( & mut line) {
163
+ Ok ( _) => {
164
+ line = line
165
+ . trim_right_matches ( |c| c == '\r' || c == '\n' )
166
+ . to_string ( ) ;
167
+ if line. len ( ) == 0 {
168
+ if shell_exec ( & mut vm, & input, vars. clone ( ) ) {
169
+ input = String :: new ( ) ;
170
+ break ;
171
+ }
172
+ } else {
173
+ input. push_str ( & line) ;
174
+ input. push_str ( "\n " ) ;
175
+ }
176
+ }
177
+ Err ( msg) => panic ! ( "Error: {:?}" , msg) ,
174
178
}
175
- Err ( msg) => panic ! ( "Error: {:?}" , msg) ,
176
179
}
177
180
}
178
181
}
0 commit comments