prompt-toolkit / prompt-toolkit/python-prompt-toolkit

Is it possible to force rendering TextArea?

Open
#1,845 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
10.6k
Forks
815
PR merge metrics
No merged PRs in 30d

Description

I am using ChatGPT streaming API, which I would like to print to a TextArea. Using the standard print method, it looks like this:

chat_translation_stream = self.client.chat.completions.create(
            ...,
            stream=True
        )
        reply = ""
        for chunk in chat_translation_stream:
            delta = chunk.choices[0].delta.content or ""
            reply += delta
            print(delta, end="", flush=True)

I replaced the print method with something like this in the accept_handler: output_field.buffer.document = Document( text=reply, cursor_position=len(reply) )
But it looks like the the TextArea is only at the end of the handler and not each time the document is modified. Is there a way to force the re-rendering?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the accept_handler and the streaming loop shown in the issue, focusing on how output_field.buffer.document is updated while TextArea is rendered. Trace the prompt-toolkit refresh path and determine what is needed for each streamed delta to become visible; done means the TextArea updates incrementally rather than only after the handler finishes.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.