mirror of
https://github.com/caelestia-dots/cli.git
synced 2026-06-16 05:49:59 -05:00
fix: handle ctrl+c/d cleanly
Also add newline before pause prompt
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
from caelestia.parser import parse_args
|
||||
from caelestia.utils.io import log
|
||||
from caelestia.utils.version import print_version
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser, args = parse_args()
|
||||
if args.version:
|
||||
print_version()
|
||||
elif "cls" in args:
|
||||
args.cls(args).run()
|
||||
else:
|
||||
parser.print_help()
|
||||
try:
|
||||
parser, args = parse_args()
|
||||
if args.version:
|
||||
print_version()
|
||||
elif "cls" in args:
|
||||
args.cls(args).run()
|
||||
else:
|
||||
parser.print_help()
|
||||
except KeyboardInterrupt:
|
||||
log("Exiting...")
|
||||
|
||||
@@ -42,10 +42,18 @@ def fatal(msg: str) -> None:
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def _input(prompt: str) -> str:
|
||||
try:
|
||||
return input(prompt)
|
||||
except (KeyboardInterrupt, EOFError):
|
||||
print()
|
||||
raise KeyboardInterrupt()
|
||||
|
||||
|
||||
def prompt(msg: str) -> str:
|
||||
return input(_format_msg(36, msg) + " ")
|
||||
return _input(_format_msg(36, msg) + " ")
|
||||
|
||||
|
||||
def pause() -> None:
|
||||
input("\033[2m\033[3m(Ctrl+C to exit, enter to continue)\033[0m")
|
||||
print("\033[1A\r\033[2K", end="") # Clear pause prompt
|
||||
_input("\n\033[2m\033[3m(Ctrl+C to exit, enter to continue)\033[0m")
|
||||
print("\033[1A\r\033[2K\033[1A\r\033[2K", end="") # Clear pause prompt
|
||||
|
||||
Reference in New Issue
Block a user