4646api : Garmin | None = None
4747
4848
49+ def safe_readkey () -> str :
50+ """
51+ Safe wrapper around readchar.readkey() that handles non-TTY environments.
52+
53+ This is particularly useful on macOS and in CI/CD environments where stdin
54+ might not be a TTY, which would cause readchar to fail with:
55+ termios.error: (25, 'Inappropriate ioctl for device')
56+
57+ Returns:
58+ str: A single character input from the user
59+ """
60+ if not sys .stdin .isatty ():
61+ print ("WARNING: stdin is not a TTY. Falling back to input()." )
62+ user_input = input ("Enter a key (then press Enter): " )
63+ return user_input [0 ] if user_input else ""
64+ try :
65+ return readchar .readkey ()
66+ except Exception as e :
67+ print (f"readkey() failed: { e } " )
68+ user_input = input ("Enter a key (then press Enter): " )
69+ return user_input [0 ] if user_input else ""
70+
71+
4972class Config :
5073 """Configuration class for the Garmin Connect API demo."""
5174
@@ -3710,7 +3733,7 @@ def main():
37103733 # Display appropriate menu
37113734 if current_category is None :
37123735 print_main_menu ()
3713- option = readchar . readkey ()
3736+ option = safe_readkey ()
37143737
37153738 # Handle main menu options
37163739 if option == "q" :
@@ -3727,7 +3750,7 @@ def main():
37273750 else :
37283751 # In a category - show category menu
37293752 print_category_menu (current_category )
3730- option = readchar . readkey ()
3753+ option = safe_readkey ()
37313754
37323755 # Handle category menu options
37333756 if option == "q" :
0 commit comments