Skip to content

Commit

Permalink
Merge pull request #80 from petereon/dependabot/pip/urllib3-2.0.7
Browse files Browse the repository at this point in the history
build(deps-dev): bump urllib3 from 2.0.5 to 2.0.7
  • Loading branch information
petereon authored Dec 4, 2023
2 parents d1a65ac + d5be316 commit 1bda18b
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 60 deletions.
21 changes: 10 additions & 11 deletions APIDOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Creates a spinner which can be used to provide some user feedback during long pr
- `refresh_per_second` _float, optional_ - Number of refreshes the spinner will do a second, this will affect
the fluidity of the "animation". Defaults to 10.
- `transient` _bool, optional_ - If the spinner will disappear after it's done, otherwise not. Defaults to True.


**Raises**:

Expand Down Expand Up @@ -146,14 +146,14 @@ Function that prompts the user for written input
the error will be reported onto the console. Defaults to True.
- `raise_type_conversion_fail` _bool, optional_ - If True, invalid inputs will raise `rich.internals.ConversionError`, else
the error will be reported onto the console. Defaults to True.


**Raises**:

- `ValidationError` - Raised if validation with provided validator fails
- `ConversionError` - Raised if the value cannot be converted to provided type
- `KeyboardInterrupt` - Raised when keyboard interrupt is encountered and Config.raise_on_interrupt is True


**Returns**:

Expand Down Expand Up @@ -188,13 +188,13 @@ A prompt that allows selecting one option from a list of options
- `return_index` _bool, optional_ - If `True`, `select` will return the index of selected element in options. Defaults to `False`.
- `strict` _bool, optional_ - If empty `options` is provided and strict is `False`, None will be returned,
if it's `True`, `ValueError` will be thrown. Defaults to False.


**Raises**:

- `ValueError` - Thrown if no `options` are povided and strict is `True`
- `ValueError` - Thrown if no `options` are provided and strict is `True`
- `KeyboardInterrupt` - Raised when keyboard interrupt is encountered and Config.raise_on_interrupt is True


**Returns**:

Expand Down Expand Up @@ -238,12 +238,12 @@ A prompt that allows selecting multiple options from a list of options
of ticked elements in options. Defaults to `False`.
- `strict` _bool, optional_ - If empty `options` is provided and strict is `False`, None will be returned,
if it's `True`, `ValueError` will be thrown. Defaults to False.


**Raises**:

- `KeyboardInterrupt` - Raised when keyboard interrupt is encountered and Config.raise_on_interrupt is True


**Returns**:

Expand Down Expand Up @@ -278,14 +278,13 @@ A prompt that asks a question and offers two responses
- `cursor` _str, optional_ - What character(s) to use as a cursor. Defaults to '> '.
- `cursor_style` _str, optional_ - Rich friendly style for the cursor. Defaults to 'pink1'.
- `char_prompt` _bool, optional_ - Print [Y/n] after the question. Defaults to True.


**Raises**:

- `KeyboardInterrupt` - Raised when keyboard interrupt is encountered and Config.raise_on_interrupt is True


**Returns**:

Optional[bool]

24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ if confirm("Will you take the ring to Mordor?"):
# Choose one item from a list
name = select(names, cursor="🢧", cursor_style="cyan")
console.print(f"Alámenë, {name}")


item_options = [
"The One Ring",
"Dagger",
Expand All @@ -66,44 +66,44 @@ if confirm("Will you take the ring to Mordor?"):
console.print("What do you bring with you?")
# Choose multiple options from a list
items = select_multiple(item_options, tick_character='🎒', ticked_indices=[0], maximal_count=3)

potato_count = 0
if "Po-tae-toes" in items:
# Prompt with type conversion and validation
potato_count = prompt('How many potatoes?', target_type=int, validator=lambda count: count > 0)

# Spinner to show while doing some work
spinner = Spinner(DOTS, "Packing things...")
spinner.start()

time.sleep(2)

spinner.stop()
# Get input without showing it being typed
if "friend" == prompt("Speak, [blue bold underline]friend[/blue bold underline], and enter", secure=True).lower():

# Custom spinner animation
spinner_animation = ['▉▉', '▌▐', ' ', '▌▐', '▉▉']
spinner = Spinner(spinner_animation, "Opening the Door of Durin...")
spinner.start()

time.sleep(2)

spinner.stop()
else:
spinner_animation = ['🐙🌊 ⚔️ ', '🐙 🌊 ⚔️ ', '🐙 🌊 ⚔️ ', '🐙 🌊 ⚔️ ', '🐙 🌊⚔️ ']
spinner = Spinner(spinner_animation, "Getting attacked by an octopus...")
spinner.start()

time.sleep(2)

spinner.stop()

if 'The One Ring' in items:
console.print("[green]You throw The One Ring to a lava from an eagle![/green]")
else:
console.print("[red]You forgot the ring and brought Middle-Earth to its knees![/red]")
console.print(f"And you brought {potato_count} taters!")
console.print(f"And you brought {potato_count} taters!")
```

For more information refer to [more examples](https://petereon.github.io/beaupy/examples/) or definitive, but much less exciting [API documentation](https://petereon.github.io/beaupy/api/)
Expand Down
8 changes: 4 additions & 4 deletions beaupy/_beaupy.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def prompt(
renderer=renderer,
)

with element.diplayed():
with element.displayed():
while True:
key = get_key()
new_state = element.state
Expand Down Expand Up @@ -270,7 +270,7 @@ def select(
page_size (int, optional): Number of options to show on a single page if pagination is enabled. Defaults to 5.
Raises:
ValueError: Thrown if no `options` are povided and strict is `True`
ValueError: Thrown if no `options` are provided and strict is `True`
KeyboardInterrupt: Raised when keyboard interrupt is encountered and Config.raise_on_interrupt is True
Returns:
Expand Down Expand Up @@ -298,7 +298,7 @@ def select(
renderer=renderer,
)

with element.diplayed():
with element.displayed():

while True:
keypress = get_key()
Expand Down Expand Up @@ -391,7 +391,7 @@ def select_multiple(
renderer=renderer,
)

with element.diplayed():
with element.displayed():
while True:
keypress = get_key()
new_state = element.state
Expand Down
18 changes: 9 additions & 9 deletions docs/content/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Selective elements default to return the selected item (in case of `select`) or list of items (in case of `select_multiple`). This behavior can be modified by `return_index` parameter (or `return_indices` in case of the latter), see example,

```python
result_index = select(options=['I\'ll be returned as 0', 'I\'ll be returned as 1'],
result_index = select(options=['I\'ll be returned as 0', 'I\'ll be returned as 1'],
return_index=True)
```

Expand Down Expand Up @@ -49,15 +49,15 @@ pizza_toppings = select_multiple(['pineapple', 'olives', 'anchovies', 'mozzarell
#### Style as text

```python
stylish = select(options = ["red", "on", "white"],
cursor = "x",
stylish = select(options = ["red", "on", "white"],
cursor = "x",
cursor_style= "red on white")
```

#### Style as hex

```python
selections = select_multiple(options = ["s", "h", "e", "", "b", "e", "l", "i", "e", "v", "e", "d"],
selections = select_multiple(options = ["s", "h", "e", "", "b", "e", "l", "i", "e", "v", "e", "d"],
tick_style="#af00ff",
ticked_indices=[1,2,6,7,8,11])
```
Expand All @@ -70,14 +70,14 @@ selections = select_multiple(options = ["s", "h", "e", "", "b", "e", "l", "i", "
Some emojis can appear as one character instead of two!

```python
result = select(options = ["here", "comes", "the", "sun"],
result = select(options = ["here", "comes", "the", "sun"],
cursor = "🌞")
```

#### Non-ascii as a cursor

```python
result = select(options = ["hardcore", "unicode"],
result = select(options = ["hardcore", "unicode"],
cursor = "")
```

Expand All @@ -87,7 +87,7 @@ result = select(options = ["hardcore", "unicode"],
You can use multiple characters as a cursor

```python
correct_abba_lyric = select_multiple(options = ["queen", "bean"],
correct_abba_lyric = select_multiple(options = ["queen", "bean"],
tick_character = "dancing")
```

Expand Down Expand Up @@ -149,7 +149,7 @@ from os import listdir
from pathlib import Path

# ugly hacky path completion callable:
def path_completion(str_path: str = ""):
def path_completion(str_path: str = ""):
if not str_path:
return []
try:
Expand Down Expand Up @@ -214,4 +214,4 @@ Animation speed can be set using `refresh_per_second` parameter:
from beaupy.spinners import Spinner, LOADING
spinner = Spinner(LOADING, "something", refresh_per_second=4)
spinner.start()
```
```
35 changes: 18 additions & 17 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = 'beaupy'
version = '3.7.0'
version = '3.7.1'
description = 'A library of elements for interactive TUIs in Python'
authors = ['Peter Vyboch <[email protected]>']
license = 'MIT'
Expand Down Expand Up @@ -42,7 +42,7 @@ python = '^3.7.8'
rich = "^12.2.0"
emoji = "^2.0.0"
python-yakh = "0.3.2"
questo = "^0.1.2"
questo = "^0.2.0"


[tool.mypy]
Expand Down
2 changes: 1 addition & 1 deletion test/beaupy_internals_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def _():

@test("Test that prompt is rendered with error")
def _():

result = _render_prompt(False, qprompt.PromptState(value='ab', title='Test prompt', error='Test Error', cursor_position=1))
assert (
result == "Test prompt\n> a[black on white]b[/black on white] \n\n(Confirm with [bold]enter[/bold])\n[red]Error:[/red] Test Error"
Expand Down
Loading

0 comments on commit 1bda18b

Please sign in to comment.