From 92a83e34d0e63cf93265727b924e8e6faeb6c29f Mon Sep 17 00:00:00 2001 From: Kanishk Pachauri Date: Tue, 17 Sep 2024 01:46:01 +0530 Subject: [PATCH] fix: Handle program kill errors correctly --- src/bitssh/prompt.py | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/bitssh/prompt.py b/src/bitssh/prompt.py index ea2078a..1e169df 100644 --- a/src/bitssh/prompt.py +++ b/src/bitssh/prompt.py @@ -3,27 +3,33 @@ from .utils import ConfigPathUtility from .ui import console import os - from inquirer import List -from typing import List, Dict +from typing import List, Dict, Optional + def ask_host_prompt(): - HOST: list[str] = ConfigPathUtility.get_config_file_host_data() - questions: list[List] = [ + HOST: List[str] = ConfigPathUtility.get_config_file_host_data() + questions: List[List] = [ inquirer.List( name="host", message="Select the Host Given in the Above List", choices=HOST, ), ] + try: + answers: Optional[Dict[str, str]] = inquirer.prompt( + questions=questions, theme=GreenPassion() + ) + if answers is None: + return - answers: Dict[str, str] = inquirer.prompt(questions=questions, theme=GreenPassion()) - - cmd: str = answers["host"] - cmd: str = cmd[6::] - cmd: str = f"ssh {cmd}" - console.print( - "Please Wait While Your System is Connecting to the Remote Server 🖥️", - style="green", - ) - os.system(cmd) + cmd: str = answers["host"] + cmd = cmd[6:] + cmd = f"ssh {cmd}" + console.print( + "Please Wait While Your System is Connecting to the Remote Server 🖥️", + style="green", + ) + os.system(cmd) + except Exception as Error: + print(f"\nInterrupted by {Error}")