mirror of https://github.com/Textualize/rich.git
tidy example
This commit is contained in:
parent
cec4262a57
commit
d28780b716
|
@ -3,7 +3,7 @@ Columns
|
|||
|
||||
Rich can render text or other Rich renderables in neat columns with the :class:`~rich.columns.Columns` class. To use, construct a Columns instance with an iterable of renderables and print it to the Console.
|
||||
|
||||
The following example is a very basic clone of the `ls` command in OSX / Linux to list directory contents::
|
||||
The following example is a very basic clone of the ``ls`` command in OSX / Linux to list directory contents::
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
from rich import print
|
||||
from rich.columns import Columns
|
||||
from rich.panel import Panel
|
||||
|
||||
import json
|
||||
from urllib.request import urlopen
|
||||
|
||||
|
||||
from rich import print
|
||||
from rich.columns import Columns
|
||||
from rich.panel import Panel
|
||||
|
||||
users = json.loads(urlopen("https://randomuser.me/api/?results=30").read())["results"]
|
||||
print(users)
|
||||
|
||||
|
@ -13,10 +13,8 @@ print(users)
|
|||
def get_content(user):
|
||||
country = user["location"]["country"]
|
||||
name = f"{user['name']['first']} {user['name']['last']}"
|
||||
|
||||
return f"[b]{name}[/b]\n[yellow]{country}"
|
||||
|
||||
|
||||
user_renderables = [Panel(get_content(user), expand=False,) for user in users]
|
||||
|
||||
user_renderables = [Panel(get_content(user), expand=False) for user in users]
|
||||
print(Columns(user_renderables))
|
||||
|
|
Loading…
Reference in New Issue