def test_refresh_screen(): layout = Layout() layout.split_row(Layout(name="foo"), Layout(name="bar")) console = Console(force_terminal=True, width=20, height=5) console.print(layout) with console.screen(): with console.capture() as capture: layout.refresh_screen(console, "foo") result = capture.get() print(repr(result)) expected = "\x1b[1;1H\x1b[34m╭─\x1b[0m\x1b[34m \x1b[0m\x1b[32m'foo'\x1b[0m\x1b[34m─╮\x1b[0m\x1b[2;1H\x1b[34m│\x1b[0m Layout \x1b[34m│\x1b[0m\x1b[3;1H\x1b[34m│\x1b[0m \x1b[1m(\x1b[0m \x1b[34m│\x1b[0m\x1b[4;1H\x1b[34m│\x1b[0m \x1b[33mna\x1b[0m \x1b[34m│\x1b[0m\x1b[5;1H\x1b[34m╰────────╯\x1b[0m" assert result == expected
""" Demonstration of Console.screen() """ from time import sleep from rich.align import Align from rich.console import Console from rich.panel import Panel console = Console() with console.screen(style="bold white on red") as screen: text = Align.center("[blink]Don't Panic![/blink]", vertical="middle") screen.update(Panel(text)) sleep(5)
def display_products() -> None: """ GUI helper to display the variety of products that are available in the footer layout. """ product_range: str = "" for count, product in enumerate(settings.CLIENT_PRODUCT_CODES): product_range = "".join((product_range, f"{count + 1}-{product} ")) layout["footer"].update( gui.Status(Text("".join(("Available Products: ", product_range)), style="warning")) ) if __name__ == "__main__": with console.screen() as screen: while True: screen.update(layout) option = IntPrompt.ask("Select an option: ", choices=[f"{i + 1}" for i in range(5)]) if option == 1: create_cart() elif option == 2: screen.update(layout) cart_selection = IntPrompt.ask( "Select a cart: ", choices=[f"{i + 1}" for i in range(len(cart_ids))] ) select_cart(cart_selection) elif option == 3:
from rich.color import ANSI_COLOR_NAMES console = Console() # inspect(console) # sys.exit(0) grid = Table.grid() # colors = ["red", "green", "blue"] colors = list(ANSI_COLOR_NAMES) grid.add_column() grid.add_column() grid.add_column() grid.add_row("[red]r[/]", "[blue]b[/]", "[green]g[/]") grid.add_row("[green]g[/]", "[red]r[/]", "[blue]b[/]") inspect(grid, methods=True) sys.exit(0) with console.screen(): for _ in range(console.width): grid.add_column() for i in range(console.height - 1): random.seed(i) random.shuffle(colors) color = cycle(colors) cells = [] for j in range(len(grid.columns)): # cells.append(f"[white on {next(color)}] [/]") cells.append(f"[white on {random.choice(colors)}] [/]") grid.add_row(*cells) print(grid, end="") sleep(5)