mirror of
https://github.com/daylinmorgan/hwylterm.git
synced 2024-12-21 18:50:44 -06:00
add basic confim util
This commit is contained in:
parent
7e82f7ba5a
commit
e175cf1fc9
2 changed files with 23 additions and 2 deletions
|
@ -10,5 +10,5 @@
|
|||
|
||||
]##
|
||||
|
||||
import hwylterm/[spin, bbansi]
|
||||
export spin, bbansi
|
||||
import hwylterm/[spin, bbansi, confirm]
|
||||
export spin, bbansi, confirm
|
||||
|
|
21
src/hwylterm/confirm.nim
Normal file
21
src/hwylterm/confirm.nim
Normal file
|
@ -0,0 +1,21 @@
|
|||
import std/[strutils]
|
||||
import ./bbansi
|
||||
|
||||
proc confirm*(
|
||||
question: string,
|
||||
prefix = "",
|
||||
suffix = ""
|
||||
): bool =
|
||||
result = false
|
||||
stderr.write $(question & bb"[yellow] (Y/n) ")
|
||||
while true:
|
||||
let ans = readLine(stdin)
|
||||
case ans.strip().toLowerAscii():
|
||||
of "y","yes": return true
|
||||
of "n","no": return false
|
||||
else:
|
||||
stderr.write($bb("[red]Please answer Yes/no\nexpected one of [b]Y,yes,N,no "))
|
||||
stderr.write "\n"
|
||||
|
||||
when isMainModule:
|
||||
echo "Response: ", confirm("Is it working?")
|
Loading…
Reference in a new issue