prompt-toolkit / prompt-toolkit/python-prompt-toolkit
Possible bug: zero-width-escapes at the end of a line are not rendered
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 10.6k
- Forks
- 815
- PR merge metrics
- No merged PRs in 30d
Description
Hi Jonathan,
I think I've come across a potential bug in prompt_toolkit.renderer._output_screen_diff: if a line of output is updated so it ends with a zero-width-escape fragment, the ZWE at the end of the line does not get rendered.
In the example app below, pressing u appends a text fragment and a ZWE fragment (red text) to the end of the output. However, the zwe fragment is not rendered since it is at the end of a line. If another text fragment is append (u), or the app is closed (q), the ZWE at the end of the line is rendered.
I'm using red text to represent a ZWE in this example, but my use case is using ZWEs to display terminal graphics.
from prompt_toolkit.application import Application
from prompt_toolkit.layout.layout import Layout
from prompt_toolkit.layout.containers import Window
from prompt_toolkit.layout.controls import FormattedTextControl
from prompt_toolkit.key_binding import KeyBindings
formatted_text = [
("", "start-of-line"),
]
kb = KeyBindings()
@kb.add("u")
def update(event):
formatted_text.extend(
[
("", " text-fragment"),
("[ZeroWidthEscape]", "\x1b[0;31m zwe-fragment\x1b[0m"),
]
)
@kb.add("c-q")
def quit(event):
event.app.exit()
app = Application(
full_screen=False,
layout=Layout(container=Window(FormattedTextControl(lambda: formatted_text))),
key_bindings=kb,
)
app.run()
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Run the provided prompt_toolkit example and inspect prompt_toolkit.renderer._output_screen_diff while pressing u to reproduce the missing zero-width escape at the line end. Confirm the fix by checking that the final zero-width-escape fragment is rendered immediately after the update, without needing another text fragment or application exit.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100