Add optional charset restriction to InputField
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
54f3e300a5
commit
fad3e5187e
+13
-9
@@ -689,15 +689,16 @@ class InputField:
|
||||
|
||||
def __init__(
|
||||
self, win, y: int, x: int, width: int,
|
||||
initial: str = "", mask: bool = False,
|
||||
initial: str = "", mask: bool = False, allowed: Optional[str] = None,
|
||||
) -> None:
|
||||
self._win = win
|
||||
self._y = y
|
||||
self._x = x
|
||||
self._width = width
|
||||
self._mask = mask
|
||||
self._buf = list(initial)
|
||||
self._cur = len(self._buf)
|
||||
self._win = win
|
||||
self._y = y
|
||||
self._x = x
|
||||
self._width = width
|
||||
self._mask = mask
|
||||
self._allowed = allowed
|
||||
self._buf = list(initial)
|
||||
self._cur = len(self._buf)
|
||||
|
||||
@property
|
||||
def value(self) -> str:
|
||||
@@ -737,7 +738,10 @@ class InputField:
|
||||
if self._cur < len(self._buf):
|
||||
del self._buf[self._cur]
|
||||
elif 32 <= key <= 126:
|
||||
self._buf.insert(self._cur, chr(key))
|
||||
ch = chr(key)
|
||||
if self._allowed is not None and ch not in self._allowed:
|
||||
return
|
||||
self._buf.insert(self._cur, ch)
|
||||
self._cur += 1
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user