mirror of https://github.com/Textualize/rich.git
print exports to terminal
This commit is contained in:
parent
8943924d00
commit
5dddadb983
|
@ -20,16 +20,18 @@ def print_table():
|
|||
table.add_row("Dec 15, 2017", "Star Wars Ep. V111: The Last Jedi", "$1,332,539,889")
|
||||
table.add_row("Dec 16, 2016", "Rogue One: A Star Wars Story", "$1,332,439,889")
|
||||
|
||||
console.print(table, justify="center")
|
||||
console.print(table)
|
||||
|
||||
|
||||
# Prints table
|
||||
print_table()
|
||||
|
||||
# Get console output as text
|
||||
file1 = "table_export_plaintext.txt"
|
||||
text = console.export_text()
|
||||
with open("plaintext_export.txt", "w") as file:
|
||||
with open(file1, "w") as file:
|
||||
file.write(text)
|
||||
print(f"Exported console output as plain text to {file1}")
|
||||
|
||||
# Calling print_table again because console output buffer
|
||||
# is flushed once export function is called
|
||||
|
@ -37,12 +39,18 @@ print_table()
|
|||
|
||||
# Get console output as html
|
||||
# use clear=False so output is not flushed after export
|
||||
file2 = "table_export_html.html"
|
||||
html = console.export_html(clear=False)
|
||||
with open("html_export.html", "w") as file:
|
||||
with open(file2, "w") as file:
|
||||
file.write(html)
|
||||
print(f"Exported console output as html to {file2}")
|
||||
|
||||
# Export text output to table_export.txt
|
||||
console.save_text("rich_export.txt", clear=False)
|
||||
file3 = "table_export_plaintext2.txt"
|
||||
console.save_text(file3, clear=False)
|
||||
print(f"Exported console output as plain text to {file3}")
|
||||
|
||||
# Export html output to table_export.html
|
||||
console.save_html("rich_export.html")
|
||||
file4 = "table_export_html2.html"
|
||||
console.save_html(file4)
|
||||
print(f"Exported console output as html to {file4}")
|
||||
|
|
Loading…
Reference in New Issue