prompt-toolkit / python-prompt-toolkit

Library for building powerful interactive command line applications in Python
https://python-prompt-toolkit.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
9.23k stars 715 forks source link

Scroll a ScrollablePane to show the bottom element. #1565

Open MinekPo1 opened 2 years ago

MinekPo1 commented 2 years ago

While trying to make a simple chat app (just a passion project, no high stakes), I ran into a problem when displaying messages:

Since the amount of messages can increase above what can be displayed on the screen (the server side max is 50 messages at 2 lines each or 100 lines total), we want to use the ScrollablePane element. However when new elements are added at the bottom, they are not visible when the number of messages reaches a certain point.

I have tried implementing the desired behavior, but was unable, as the only way I thought of required query a components size and I was unsuccessful at finding any method do such.

lin-calvin commented 1 year ago

Try this

#item it the last item of your message container
curr=self.app.layout.current_window
self.app.layout.focus(item)
self.app._redraw()
self.app.layout.focus(curr)
self.app._redraw()

it works well for me