Repository navigation
Add custom buttons to UserInput prompts - #1348
Open
CraigBurden wants to merge 1 commit into
Open
CraigBurden wants to merge 1 commit into
CraigBurden wants to merge 1 commit into
Conversation
prompt() and start_prompt() take an optional `buttons` list of Button objects. The web GUI shows them in place of the Okay/Submit button. Buttons use the built-in blue/red/grey styles or any CSS color, with an optional label color. A prompt with buttons returns a PromptResponse(text, button): the text entered (empty unless text_input is set) and the value of the button pressed (its text unless a value is given). Prompts without buttons still return a string, so existing callers are unaffected. respond() takes the pressed button as an optional third argument and ignores responses to a button prompt that match none of its buttons. On the console the user enters any text first, then picks a button by its number, text or value.
This branch has not been deployed
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Add custom buttons to UserInput prompts
Motivation
Many operator prompts are really a choice: Pass / Fail, Retest / Stop, Accept / Reject. At the moment the only options are an Okay button or a text box, so tests either ask the operator to type a word or chain several yes/no prompts together. This PR lets a prompt offer its own buttons and reports which one was pressed. It works with or without a text box, so a single prompt can ask for a serial number and a verdict.
Changes
user_input.Button(text, color='grey', text_color=None, value=None):coloris one of the GUI's built-inblue/red/greystyles or any CSS color.valueis the button's response, and defaults totext.prompt()/start_prompt()take a keyword-onlybuttonsargument. A prompt with buttons returnsPromptResponse(text, button), aNamedTuple.textis''whentext_inputis false. Prompts without buttons still returnstr, so existing callers are unaffected.respond(prompt_id, response, button=None): for a button prompt,buttonmust match one of the buttons' responses, otherwise the response is ignored with a warning. Without buttons, behaviour is unchanged.htf-user-input-plugshows the buttons in place of Okay/Submit. Clicking a button sends[id, text, button value]. With buttons, Enter in the text box doesn't submit, because a button still has to be chosen.dist/is rebuilt withnpm run build._asdict()gains abuttonslist (text,value,color,text-color), using the same hyphenated key style astext-inputandimage-url.examples/all_the_things.pygets aninspect_widgetphase that shows the feature.Testing
test/plugs/user_input_test.py:buttonsentries in_asdict()PromptResponsepytest test(589 passed).StationServer:value='fail-value') returnsPromptResponse('', 'fail-value')PromptResponse('SN123', 'Reject')''SN9, thenmaybe(re-prompts), then2returnsPromptResponse('SN9', 'rej').🤖 Generated with Claude Code