Skip to content

Add a new module KLQueries for sanitized input prompts - #46

Merged
a-hurst merged 8 commits into
testingfrom
klqueries
Oct 21, 2026
Merged

a-hurst merged 8 commits into
testingfrom
klqueries

Conversation

@a-hurst

@a-hurst a-hurst commented Oct 6, 2026 •

Copy link
Copy Markdown
Owner

PR Description

This PR adds a new module (KLQueries) for easily prompting and validating keyboard input from users. This was previously technically possible with horrendous abuse of the query function in KLCommunications (or adding custom 'experimental' queries to the user_queries.json file), but this module provides the same functionality (and more) with a much cleaner and simpler API.

Currently, the KLQueries module provides 3 Query classes: NumberQuery, ChoiceQuery, and TextQuery, each for different types of responses. NumberQueries ensure that the user's response is numeric and enforces upper and lower bounds on the response. ChoiceQueries are for multiple-choice queries and ensure the response is one of a set of possible options, and TextQueries are for free-form text responses (with optional limits on the minimum/maximum number of characters). The module also provides the QueryStyle class for customizing the location and appearance of queries.

A FormatQuery class that requires responses follow a regex-style format (e.g. "P###") is planned for the future.

In addition to the new module itself, the blit function has also been fully re-documented with a proper explanation of the location and registration parameter, which was necessary in order to reference the explanation in the documentation for QueryStyle.

This PR is intended to completely remove the need for KLCommunication.query from the public API (currently only used in BaseballTOJ and TraceLab) and lay the groundwork for replacinguser_queries.json itself with a more flexible and more readable pure-Python equivalent.

Merge Checklist

  • the PR has been reviewed and all comments are resolved
  • all CI checks pass
  • (if applicable): the PR description includes the phrase closes #<issue-number> to automatically close an issue
  • (if applicable): bug fixes, new features, or API changes are documented in CHANGELOG.rst

@a-hurst
a-hurst merged commit 058ff40 into testing Oct 21, 2026
7 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant