我目前正在尝试使用 Spring Shell 制作一个 cli 应用程序。
我希望用户能够快速选择 2-3 个选项之一。我当前的代码在 Eclipse 中运行良好,但是当我在 Powershell 中启动它时,我必须多次(至少 3 次)按 Enter 才能选择该选项。按一次回车后,什么也没有发生。
我目前的方法:
@ShellMethod(key = { "setService", "select" }, value = "Choose a Speech to Text Service")
public void setService() {
boolean success = false;
do {
this.console.write("Please select a speech recognition service. Type in the number and press enter:");
this.console.write("1. Google Speech API");
this.console.write("2. Bing Speech API");
// Get Input
Scanner s = new Scanner(System.in);
String input = s.nextLine();
// Select Service
switch (input) {
case "1":
/*
* do something...
*/
console.write("Google Speech API selected");
success = true;
break;
case "2":
/*
* do something...
*/
console.write("Bing Speech API selected");
success = true;
break;
default:
this.console.error("Input not valid. Please type a number and press Enter to select a Service");
break;
}
} while (!success);
}
如何解决 powershell 的问题,或者是否有更优雅的方式来执行此输入?