bchao1 / bullet

🚅 Interactive prompts made simple. Build a prompt like stacking blocks.
https://pypi.org/project/bullet/
MIT License
3.55k stars 113 forks source link

feature request: tree view #14

Open lwerdna opened 5 years ago

lwerdna commented 5 years ago

Long shot here, but let me dream :)

Jengah commented 5 years ago

Can you give a description of the intended functionality you hope to see in a "tree view" feature?

lwerdna commented 5 years ago

Sure, I want a list where there is a hierarchy, and by expanding one given list item, its sub options become available.

In a filesystem analogy, the un-expanded list items are folders, and the sub options becoming available when you click to expand are the files within that folder.

CurtisPreston99 commented 5 years ago

you can already do something like the file thing

from bullet import Bullet
from bullet import colors
import os

d = '.'

while True:
    files=[os.path.join(d, o) for o in os.listdir(d) 
                    if os.path.isdir(os.path.join(d,o))]

    cli = Bullet(
            prompt = "\nPlease choose a fruit: ",
            choices =files, 
            indent = 0,
            align = 5, 
            margin = 2,
            shift = 0,
            bullet = "",
            pad_right = 5
            )
    result = cli.launch()
    print("You chose:", result)
    os.chdir(result)

but in my fork Bullet supports dicts that you could feed the "tree structure" into like this

from bullet import Bullet
from bullet import colors

tree ={"op1":{"subop1":"end"},
         "op2":{"subop2":"end"},
         "op3":{"subop3":
                  {"subsub op":"end"}}} 

while True:
    cli = Bullet(
            prompt = "\nPlease choose a fruit: ",
            choices =tree, 
            indent = 0,
            align = 5, 
            margin = 2,
            shift = 0,
            bullet = "",
            pad_right = 5
            )
    result = cli.launch()
    print("You chose:", result)
    tree=result
    if(tree=="end"):
         break

print("reached leaf")