-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Cannot delete text in InputField #133
Comments
Also when typing in the InputField, the letters or digits are added at the beginning of the input instead of the end. |
Windows 11/Powershell/Windows Terminal and also experiencing this issue |
20240102-2235-17.6046383.mp4 |
Same error here, on windows 11 power shell |
Could you show me the output of pressing backspace while running |
I just ran into this issue as well. Here is the output for backspace:
And the output for delete:
Note the behavior of If I call msvcrt.getch directly, I get this: backspace:
delete:
|
Huh, that's interesting. The codes seem correct, so no idea why it doesn't behave properly. Maybe someone with a Windows machine could diagnose it further?
Could you record a video of this as a separate issue? That's definitely not intended! |
Sorry I don't have a video, but I did look into this further and tried to do some debugging with pdb. I set a breakpoint in the GetchWindow constructor and can see the "Press any key" prompt appears, but when running the program normally (not in a debugger) it is not visible, possibly because the screen refreshes so quickly. The issue appears to be with the call to Lines 184 to 185 in e6ef8b3
If there is no pending keypress, PS E:\tmp> python -c 'import pytermgui; print(ascii(pytermgui.input.getch()))'
''
PS E:\tmp> python -c 'import pytermgui; print(ascii(pytermgui.input.getch(windows_raise_timeout=True)))'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\user\.virtualenvs\ptg-test--GZ1WdmM\Lib\site-packages\pytermgui\input.py", line 441, in getch
key = _getch()
^^^^^^^^
File "C:\Users\user\.virtualenvs\ptg-test--GZ1WdmM\Lib\site-packages\pytermgui\input.py", line 209, in __call__
buff = self.get_chars()
^^^^^^^^^^^^^^^^
File "C:\Users\user\.virtualenvs\ptg-test--GZ1WdmM\Lib\site-packages\pytermgui\input.py", line 185, in get_chars
raise TimeoutException("No input available.")
pytermgui.exceptions.TimeoutException: No input available.
PS E:\tmp> Most examples I have seen of Anyhow, I realize this doesn't address the original problem regarding backspace and delete. I am still not sure what is causing that issue. |
Could you try commenting out: Lines 182 to 185 in e6ef8b3
Looking at it again, it seems that not checking up front would be the more accurate algorithm when compared to the UNIX implementation. |
With the following changes, --- a/pytermgui/input.py
+++ b/pytermgui/input.py
@@ -23,6 +23,7 @@
from codecs import getincrementaldecoder
from contextlib import contextmanager
from select import select
+from time import time
from typing import (
IO,
Any,
@@ -172,7 +173,7 @@
return string
- def get_chars(self) -> str:
+ def get_chars(self, timeout: int = 3) -> str:
"""Reads characters from sys.stdin.
Returns:
@@ -181,14 +182,17 @@
# We need to type: ignore these on non-windows machines,
# as the library does not exist.
- if not msvcrt.kbhit(): # type: ignore
- raise TimeoutException("No input available.")
-
- char = msvcrt.getch() # type: ignore
- if char == b"\xe0":
- char = "\x1b"
-
- buff = self._ensure_str(char)
+ start = time()
+ while True:
+ if msvcrt.kbhit(): # type: ignore
+ char = msvcrt.getch() # type: ignore
+ if char == b"\xe0":
+ char = "\x1b"
+
+ buff = self._ensure_str(char)
+ break
+ if time() - start > timeout:
+ raise TimeoutException("No input available.")
while msvcrt.kbhit(): # type: ignore
char = msvcrt.getch() # type: ignore The first loop waits for the initial key-press (within 3 seconds by default). The second loop collects any remaining buffered key-presses. However the original problem still exists. I have been using the second example in the README for testing. With the patch above, CTRL-H works for backspace, but the actual backspace key still doesn't work. Unfortunately there are additional issues as well when comparing Windows and Linux. For example, the arrow keys do not work on Windows either, and the text on the submit button is not visible in the Windows version. While PyTermGUI may be great for non-Windows platforms, I think it needs a dedicated maintainer/tester for Windows to be considered cross-platform. Unfortunately I do not have the time to do so, and have discovered another project (Textual) that seems to better fit my needs. |
Unfortunately I'm just one guy, so this is the best I can do :( I think the problem here is PowerShell, and its many incompatibilities with pretty much every other shell ever. Since the $TERM and $COLORTERM env vars don't seem to be set, a lot of our compatibility shims don't really work in this configuration. Your changes are good, but they further distance the UNIX and Windows implementations unfortunately. I believe my suggestion above should be enough to fix the divergence in |
Cannot delete text in InputField
To Reproduce
Expected behavior
Pressing backspace or delete should delete the text
System information
Windows 11, Powershell, Windows Terminal
The text was updated successfully, but these errors were encountered: