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

Flow layout or table (question/request)

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

Hi, I am experimenting with a move from curses to prompt_toolkit (and some rich) and having fun so far. One thing that I need to present to the user is a bunch of pairs of data. They are paths and the free space on the associated disk. It is presently output as follows and adjusts the number of 'cells' on each row based on the overall width of the terminal.

001:   24GB | 003:   25GB | 005:   38GB | 007:   66GB | 009: 9998GB |  |
002:   24GB | 004:   25GB | 006:   66GB | 008: 8256GB |             |  |
001:   24GB | 002:   24GB | 003:   25GB | 004:   25GB | 005:   38GB | 006:   66GB | 007:   66GB | 008: 8256GB | 009: 9998GB

It is not working beautifully or anything, but I share it to show one view of the idea. In general, I think the term 'flow layout' would be appropriate for what I want here. Or, alternatively, flowing the data through cells in a table. It might even be able to be viewed as a wrap feature with some control over exactly where the wrap can occur. Either way, there's a back and forth of sorts between the data size and the terminal size. The first few seconds of https://www.youtube.com/watch?v=pDqjHozkMBs show a flow layout. Note, I am a Qt/Python GUI dev significantly, not Java, but this video turned up quickly.

Does prompt_toolkit have any existing features to manage this? As mentioned, I can imagine that could be in the form of an ability to flow, an ability to control wrap points, or even just the ability to sensibly check the Window() width available for the content prior to creating the content and then I can manage the flow. The last point seems the simplest in terms of the demands on prompt_toolkit but I wasn't sure if there were caveats about doing that in combination with .invalidate() or similar potentially getting a different terminal size when they execute. That wouldn't be the end of the world, but if I can learn the proper way to handle the situation, that would be nice.

Thanks for any help you can offer to get me in the proper mindset to solve this well within the prompt_toolkit framework. For reference, my efforts are available at https://github.com/ericaltendorf/plotman/pull/299 and can be run via the plotman prompt_toolkit command. Though, I don't actually expect anyone to run it. :]

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 reviewing prompt_toolkit's Window width behavior and invalidate() handling, then compare the requested flow or table layout with the plotman PR #299 example. The issue names no source files or tests. Done would be a documented supported approach or a clearly scoped feature for adapting cells to terminal width.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.