textual: app hangs when pasting emoji from clipboard to an Input widget

Although Input widgets display emojis correctly when a value is set in code (I mean actual emoji like 😊not :smiling_face_with_smiling_eyes:), the whole app hangs when trying to paste emoji from the clipboard on Windows 10.

As a sample code, one can use even this first example: Input - Textual Then copy an emoji to the clipboard and then try to paste it (either Ctr+V or Ctrl+Shift+V) For me, the main app hangs and the respective python process needs to be terminated. The textual console continues to work.

Here is the output from the textual console:

───────────── Client '127.0.0.1' connected ────────────────────────────────────────────────────
[09:56:30] PRINT                                                                                                                                                                                      app.py:1102
Exception in thread Thread-1:
[09:56:30] PRINT                                                                                                                                                                                      app.py:1102
Traceback (most recent call last):
[09:56:30] PRINT                                                                                                                                                                                      app.py:1102
  File "c:\Users\user\AppData\Local\Programs\Python\Python311\Lib\threading.py", line 1038, in _bootstrap_inner
[09:56:30] PRINT                                                                                                                                                                                      app.py:1102
    self.run()
[09:56:30] PRINT                                                                                                                                                                                      app.py:1102
  File "C:\Projekty\RPG\.py311_env\Lib\site-packages\textual\drivers\_writer_thread.py", line 60, in run
[09:56:30] PRINT                                                                                                                                                                                      app.py:1102
    write(text)
[09:56:30] PRINT                                                                                                                                                                                      app.py:1102
UnicodeEncodeError: 'utf-8' codec can't encode characters in position 423-424: surrogates not allowed


I could reproduce this on Win10 in Windows Terminal 1.17 using PowerShell 7. Works fine on Ubuntu 22. When run using PowerShell, but not inside Windows Terminal, nothing is pasted, but at least the app continues to work. Still, this is useless since emojis do not work in PS without WT.

Textual Diagnostics

Versions

Name Value
Textual 0.33.0
Rich 13.5.2

Python

Name Value
Version 3.11.4
Implementation CPython
Compiler MSC v.1934 64 bit (AMD64)
Executable C:\Projekty\RPG\.py311_env\Scripts\python.exe

Operating System

Name Value
System Windows
Release 10
Version 10.0.19044

Terminal

Name Value
Terminal Application Windows Terminal
TERM Not set
COLORTERM Not set
FORCE_COLOR Not set
NO_COLOR Not set

Rich Console options

Name Value
size width=209, height=52
legacy_windows False
min_width 1
max_width 209
is_terminal True
encoding utf-8
max_height 52
justify None
overflow None
no_wrap False
highlight None
markup None
height None

About this issue

  • Original URL
  • State: closed
  • Created 10 months ago
  • Comments: 15 (8 by maintainers)

Commits related to this issue

Most upvoted comments

FAQ links are fixed now…

Ah, in that case no need for the conditional.

Of note:

>>> print('\ud83d\ude09')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'utf-8' codec can't encode characters in position 0-1: surrogates not allowed
>>> print('\ud83d\ude09'.encode('utf-16', 'surrogatepass').decode('utf-16'))
πŸ˜‰

@HubertReX The auto-generated link is correct, pointing to the FAQ; the other link is the HOWTO, which is far more comprehensive. The reason the FAQ link is broken at the moment is we’re β€œbetween FAQs” (it used to be in the repo, it’s moving to the docs on website, we’ve just not published the updated version of the docs yet).