add basic confim util

This commit is contained in:
Daylin Morgan 2024-10-08 15:32:24 -05:00
parent 7e82f7ba5a
commit e175cf1fc9
Signed by: daylin
GPG key ID: 950D13E9719334AD
2 changed files with 23 additions and 2 deletions

View file

@ -10,5 +10,5 @@
]## ]##
import hwylterm/[spin, bbansi] import hwylterm/[spin, bbansi, confirm]
export spin, bbansi export spin, bbansi, confirm

21
src/hwylterm/confirm.nim Normal file
View 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?")