prompt-toolkit / python-prompt-toolkit

Library for building powerful interactive command line applications in Python
https://python-prompt-toolkit.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
9.2k stars 714 forks source link

Support for Mixed-case in Style Tags ? #1098

Open jvickroy opened 4 years ago

jvickroy commented 4 years ago

Would it be possible to update line 170:

CLASS_NAMES_RE = re.compile(r"^[a-z0-9.\s_-]*$") # This one can't contain a comma!

in: https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/prompt_toolkit/styles/style.py

to support lower and UPPER case letters?

I like to create style tag names that use upper case letters for colors (R for Red, G for Green, etc.)

Thanks, /jim

jonathanslenders commented 4 years ago

Would this become case sensitive in that case? Are CSS classnames case sensitive?

jvickroy commented 4 years ago

First, apologies for my delayed response. Although, subscribed to this thread, I did not see an e-mail notification of your response. I'm a relative novice in using github so I may be doing something incorrectly.

Now to the matter at hand ...

Would this become case sensitive in that case?

Sorry, but I do not know what this refers to. Can you elaborate?

Are CSS classnames case sensitive?

I did not find anything recent but see: https://stackoverflow.com/questions/1547986/can-i-use-camelcase-in-css-class-names Could you explain why this is relevant? I'm not asking for prompt-toolkit to be case aware in this instance; I'm only asking that prompt-toolkit accept uppercase letters.

The following code fragment illustrates the issue:

from   prompt_toolkit.output import ColorDepth
from   prompt_toolkit.styles import Style

tags = Style.from_dict ( dict (
    _alert_      = 'fg:red   bg:yellow',
    _blue_white_ = 'fg:blue  bg:white',
    _button_     = 'fg:white bg:darkred',
    _hiliteY_    = 'fg:black bg:yellow'
##    _hilitey_    = 'fg:black bg:yellow', this works -- all lowercase
    _required_   = 'fg:Black bg:Yellow',
    _optional_   = 'fg:White bg:Green',
    _question_   = 'fg:Azure italic underline bg:DarkGreen',
    _decision_   = 'fg:Black bg:Orange',
    _keyboard_   = 'fg:White bg:Black',
    ))
default = dict (style=tags, color_depth=ColorDepth.TRUE_COLOR)

which produces the following in Python 3.8 and prompt-toolkit 3.0.5

Traceback (most recent call last):
  File "C:\Users\jgv\Documents\My Projects\AstroPixDB (FITS-peewee)\support\styling.py", line 12, in <module>
    tags = Style.from_dict ( dict (
  File "C:\Users\jgv\AppData\Local\Programs\Python\Python38\lib\site-packages\prompt_toolkit\styles\style.py", line 264, in from_dict
    return cls(list(style_dict.items()))
  File "C:\Users\jgv\AppData\Local\Programs\Python\Python38\lib\site-packages\prompt_toolkit\styles\style.py", line 232, in __init__
    assert CLASS_NAMES_RE.match(class_names), repr(class_names)
AssertionError: '_hiliteY_'

My contention is that hiliteY should be acceptable. What are your thoughts?

/jim