prompt-toolkit / prompt-toolkit/python-prompt-toolkit
Creating and maintaining evenly-spaced columns on full-application
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 10.6k
- Forks
- 815
- PR merge metrics
- No merged PRs in 30d
Description
is it possible to create a [vertically] evenly-spaced layout, which stays evenly spaced, even when dynamically changing content of window children?
Below is some sample code. Pressing c injects some content into the two windows' FormattedTextControl's, relative width changes (vertical divider moved with each press..). Columns are not evenly spaced even on initialization on narrow terminal when user_msg instructions are initially displayed (namely, application doesn't even start evenly spaced on a narrow terminal).
from random import randint
from prompt_toolkit.application import Application
from prompt_toolkit.key_binding import KeyBindings
from prompt_toolkit.layout.containers import VSplit, Window
from prompt_toolkit.layout.controls import FormattedTextControl
from prompt_toolkit.layout.dimension import D
from prompt_toolkit.layout.layout import Layout
user_msg = "press 'c' to change, 'q' to quit"
body = VSplit(
[
Window(
FormattedTextControl(text=user_msg),
width=D(weight=1),
wrap_lines=True,
),
Window(width=1, char="|"),
Window(FormattedTextControl(), width=D(weight=1), wrap_lines=True),
]
)
kb = KeyBindings()
@kb.add("c")
def change_content(event):
for w in event.app.layout.find_all_windows():
prev_width = f"prev_width: {w.render_info.window_width}"
rand_str = "*" * randint(1, 150)
w.content.text = "\n".join([prev_width, rand_str])
@kb.add("q")
def quit(event):
event.app.exit()
layout = Layout(body)
app = Application(layout=layout, key_bindings=kb, full_screen=True)
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
Start by running the sample code from the issue and reproducing the divider movement after pressing c, including on a narrow terminal. Then trace the VSplit, Window, and D(weight=1) layout behavior; done means both columns remain evenly spaced after content changes and at initial render.
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
- Mostly clear
- Newbie friendliness
- 38/100