prompt-toolkit / prompt-toolkit/python-prompt-toolkit
Create Layout that does not contain any Window object
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 10.6k
- Forks
- 815
- PR merge metrics
- No merged PRs in 30d
Description
I want to initialize my layout with an empty HSplit. Children are added and removed later while the application is running. The first child is not available when I create the Layout.
>>> from prompt_toolkit.layout import Layout
>>> from prompt_toolkit.layout.containers import HSplit
>>> Layout(HSplit(children=[]))
Traceback (most recent call last):
File "/home/ich/code/upsies/venv/lib/python3.8/site-packages/prompt_toolkit/layout/layout.py", line 61, in __init__
self._stack.append(next(self.find_all_windows()))
StopIteration
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ich/code/upsies/venv/lib/python3.8/site-packages/prompt_toolkit/layout/layout.py", line 63, in __init__
raise InvalidLayoutError(
prompt_toolkit.layout.layout.InvalidLayoutError: Invalid layout. The layout does not contain any Window object.
I tried replacing the exception with a pass in https://github.com/prompt-toolkit/python-prompt-toolkit/blob/10f5cca40f40f5dbda4c521ba72270b23f72628c/prompt_toolkit/layout/layout.py#L63 and the tests were passing, but then the current_control property broke. It looks like non-emptiness is built into the guts of the Layout class.
I could add an empty window, but that adds an empty line. I could remove that window when I've added the first real widget, but that's not very elegant or obvious why that's necessary.
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
Read prompt_toolkit/layout/layout.py, especially the constructor logic that finds a Window and the current_control property. Reproduce the empty HSplit case, inspect the existing layout tests, and define tests showing that children can be added and removed later without requiring a dummy Window or breaking current_control.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100