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

Store calculated height on ScrollablePane to enable tail -f like behaviour

Open
#1,791 0 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

We can use pane.vertical_scroll to manipulate the scrolling so it always shows the last line, useful for having a pane that shows some log or command output. However, this value needs to be equal to the lines written minus the height of the pane, which is easy to get if it's set on initialisation, but it is not if the pane is dynamic and supposed to fill the available height.

The height is calculated by preferred_height, but that receives input from its caller that we can't easily ascertain. The result of this calculation is kept private.

To correctly use vertical_scroll, we need to implement the following:

if pane.height and state.line_counter > pane.height:
    pane.vertical_scroll = state.line_counter - pane.height

Which works for the fixed height case and can be simplified to: max(0, state.line_counter - pane.height) if we had some attribute available that has the current height of the pane, regardless of whether it's fixed or dynamically sized.

But see also the related bug.

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 in src/prompt_toolkit/layout/scrollable_pane.py, especially preferred_height and the handling of vertical_scroll. Trace how the calculated height reaches the pane and determine what current height information is available for dynamically sized panes. Done means callers can use the current height to keep output positioned at the last line in both fixed- and dynamic-height cases.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.