Go directly to langauge by name

This commit is contained in:
greg 2017-12-09 13:38:55 -08:00
parent cc79565fb3
commit 7e7aa55d6e

View File

@ -229,10 +229,10 @@ impl Repl {
"help" => { "help" => {
println!("Commands:"); println!("Commands:");
println!("exit | quit"); println!("exit | quit");
println!("lang [show|next|previous]"); println!("lang(uage) [go|show|next|previous]");
println!("set [show|hide] [tokens|parse|symbols|eval|llvm]"); println!("set [show|hide] [tokens|parse|symbols|eval|llvm]");
} }
"lang" => { "lang" | "language" => {
match commands.get(1) { match commands.get(1) {
Some(&"show") => { Some(&"show") => {
for (i, lang) in self.languages.iter().enumerate() { for (i, lang) in self.languages.iter().enumerate() {
@ -243,6 +243,22 @@ impl Repl {
} }
} }
}, },
Some(&"go") => {
match commands.get(2) {
None => println!("Must specify a language name"),
Some(&desired_name) => {
for (i, _) in self.languages.iter().enumerate() {
let lang_name = self.languages[i].get_language_name();
if lang_name.to_lowercase() == desired_name.to_lowercase() {
self.current_language_index = i;
println!("Switching to {}", self.languages[self.current_language_index].get_language_name());
return true;
}
}
println!("Language {} not found", desired_name);
}
}
},
Some(&"next") => { Some(&"next") => {
self.current_language_index = (self.current_language_index + 1) % self.languages.len(); self.current_language_index = (self.current_language_index + 1) % self.languages.len();
println!("Switching to {}", self.languages[self.current_language_index].get_language_name()); println!("Switching to {}", self.languages[self.current_language_index].get_language_name());