我怎样才能为用户提供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()
}