2
2
// License, v. 2.0. If a copy of the MPL was not distributed with this
3
3
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
4
mod helper;
5
+ mod theme;
5
6
6
7
use std:: { cell:: RefCell , collections:: VecDeque , fmt:: Debug } ;
7
8
8
9
use clap:: { Parser as ClapParser , Subcommand } ;
10
+ use cliclack:: { input, intro, set_theme} ;
9
11
use helper:: { exit_with_parse_errors, initialize_global_object} ;
10
12
use nova_vm:: ecmascript:: {
11
13
execution:: {
@@ -17,6 +19,7 @@ use nova_vm::ecmascript::{
17
19
} ;
18
20
use oxc_parser:: Parser ;
19
21
use oxc_span:: SourceType ;
22
+ use theme:: DefaultTheme ;
20
23
21
24
/// A JavaScript engine
22
25
#[ derive( Debug , ClapParser ) ] // requires `derive` feature
@@ -49,10 +52,7 @@ enum Command {
49
52
} ,
50
53
51
54
/// Runs the REPL
52
- Repl {
53
- #[ arg( short, long) ]
54
- verbose : bool ,
55
- } ,
55
+ Repl { } ,
56
56
}
57
57
58
58
#[ derive( Default ) ]
@@ -165,13 +165,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
165
165
}
166
166
}
167
167
}
168
- Command :: Repl { verbose } => {
168
+ Command :: Repl { } => {
169
169
let allocator = Default :: default ( ) ;
170
170
let host_hooks: & CliHostHooks = & * Box :: leak ( Box :: default ( ) ) ;
171
171
let mut agent = Agent :: new (
172
172
Options {
173
173
disable_gc : false ,
174
- print_internals : verbose ,
174
+ print_internals : true ,
175
175
} ,
176
176
host_hooks,
177
177
) ;
@@ -187,9 +187,18 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
187
187
}
188
188
let realm = agent. current_realm_id ( ) ;
189
189
190
+ set_theme ( DefaultTheme ) ;
191
+ println ! ( "\n \n " ) ;
192
+ let mut placeholder = "Enter a line of Javascript" . to_string ( ) ;
193
+
190
194
loop {
191
- let mut input = String :: new ( ) ;
192
- std:: io:: stdin ( ) . read_line ( & mut input) ?;
195
+ intro ( "Nova Repl (type exit or ctrl+c to exit)" ) ?;
196
+ let input: String = input ( "" ) . placeholder ( & placeholder) . interact ( ) ?;
197
+
198
+ if input. matches ( "exit" ) . count ( ) == 1 {
199
+ std:: process:: exit ( 0 ) ;
200
+ }
201
+ placeholder = input. to_string ( ) ;
193
202
let script = match parse_script ( & allocator, input. into ( ) , realm, true , None ) {
194
203
Ok ( script) => script,
195
204
Err ( ( file, errors) ) => {
@@ -199,9 +208,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
199
208
let result = script_evaluation ( & mut agent, script) ;
200
209
match result {
201
210
Ok ( result) => {
202
- if verbose {
203
- println ! ( "{:?}" , result) ;
204
- }
211
+ println ! ( "{:?}\n " , result) ;
205
212
}
206
213
Err ( error) => {
207
214
eprintln ! (
0 commit comments