-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Quantum RPG] allow action selections to be modified #182
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3de7cb5
allow action selections to be modified
solodov 04a8765
match statement is not available yet in unitary tests
solodov aa5db22
fixed lint warnings
solodov 49ab194
and another lint warning
solodov 67fe0dd
Finished support for confirming selection:
solodov 6b97ead
Merge branch 'main' into main
solodov 7113984
fixed lint warning
solodov 4aed4e1
"redo selection" instead of "select again"
solodov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,3 +42,5 @@ docs/generated | |
|
||
# Notebook formatting script. | ||
nbformat | ||
|
||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
"""Functions for safe and user-friendly input.""" | ||
|
||
from typing import Callable, Optional, Sequence, TextIO | ||
from typing import Callable, Optional, Sequence, TextIO, Union | ||
|
||
import sys | ||
import unitary.examples.quantum_rpg.qaracter as qaracter | ||
|
||
from unitary.examples.quantum_rpg import qaracter | ||
|
||
_USER_INPUT = Callable[[str], str] | ||
_INVALID_MESSAGE = "Invalid number selected." | ||
|
@@ -27,9 +28,9 @@ def get_user_input_number( | |
get_user_input: _USER_INPUT, | ||
message: str = "", | ||
max_number: Optional[int] = None, | ||
invalid_message: Optional[str] = _INVALID_MESSAGE, | ||
invalid_message: str = _INVALID_MESSAGE, | ||
file: TextIO = sys.stdout, | ||
): | ||
) -> int: | ||
"""Helper to get a valid number from the user. | ||
|
||
This will only accept valid numbers from the user from 1 to max_number. | ||
|
@@ -54,9 +55,32 @@ def get_user_input_number( | |
print("number out of range", file=file) | ||
|
||
|
||
def get_multiple_user_inputs( | ||
get_user_input: _USER_INPUT, | ||
*prompts: Sequence[Union[Callable[[], int], Callable[[], str]]], | ||
file: TextIO = sys.stdout, | ||
) -> Sequence[Union[int, str]]: | ||
"""Runs multiple number or string prompts and returns their results. | ||
|
||
After all inputs have been provided the last prompt asks for confirmation if | ||
user happy with inputs, and allows to restart the sequence and change | ||
inputs. | ||
""" | ||
while True: | ||
inputs = [p() for p in prompts] | ||
print("[enter]) Confirm selection.", file=file) | ||
print("r) Select again.", file=file) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we could change this to "Redo selection" so that the choice of 'r' is more obvious? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
while True: | ||
a = get_user_input("Choose your action: ") | ||
if a == "r": | ||
break | ||
if a == "": | ||
return inputs | ||
|
||
|
||
def get_user_input_qaracter_name( | ||
get_user_input: _USER_INPUT, | ||
qaracter_type: Optional[str] = "a new qaracter", | ||
qaracter_type: str = "a new qaracter", | ||
file: TextIO = sys.stdout, | ||
): | ||
while True: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am conflicted about making the user do an extra prompt at the end for every action. Let's discuss at the next unitary meeting.