我正在寻找一种方法来阻止以下栏的进度:
private static void cancellaaaaaaaaable() throws InterruptedException {
System.out.println("Cancellaaaaaaable!");
System.out.print(ANSI_RED);
for(int i = 0; i < 79; i++){
// Something that allows user input/interaction capable to stop the progressbar
System.out.print("█");
TimeUnit.MILLISECONDS.sleep(500);
}
System.out.print(ANSI_RESET);
}
当进度条开始时,用户应该有大约 40 秒的时间来决定停止和取消进度条。
有没有办法做到这一点?任何键盘输入都很棒,除了那些残酷地停止该过程的键盘输入。