Exemplo n.º 1
0
def test_render():
    bar = Bar(size=100, begin=11, end=62, width=50)
    bar_render = render(bar)
    assert bar_render == expected[0]
    bar = Bar(size=100, begin=12, end=57, width=50)
    bar_render = render(bar)
    assert bar_render == expected[1]
    # begin after end
    bar = Bar(size=100, begin=60, end=40, width=50)
    bar_render = render(bar)
    assert bar_render == expected[2]
Exemplo n.º 2
0
 def render(self, task):
     return Bar(
         total=task.total,
         completed=task.completed,
         width=self.bar_width,
         style='dim white',
     )
Exemplo n.º 3
0
def test_render():
    bar = Bar(completed=11, width=50)
    bar_render = render(bar)
    assert bar_render == expected[0]
    bar.update(completed=12)
    bar_render = render(bar)
    assert bar_render == expected[1]
Exemplo n.º 4
0
def test_get_pulse_segments():
    bar = Bar()
    segments = bar._get_pulse_segments(
        Style.parse("red"), Style.parse("yellow"), "standard", False
    )
    print(repr(segments))
    expected = [
        Segment("━", Style.parse("red"), False),
        Segment("━", Style.parse("red"), False),
        Segment("━", Style.parse("red"), False),
        Segment("━", Style.parse("red"), False),
        Segment("━", Style.parse("red"), False),
        Segment("━", Style.parse("red"), False),
        Segment("━", Style.parse("red"), False),
        Segment("━", Style.parse("red"), False),
        Segment("━", Style.parse("red"), False),
        Segment("━", Style.parse("red"), False),
        Segment("━", Style.parse("yellow"), False),
        Segment("━", Style.parse("yellow"), False),
        Segment("━", Style.parse("yellow"), False),
        Segment("━", Style.parse("yellow"), False),
        Segment("━", Style.parse("yellow"), False),
        Segment("━", Style.parse("yellow"), False),
        Segment("━", Style.parse("yellow"), False),
        Segment("━", Style.parse("yellow"), False),
        Segment("━", Style.parse("yellow"), False),
        Segment("━", Style.parse("yellow"), False),
    ]
    assert segments == expected
Exemplo n.º 5
0
def test_update():
    bar = Bar()
    assert bar.completed == 0
    assert bar.total == 100
    bar.update(10, 20)
    assert bar.completed == 10
    assert bar.total == 20
    assert bar.percentage_completed == 50
    bar.update(100)
    assert bar.percentage_completed == 100
Exemplo n.º 6
0
def daily_xp(tdb: TaskDB):
    total = 10
    completed = tdb.filter(filters.completed_today)
    xp = completed.xp
    bar = Bar(
        total=total,
        completed=xp,
        width=30,
        style=style_bar.get("bg", style_default),
        complete_style=style_bar.get("complete", style_default),
        finished_style=style_bar.get("finished", style_default),
    )
    progress = Text(
        f" {xp}/{total}",
        style=style_bar.get("complete")
        if xp < total else style_bar.get("finished"),
    )
    print(bar, progress)
Exemplo n.º 7
0
    def _add(self, message, iterables=[], override=None):

        key = Text(message, overflow='ellipsis', no_wrap=True)
        busy = Text()

        if override is None:

            total = 1
            pulse = True

            try:
                total = len(iterables) if iterables != [] else 1
                pulse = iterables == []

            # Not all iterables have a length
            except TypeError:
                pass

            busy._text = ["→"]
            color = Style(color="rgb(161, 209, 255)", dim=True)
            value = Bar(total=total,
                        pulse=pulse,
                        complete_style=color,
                        finished_style=color,
                        pulse_style=color)
        else:
            value = override

        operation = Table(box=None,
                          show_header=False,
                          show_footer=False,
                          show_edge=True,
                          padding=(0, 0 if self.show_header else 1))

        operation.add_column(width=3 if self.show_header else 2,
                             justify="center")
        operation.add_column(width=62 if self.show_header else 60)
        operation.add_column()
        operation.add_row(busy, key, value)

        self.add_row(operation)
        return (key, value, busy)
Exemplo n.º 8
0
def test_init():
    bar = Bar(completed=50)
    repr(bar)
    assert bar.percentage_completed == 50.0
Exemplo n.º 9
0
def test_repr():
    bar = Bar(size=100, begin=11, end=62, width=50)
    assert repr(bar) == "Bar(100, 11, 62)"
Exemplo n.º 10
0
    assert bar_render == expected[1]
    # begin after end
    bar = Bar(size=100, begin=60, end=40, width=50)
    bar_render = render(bar)
    assert bar_render == expected[2]


def test_measure():
    bar = Bar(size=100, begin=11, end=62)
    measurement = bar.__rich_measure__(None, 120)
    assert measurement.minimum == 4
    assert measurement.maximum == 120


def test_zero_total():
    # Shouldn't throw zero division error
    bar = Bar(size=0, begin=0, end=0)
    render(bar)


if __name__ == "__main__":
    bar = Bar(size=100, begin=11, end=62, width=50)
    bar_render = render(bar)
    print(repr(bar_render))
    bar = Bar(size=100, begin=12, end=57, width=50)
    bar_render = render(bar)
    print(repr(bar_render))
    bar = Bar(size=100, begin=60, end=40, width=50)
    bar_render = render(bar)
    print(repr(bar_render))
Exemplo n.º 11
0
def test_measure():
    console = Console(width=120)
    bar = Bar(size=100, begin=11, end=62)
    measurement = bar.__rich_measure__(console, console.options)
    assert measurement.minimum == 4
    assert measurement.maximum == 120
Exemplo n.º 12
0
print(test)

import time

from rich.live import Live
from rich.table import Table

table = Table()
table.add_column("Row ID")
table.add_column("Description")
table.add_column("Level")

with Live(table,
          refresh_per_second=4):  # update 4 times a second to feel fluid
    for row in range(12):
        time.sleep(0.4)  # arbitrary delay
        # update the renderable internally
        table.add_row(f"{row}", f"description {row}", "[red]ERROR")

from rich.bar import Bar

console.print(Bar(5, 5, 5, color='red'))

import getch
# ...
char = getch.getch()  # User input, but not displayed on the screen
console.print(char)
# or
char = getch.getche()  # also displayed on the screen
console.print(char)
Exemplo n.º 13
0
"""

Use Bar to renderer a sort-of circle.

"""
import math

from rich.align import Align
from rich.bar import Bar
from rich.color import Color
from rich import print

SIZE = 40

for row in range(SIZE):
    y = (row / (SIZE - 1)) * 2 - 1
    x = math.sqrt(1 - y * y)
    color = Color.from_rgb((y + 1) * 127, 0, 0)
    bar = Bar(2, width=SIZE * 2, begin=1 - x, end=1 + x, color=color)
    print(Align.center(bar))
Exemplo n.º 14
0
def test_measure():
    bar = Bar(size=100, begin=11, end=62)
    measurement = bar.__rich_measure__(None, 120)
    assert measurement.minimum == 4
    assert measurement.maximum == 120
Exemplo n.º 15
0
def test_zero_total():
    # Shouldn't throw zero division error
    bar = Bar(total=0)
    render(bar)
Exemplo n.º 16
0
def test_measure():
    bar = Bar()
    measurement = bar.__measure__(None, 120)
    assert measurement.minimum == 4
    assert measurement.maximum == 120
Exemplo n.º 17
0
def test_render():
    bar = Bar(completed=11, width=50)
    bar_render = render(bar)
    assert bar_render == expected[0]
    bar.update(completed=12)
    bar_render = render(bar)
    assert bar_render == expected[1]


def test_measure():
    bar = Bar()
    measurement = bar.__measure__(None, 120)
    assert measurement.minimum == 4
    assert measurement.maximum == 120


def test_zero_total():
    # Shouldn't throw zero division error
    bar = Bar(total=0)
    render(bar)


if __name__ == "__main__":
    bar = Bar(completed=11, width=50)
    bar_render = render(bar)
    print(repr(bar_render))
    bar.update(completed=12)
    bar_render = render(bar)
    print(repr(bar_render))
Exemplo n.º 18
0
def test_pulse():
    bar = Bar(pulse=True, animation_time=10)
    bar_render = render(bar)
    print(repr(bar_render))
    expected = "\x1b[38;2;249;38;114m━\x1b[0m\x1b[38;2;244;38;112m━\x1b[0m\x1b[38;2;230;39;108m━\x1b[0m\x1b[38;2;209;42;102m━\x1b[0m\x1b[38;2;183;44;94m━\x1b[0m\x1b[38;2;153;48;86m━\x1b[0m\x1b[38;2;123;51;77m━\x1b[0m\x1b[38;2;97;53;69m━\x1b[0m\x1b[38;2;76;56;63m━\x1b[0m\x1b[38;2;62;57;59m━\x1b[0m\x1b[38;2;58;58;58m━\x1b[0m\x1b[38;2;62;57;59m━\x1b[0m\x1b[38;2;76;56;63m━\x1b[0m\x1b[38;2;97;53;69m━\x1b[0m\x1b[38;2;123;51;77m━\x1b[0m\x1b[38;2;153;48;86m━\x1b[0m\x1b[38;2;183;44;94m━\x1b[0m\x1b[38;2;209;42;102m━\x1b[0m\x1b[38;2;230;39;108m━\x1b[0m\x1b[38;2;244;38;112m━\x1b[0m\x1b[38;2;249;38;114m━\x1b[0m\x1b[38;2;244;38;112m━\x1b[0m\x1b[38;2;230;39;108m━\x1b[0m\x1b[38;2;209;42;102m━\x1b[0m\x1b[38;2;183;44;94m━\x1b[0m\x1b[38;2;153;48;86m━\x1b[0m\x1b[38;2;123;51;77m━\x1b[0m\x1b[38;2;97;53;69m━\x1b[0m\x1b[38;2;76;56;63m━\x1b[0m\x1b[38;2;62;57;59m━\x1b[0m\x1b[38;2;58;58;58m━\x1b[0m\x1b[38;2;62;57;59m━\x1b[0m\x1b[38;2;76;56;63m━\x1b[0m\x1b[38;2;97;53;69m━\x1b[0m\x1b[38;2;123;51;77m━\x1b[0m\x1b[38;2;153;48;86m━\x1b[0m\x1b[38;2;183;44;94m━\x1b[0m\x1b[38;2;209;42;102m━\x1b[0m\x1b[38;2;230;39;108m━\x1b[0m\x1b[38;2;244;38;112m━\x1b[0m\x1b[38;2;249;38;114m━\x1b[0m\x1b[38;2;244;38;112m━\x1b[0m\x1b[38;2;230;39;108m━\x1b[0m\x1b[38;2;209;42;102m━\x1b[0m\x1b[38;2;183;44;94m━\x1b[0m\x1b[38;2;153;48;86m━\x1b[0m\x1b[38;2;123;51;77m━\x1b[0m\x1b[38;2;97;53;69m━\x1b[0m\x1b[38;2;76;56;63m━\x1b[0m\x1b[38;2;62;57;59m━\x1b[0m\x1b[38;2;58;58;58m━\x1b[0m\x1b[38;2;62;57;59m━\x1b[0m\x1b[38;2;76;56;63m━\x1b[0m\x1b[38;2;97;53;69m━\x1b[0m\x1b[38;2;123;51;77m━\x1b[0m\x1b[38;2;153;48;86m━\x1b[0m\x1b[38;2;183;44;94m━\x1b[0m\x1b[38;2;209;42;102m━\x1b[0m\x1b[38;2;230;39;108m━\x1b[0m\x1b[38;2;244;38;112m━\x1b[0m\x1b[38;2;249;38;114m━\x1b[0m\x1b[38;2;244;38;112m━\x1b[0m\x1b[38;2;230;39;108m━\x1b[0m\x1b[38;2;209;42;102m━\x1b[0m\x1b[38;2;183;44;94m━\x1b[0m\x1b[38;2;153;48;86m━\x1b[0m\x1b[38;2;123;51;77m━\x1b[0m\x1b[38;2;97;53;69m━\x1b[0m\x1b[38;2;76;56;63m━\x1b[0m\x1b[38;2;62;57;59m━\x1b[0m\x1b[38;2;58;58;58m━\x1b[0m\x1b[38;2;62;57;59m━\x1b[0m\x1b[38;2;76;56;63m━\x1b[0m\x1b[38;2;97;53;69m━\x1b[0m\x1b[38;2;123;51;77m━\x1b[0m\x1b[38;2;153;48;86m━\x1b[0m\x1b[38;2;183;44;94m━\x1b[0m\x1b[38;2;209;42;102m━\x1b[0m\x1b[38;2;230;39;108m━\x1b[0m\x1b[38;2;244;38;112m━\x1b[0m\x1b[38;2;249;38;114m━\x1b[0m\x1b[38;2;244;38;112m━\x1b[0m\x1b[38;2;230;39;108m━\x1b[0m\x1b[38;2;209;42;102m━\x1b[0m\x1b[38;2;183;44;94m━\x1b[0m\x1b[38;2;153;48;86m━\x1b[0m\x1b[38;2;123;51;77m━\x1b[0m\x1b[38;2;97;53;69m━\x1b[0m\x1b[38;2;76;56;63m━\x1b[0m\x1b[38;2;62;57;59m━\x1b[0m\x1b[38;2;58;58;58m━\x1b[0m\x1b[38;2;62;57;59m━\x1b[0m\x1b[38;2;76;56;63m━\x1b[0m\x1b[38;2;97;53;69m━\x1b[0m\x1b[38;2;123;51;77m━\x1b[0m\x1b[38;2;153;48;86m━\x1b[0m\x1b[38;2;183;44;94m━\x1b[0m\x1b[38;2;209;42;102m━\x1b[0m\x1b[38;2;230;39;108m━\x1b[0m\x1b[38;2;244;38;112m━\x1b[0m"
    assert bar_render == expected
Exemplo n.º 19
0
def test_zero_total():
    # Shouldn't throw zero division error
    bar = Bar(size=0, begin=0, end=0)
    render(bar)
Exemplo n.º 20
0
"""

Use Bar to renderer a sort-of cirlce.

"""
import math

from rich.bar import Bar
from rich.color import Color
from rich import print

SIZE = 40

for row in range(SIZE):
    y = (row / SIZE) * 2 - 1
    x = math.sqrt(1 - y * y)
    color = Color.from_rgb((y + 1) * 127, 0, 0)
    bar = Bar(1, width=SIZE * 2, begin=1 - x, end=x, color=color)
    print(bar)