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

Different rendering for focused or unfocused ScrollablePane

Open
#1,792 2 comments 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

The following code demonstrates a rendering difference between focused and unfocused mode:

import asyncio
from time import sleep

from prompt_toolkit.application import Application
from prompt_toolkit.buffer import Buffer
from prompt_toolkit.key_binding import KeyBindings
from prompt_toolkit.layout import ScrollablePane, HSplit, Layout, Window
from prompt_toolkit.layout.controls import BufferControl
from prompt_toolkit.widgets import Frame, TextArea


class Runner:
    def __init__(self):
        self.buffer = Buffer()
        self.buffer_control = BufferControl(buffer=self.buffer)
        self.scrollable_pane = ScrollablePane(
            Window(self.buffer_control, wrap_lines=True), show_scrollbar=True, height=5
        )
        self.text_control = TextArea(
            prompt="Your username: ", multiline=False, password=False
        )
        self.focused_pane = Frame(self.text_control)

        root_container = HSplit([self.scrollable_pane, self.focused_pane])
        self.layout = Layout(root_container)

        self.app = Application(layout=self.layout)

    async def run(self):
        asyncio.create_task(self.update_buffer())
        kb = KeyBindings()

        @kb.add("c-q")
        def _(event) -> None:
            event.app.exit()

        self.layout.focus(self.focused_pane)
        await self.app.run_async()

    async def run_pane_focused(self):
        asyncio.create_task(self.update_buffer())
        kb = KeyBindings()

        @kb.add("c-q")
        def _(event) -> None:
            event.app.exit()

        self.layout.focus(self.scrollable_pane)
        await self.app.run_async()

    async def update_buffer(self):
        count = 0
        while count < 10:
            self.buffer.insert_text(f"New Line {count}\n")
            count += 1
            self.scrollable_pane.vertical_scroll = count
            await asyncio.sleep(1)

        self.app.exit()


if __name__ == "__main__":
    runner = Runner()
    # asyncio.run(runner.run())
    asyncio.run(runner.run_pane_focused())

Toggle the different runner methods to see the difference.

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 by running the Python reproduction with ScrollablePane focused and unfocused, then inspect ScrollablePane's rendering and focus handling. Compare both modes while the buffer updates; done means the pane renders consistently in either focus state.

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
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.