Open
Conversation
* use FormattedText for prompt strings rather than ANSI * do all interpretation and formatting within render_prompt_string() ( renamed from get_prompt() ) * make formatting more robust: don't depend on a special string to be substituted for backslashes * inline an error message if the user gives an unrecognized backslash prompt format string * replace backslashes with forward slashes in socket names, in case they would be further substituted as format strings Motivation: It is much easier to figure out how to apply colors and styles using this method. Bugs and limitations: Since the substitutions are still done serially on a string (or list of strings), in the rare case that say a DSN-name substitution value contained a backslash, it might again be substituted, or fail. A better way could be to use "re.split()" with a capture group, replace known prompt strings with callables, then have a substitution pass, then join at the end. But the edge case of a double-substitution is very unlikely, and the edge case of HTML characters is handled.
ff2b14e to
a3aae2e
Compare
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.
Description
FormattedTextfor prompt strings rather thanANSIrender_prompt_string()( renamed fromget_prompt())Motivation:
It is much easier to figure out how to apply colors and styles using this method.
Bugs and limitations:
Since the substitutions are still done serially on a string (or list of strings), in the rare case that say a DSN-name substitution value contained a backslash, it might again be substituted, or fail. A better way could be to use
re.split()with a capture group, replace known prompt strings with callables, then have a substitution pass, then join at the end. But the edge case of a double-substitution is very unlikely, and the edge case of HTML characters is handled.Documentation: https://python-prompt-toolkit.readthedocs.io/en/stable/pages/printing_text.html#html
Example:
Checklist
changelog.mdfile.AUTHORSfile (or it's already there).