👷 To fully customize your prompts, you'll have to take total control of formatting and colors. Here's what you need to know.
- General
bulletObjects- More Customization: Extending Existing Prompts
Always create an UI object with a prompt specified.
from bullet import Bullet, Check, YesNo, Input # and etc...
cli = Bullet(prompt = "Choose from the items below: ") # Create a Bullet or Check object
result = cli.launch() # Launch a promptcli = Bullet(choices = ["first item", "second item", "third item"])cli = Bullet(bullet = "★")
cli = Check(check = "√")
cli = Password(hidden = "*")
cli = ScrollBar(pointer = "→")You can also use emojis!
It is recommended to EXPLICITLY specify ALL colors for an UI object.
from bullet import colors🎨 The following colors (both background and foreground) are supported in
bullets. Note thatdefaultis the color of your default terminal.
default, black, red, green, yellow, blue, magenta, cyan, white
🎨 Remember to specify
foregroundandbackground.
black_foreground = colors.foreground["black"]
white_background = colors.background["white"]🎨 You can wrap a color with the
brightfunction
bright_cyan = colors.bright(colors.foreground["cyan"])🎨 Define the following colors when initializing the UI components.
- Use foreground colors:
bullet_colorcheck_colorpointer_colorindicator_colorcheck_on_switchword_colorword_on_switchseparator_color
- Use background colors:
background_colorbackground_on_switch
📐 Define the following UI components (not all is needed for some objects).
indent: distance from left-boundary to start of prompt.pad_right: extended background length.align: distance between bullet (or check) and start of prompt.margin: distance between list item and bullets (or checks).shift: number of new lines between prompt and first item.
👷 Currently only styles for
Bulletis supported.
from bullet import styles
client = Bullet(**styles.Greece)Single-choice prompt.
- Define
bulletwhen initializingBulletobject. - Move current position up and down using arrow keys.
- Returns the chosen item after pressing enter.
Multiple-choice prompt.
- Define
checkwhen initializingCheckobject. - Move current position up and down using arrow keys.
- Check/Un-check an item by pressing space.
- Returns the a list of chosen items after pressing enter.
Just vanilla user input.
strip: bool: whether to strip trailing spaces.pattern: str: Default is"". If defined, user input should match pattern.
Guarded Yes/No question.
- Only enter
y/Yorn/N. Other invalid inputs will be guarded, and the user will be asked to re-enter.
Enter passwords.
- Define
hiddenwhen initializingPasswordobject. This would be the character shown on the terminal when passwords are entered. - In convention, space characters
' 'are guarded and should not be in a password.
Enter numeric values.
- Non-numeric values will be guarded, and the user will be asked to re-enter.
- Define
typeto cast return value. For example,type = float, will cast return value tofloat.
Wrapping it all up.
- Stack
bulletUI components into one vertically-rendered prompt. - Returns a list of tuples
(prompt, result). spacing: number of lines between adjacent UI components.- Or, if
separatoris defined, each UI will be separated by a sequence ofseparatorcharacters. - See
./examples/prompt.pyto get a better understanding.
cli = VerticalPrompt(
[
YesNo("Are you a student? "),
Input("Who are you? "),
Numbers("How old are you? "),
Bullet("What is your favorite programming language? ",
choices = ["C++", "Python", "Javascript", "Not here!"]),
],
spacing = 1
)
result = cli.launch()- Link
bulletUI components into a multi-stage prompt. Previous prompts will be cleared upon entering the next stage. - Returns a list of tuples
(prompt, result).
For
Promptojects, callsummarize()after launching the prompt to print out user input.
Enhanced
Bullet: Too many items? It's OK!
pointer: points to item currently selected.up_indicator,down_indicator: indicators shown in first and last row of the rendered items.height: maximum items rendered on terminal.- For example, your can have 100 choices (
len(choices) = 100) but defineheight = 5.
- For example, your can have 100 choices (
See
./examples/check.pyfor the big picture of what's going on.
In bullet, you can easily inherit a base class (existing bullet objects) and create your customized prompt. This is done by introducing the keyhandler module to register user-defined keyboard events.
from bullet import keyhandlerSay you want the user to choose at least 1 and at most 3 items from a list of 5 items. You can inherit the Check class, and register a customized keyboard event as a method.
@keyhandler.register(NEWLINE_KEY)
def accept(self):
# do some validation checks: chosen items >= 1 and <= 3.Note that accept() is the method for all prompts to return user input. The binded keyboard event by default is NEWLINE_KEY pressed.
See
./bullet/charDef.py
LINE_BEGIN_KEY: Ctrl + HLINE_END_KEY: Ctrl + ETAB_KEYNEWLINE_KEY: EnterESC_KEYBACK_SPACE_KEYARROW_UP_KEYARROW_DOWN_KEYARROW_RIGHT_KEYARROW_LEFT_KEYINSERT_KEYDELETE_KEYEND_KEYPG_UP_KEYPG_DOWN_KEYSPACE_CHARINTERRUPT_KEY: Ctrl + C
