more durable input logic
This commit is contained in:
parent
b3db83cbdd
commit
bea4d6797b
2
.gitignore
vendored
2
.gitignore
vendored
@ -5,3 +5,5 @@ lib/
|
|||||||
target/
|
target/
|
||||||
|
|
||||||
pyvenv.cfg
|
pyvenv.cfg
|
||||||
|
|
||||||
|
.aider*
|
||||||
|
|||||||
46
src/main.py
46
src/main.py
@ -228,11 +228,22 @@ class RedditCLI:
|
|||||||
# Show welcome screen
|
# Show welcome screen
|
||||||
self.show_welcome()
|
self.show_welcome()
|
||||||
# Get search query from user
|
# Get search query from user
|
||||||
query = input("\nEnter search query: ").strip()
|
while True:
|
||||||
if not query:
|
query = input("\nEnter search query: ").strip()
|
||||||
self.console.print("[red]No query provided. Exiting.[/red]")
|
if not query:
|
||||||
return
|
self.console.print(
|
||||||
self.search(query)
|
"[red]No query provided. Please try again.[/red]"
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
self.search(query)
|
||||||
|
break
|
||||||
|
except Exception as e:
|
||||||
|
if "User requested new search" in str(e):
|
||||||
|
# Continue the loop to get a new search query
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
raise e
|
||||||
else:
|
else:
|
||||||
# Process the provided query
|
# Process the provided query
|
||||||
self.search(args.query)
|
self.search(args.query)
|
||||||
@ -295,7 +306,30 @@ class RedditCLI:
|
|||||||
|
|
||||||
if not posts:
|
if not posts:
|
||||||
self.console.print("[yellow]No results found[/yellow]")
|
self.console.print("[yellow]No results found[/yellow]")
|
||||||
return
|
# Instead of returning, ask user if they want to search again
|
||||||
|
while True:
|
||||||
|
choice = (
|
||||||
|
input("\nWould you like to perform a new search? (y/n): ")
|
||||||
|
.strip()
|
||||||
|
.lower()
|
||||||
|
)
|
||||||
|
if choice in ["y", "yes"]:
|
||||||
|
new_query = input("Enter new search query: ").strip()
|
||||||
|
if new_query:
|
||||||
|
self.search(new_query)
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
self.console.print(
|
||||||
|
"[yellow]No query provided.[/yellow]"
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
elif choice in ["n", "no"]:
|
||||||
|
# Return to main menu by raising an exception that gets caught
|
||||||
|
raise Exception("User requested new search")
|
||||||
|
else:
|
||||||
|
self.console.print(
|
||||||
|
"[red]Please enter 'y' for yes or 'n' for no[/red]"
|
||||||
|
)
|
||||||
|
|
||||||
self.search_results = posts
|
self.search_results = posts
|
||||||
self.current_page = 0
|
self.current_page = 0
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user