Skip to content

Commit ce83437

Browse files
committed
Fixed demo readkey for macOS
1 parent e2ca80a commit ce83437

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

demo.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,29 @@
4646
api: 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+
4972
class 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":

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "garminconnect"
3-
version = "0.2.33"
3+
version = "0.2.34"
44
description = "Python 3 API wrapper for Garmin Connect"
55
authors = [
66
{name = "Ron Klinkien", email = "[email protected]"},

0 commit comments

Comments
 (0)