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

avoid that HSplit produces gaps between children

Open
#777 3 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

hi @jonathanslenders,
i'd appreciate if you could give me a hint how to produce the desired effect.

from __future__ import unicode_literals
from prompt_toolkit.layout.containers import HSplit, VSplit, Window, ScrollOffsets, VerticalAlign
from prompt_toolkit import Application
from prompt_toolkit.layout.controls import FormattedTextControl
from prompt_toolkit.key_binding import KeyBindings
from prompt_toolkit.layout.dimension import LayoutDimension, Dimension
from prompt_toolkit.layout.layout import Layout
from prompt_toolkit.styles import Style

def gen_win(name, lines):
	def get_text_fragments():
		tokens = []
		tokens.extend([('class:blah.title', name + '\n')])
		for i in xrange(lines):
			tokens.append(('class:blah', '#####################'))
			tokens.append(('class:blah', '\n'))
		tokens.pop()
		return tokens
	return Window(
		FormattedTextControl(get_text_fragments),
		style='class:blah',
		width=Dimension.exact(16),
		height=Dimension(min=3),
	)

cont = HSplit([
	gen_win('foo', 3),
	gen_win('bar', 9),
], align=VerticalAlign.TOP)

kb = KeyBindings()
@kb.add(u'q')
@kb.add(u'c-q')
def exit_(event):
	event.app.exit()

app = Application(
	layout = Layout(
		cont,
	),
	full_screen=True,
	key_bindings=kb,
	style = Style.from_dict(
		{
			'blah':       'bg:#bbbbbb #000000',
			'blah.title': 'bg:#668866 #ffffff',
		}
	),
)

app.run()

what i'd like is basically

foo
##########
##########
##########

bar
##########
##########
...

<empty space here>

but what i get is

foo
##########
##########
##########

<empty space here>

bar
##########
##########
...

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 issue's Python reproducer and inspect how HSplit, VerticalAlign.TOP, Window, and Dimension determine child heights. Confirm the layout behavior against the shown output, then use the relevant layout tests or add a focused regression test. Done means the unused space appears after the children rather than between them.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.