我怎样才能为用户提供 5 秒的时间来写一些东西,以便请求无限长的暂停。如果在这 5 秒内没有要求暂停,则该过程继续。如果需要暂停,则用户拥有他需要的所有时间,并且他可以点击“输入”以便在他想要的任何时候恢复该过程。
这种功能的有趣之处在于,如果用户不在,则暂停仅持续 5 秒。并且如果用户在场,那么他可以享受暂停以观看例如已经生成的图表。
代码最终可能如下所示:
DoYouWantaPause = function(){
myprompt = "You have 5 seconds to write the letter <p>. If you don't the process will go on."
foo = readline(prompt = myprompt, killAfter = 5 Seconds) # give 5 seconds to the user. If the user enter a letter, then this letter is stored in `foo`.
if (foo == "p" | foo == "P") { # if the user has typed "p" or "P"
foo = readline(prompt = "Press enter when you want to resume the process") # Offer a pause of indefinite length
}
}
# Main
for (i in somelist){
...
DoYouWantaPause()
}