From fe0e58efe729db80457fef2cf005f6cdd931f52e Mon Sep 17 00:00:00 2001 From: greg Date: Sat, 9 Dec 2017 13:38:55 -0800 Subject: [PATCH] Go directly to langauge by name --- schala-lib/src/lib.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/schala-lib/src/lib.rs b/schala-lib/src/lib.rs index dd2dcfd..d5e32aa 100644 --- a/schala-lib/src/lib.rs +++ b/schala-lib/src/lib.rs @@ -229,10 +229,10 @@ impl Repl { "help" => { println!("Commands:"); println!("exit | quit"); - println!("lang [show|next|previous]"); + println!("lang(uage) [go|show|next|previous]"); println!("set [show|hide] [tokens|parse|symbols|eval|llvm]"); } - "lang" => { + "lang" | "language" => { match commands.get(1) { Some(&"show") => { 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") => { self.current_language_index = (self.current_language_index + 1) % self.languages.len(); println!("Switching to {}", self.languages[self.current_language_index].get_language_name());