From 92e1b7ac7026142aeec36ff2f54ffd7c2875c8d2 Mon Sep 17 00:00:00 2001 From: toto6038 <50100922+toto6038@users.noreply.github.com> Date: Tue, 18 Jan 2022 03:57:27 +0800 Subject: [PATCH 01/15] Rename `README.cn.md`, and apply link change --- README.de-ch.md | 3 ++- README.de.md | 3 ++- README.es.md | 3 ++- README.fr.md | 3 ++- README.hi.md | 3 ++- README.it.md | 3 ++- README.ja.md | 3 ++- README.kr.md | 3 ++- README.pt-br.md | 3 ++- README.ru.md | 3 ++- README.sv.md | 3 ++- README.cn.md => README.zh-cn.md | 3 ++- 12 files changed, 24 insertions(+), 12 deletions(-) rename README.cn.md => README.zh-cn.md (98%) diff --git a/README.de-ch.md b/README.de-ch.md index e96575322..4d6359ff5 100644 --- a/README.de-ch.md +++ b/README.de-ch.md @@ -7,7 +7,8 @@ ![Logo](https://github.com/willmcgugan/rich/raw/master/imgs/logo.svg) [English readme](https://github.com/willmcgugan/rich/blob/master/README.md) - • [中文 readme](https://github.com/willmcgugan/rich/blob/master/README.cn.md) + • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-cn.md) + • [正體中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-tw.md) • [Lengua española readme](https://github.com/willmcgugan/rich/blob/master/README.es.md) • [Deutsche readme](https://github.com/willmcgugan/rich/blob/master/README.de.md) • [Läs på svenska](https://github.com/willmcgugan/rich/blob/master/README.sv.md) diff --git a/README.de.md b/README.de.md index 38cf845d7..148f146f2 100644 --- a/README.de.md +++ b/README.de.md @@ -7,7 +7,8 @@ ![Logo](https://github.com/willmcgugan/rich/raw/master/imgs/logo.svg) [English readme](https://github.com/willmcgugan/rich/blob/master/README.md) - • [中文 readme](https://github.com/willmcgugan/rich/blob/master/README.cn.md) + • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-cn.md) + • [正體中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-tw.md) • [Lengua española readme](https://github.com/willmcgugan/rich/blob/master/README.es.md) • [Deutsche readme](https://github.com/willmcgugan/rich/blob/master/README.de.md) • [Läs på svenska](https://github.com/willmcgugan/rich/blob/master/README.sv.md) diff --git a/README.es.md b/README.es.md index a3aa631ca..ec4e4f425 100644 --- a/README.es.md +++ b/README.es.md @@ -7,7 +7,8 @@ ![Logo](https://github.com/willmcgugan/rich/raw/master/imgs/logo.svg) [English readme](https://github.com/willmcgugan/rich/blob/master/README.md) - • [中文 readme](https://github.com/willmcgugan/rich/blob/master/README.cn.md) + • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-cn.md) + • [正體中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-tw.md) • [Lengua española readme](https://github.com/willmcgugan/rich/blob/master/README.es.md) • [Deutsche readme](https://github.com/willmcgugan/rich/blob/master/README.de.md) • [Läs på svenska](https://github.com/willmcgugan/rich/blob/master/README.sv.md) diff --git a/README.fr.md b/README.fr.md index 394f03bf8..0fbea94fc 100644 --- a/README.fr.md +++ b/README.fr.md @@ -7,7 +7,8 @@ ![Logo](https://github.com/willmcgugan/rich/raw/master/imgs/logo.svg) [English readme](https://github.com/willmcgugan/rich/blob/master/README.md) - • [中文 readme](https://github.com/willmcgugan/rich/blob/master/README.cn.md) + • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-cn.md) + • [正體中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-tw.md) • [Lengua española readme](https://github.com/willmcgugan/rich/blob/master/README.es.md) • [Deutsche readme](https://github.com/willmcgugan/rich/blob/master/README.de.md) • [Läs på svenska](https://github.com/willmcgugan/rich/blob/master/README.sv.md) diff --git a/README.hi.md b/README.hi.md index 9c3009f4f..443472c5c 100644 --- a/README.hi.md +++ b/README.hi.md @@ -7,7 +7,8 @@ ![Logo](https://github.com/willmcgugan/rich/raw/master/imgs/logo.svg) [English readme](https://github.com/willmcgugan/rich/blob/master/README.md) - • [中文 readme](https://github.com/willmcgugan/rich/blob/master/README.cn.md) + • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-cn.md) + • [正體中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-tw.md) • [Lengua española readme](https://github.com/willmcgugan/rich/blob/master/README.es.md) • [Deutsche readme](https://github.com/willmcgugan/rich/blob/master/README.de.md) • [Läs på svenska](https://github.com/willmcgugan/rich/blob/master/README.sv.md) diff --git a/README.it.md b/README.it.md index 7d0b68d71..cf2e2c5fe 100644 --- a/README.it.md +++ b/README.it.md @@ -6,7 +6,8 @@ ![Logo](https://github.com/willmcgugan/rich/raw/master/imgs/logo.svg) [English readme](https://github.com/willmcgugan/rich/blob/master/README.md) - • [中文 readme](https://github.com/willmcgugan/rich/blob/master/README.cn.md) + • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-cn.md) + • [正體中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-tw.md) • [Lengua española readme](https://github.com/willmcgugan/rich/blob/master/README.es.md) • [Deutsche readme](https://github.com/willmcgugan/rich/blob/master/README.de.md) • [Läs på svenska](https://github.com/willmcgugan/rich/blob/master/README.sv.md) diff --git a/README.ja.md b/README.ja.md index 1bec48459..0429d1150 100644 --- a/README.ja.md +++ b/README.ja.md @@ -7,7 +7,8 @@ ![Logo](https://github.com/willmcgugan/rich/raw/master/imgs/logo.svg) [English readme](https://github.com/willmcgugan/rich/blob/master/README.md) - • [中文 readme](https://github.com/willmcgugan/rich/blob/master/README.cn.md) + • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-cn.md) + • [正體中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-tw.md) • [Lengua española readme](https://github.com/willmcgugan/rich/blob/master/README.es.md) • [Deutsche readme](https://github.com/willmcgugan/rich/blob/master/README.de.md) • [Läs på svenska](https://github.com/willmcgugan/rich/blob/master/README.sv.md) diff --git a/README.kr.md b/README.kr.md index a1a67ea95..e3aa03134 100644 --- a/README.kr.md +++ b/README.kr.md @@ -7,7 +7,8 @@ ![Logo](https://github.com/willmcgugan/rich/raw/master/imgs/logo.svg) [English readme](https://github.com/willmcgugan/rich/blob/master/README.md) - • [中文 readme](https://github.com/willmcgugan/rich/blob/master/README.cn.md) + • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-cn.md) + • [正體中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-tw.md) • [Lengua española readme](https://github.com/willmcgugan/rich/blob/master/README.es.md) • [Deutsche readme](https://github.com/willmcgugan/rich/blob/master/README.de.md) • [Läs på svenska](https://github.com/willmcgugan/rich/blob/master/README.sv.md) diff --git a/README.pt-br.md b/README.pt-br.md index c2294502e..3d888ee44 100644 --- a/README.pt-br.md +++ b/README.pt-br.md @@ -7,7 +7,8 @@ ![Logo](https://github.com/willmcgugan/rich/raw/master/imgs/logo.svg) [English readme](https://github.com/willmcgugan/rich/blob/master/README.md) - • [中文 readme](https://github.com/willmcgugan/rich/blob/master/README.cn.md) + • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-cn.md) + • [正體中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-tw.md) • [Lengua española readme](https://github.com/willmcgugan/rich/blob/master/README.es.md) • [Deutsche readme](https://github.com/willmcgugan/rich/blob/master/README.de.md) • [Läs på svenska](https://github.com/willmcgugan/rich/blob/master/README.sv.md) diff --git a/README.ru.md b/README.ru.md index 4223309d9..d9a02c21c 100644 --- a/README.ru.md +++ b/README.ru.md @@ -8,7 +8,8 @@ ![Logo](https://github.com/willmcgugan/rich/raw/master/imgs/logo.svg) [English readme](https://github.com/willmcgugan/rich/blob/master/README.md) - • [中文 readme](https://github.com/willmcgugan/rich/blob/master/README.cn.md) + • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-cn.md) + • [正體中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-tw.md) • [Lengua española readme](https://github.com/willmcgugan/rich/blob/master/README.es.md) • [Deutsche readme](https://github.com/willmcgugan/rich/blob/master/README.de.md) • [Läs på svenska](https://github.com/willmcgugan/rich/blob/master/README.sv.md) diff --git a/README.sv.md b/README.sv.md index 35b266979..b630b3e7f 100644 --- a/README.sv.md +++ b/README.sv.md @@ -7,7 +7,8 @@ ![Logo](https://github.com/willmcgugan/rich/raw/master/imgs/logo.svg) [English readme](https://github.com/willmcgugan/rich/blob/master/README.md) - • [中文 readme](https://github.com/willmcgugan/rich/blob/master/README.cn.md) + • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-cn.md) + • [正體中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-tw.md) • [Lengua española readme](https://github.com/willmcgugan/rich/blob/master/README.es.md) • [Deutsche readme](https://github.com/willmcgugan/rich/blob/master/README.de.md) • [Läs på svenska](https://github.com/willmcgugan/rich/blob/master/README.sv.md) diff --git a/README.cn.md b/README.zh-cn.md similarity index 98% rename from README.cn.md rename to README.zh-cn.md index 3fc571cd7..97f099634 100644 --- a/README.cn.md +++ b/README.zh-cn.md @@ -7,7 +7,8 @@ ![Logo](https://github.com/willmcgugan/rich/raw/master/imgs/logo.svg) [English readme](https://github.com/willmcgugan/rich/blob/master/README.md) - • [中文 readme](https://github.com/willmcgugan/rich/blob/master/README.cn.md) + • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-cn.md) + • [正體中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-tw.md) • [Lengua española readme](https://github.com/willmcgugan/rich/blob/master/README.es.md) • [Deutsche readme](https://github.com/willmcgugan/rich/blob/master/README.de.md) • [Läs på svenska](https://github.com/willmcgugan/rich/blob/master/README.sv.md) From 506432672b0ad481db18de3b2c8cb9c0fbb69827 Mon Sep 17 00:00:00 2001 From: toto6038 <50100922+toto6038@users.noreply.github.com> Date: Tue, 18 Jan 2022 03:58:06 +0800 Subject: [PATCH 02/15] Add `README.zh-tw.md` --- README.zh-tw.md | 457 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 457 insertions(+) create mode 100644 README.zh-tw.md diff --git a/README.zh-tw.md b/README.zh-tw.md new file mode 100644 index 000000000..189b1fada --- /dev/null +++ b/README.zh-tw.md @@ -0,0 +1,457 @@ +[![Downloads](https://pepy.tech/badge/rich/month)](https://pepy.tech/project/rich) +[![PyPI version](https://badge.fury.io/py/rich.svg)](https://badge.fury.io/py/rich) +[![codecov](https://codecov.io/gh/willmcgugan/rich/branch/master/graph/badge.svg)](https://codecov.io/gh/willmcgugan/rich) +[![Rich blog](https://img.shields.io/badge/blog-rich%20news-yellowgreen)](https://www.willmcgugan.com/tag/rich/) +[![Twitter Follow](https://img.shields.io/twitter/follow/willmcgugan.svg?style=social)](https://twitter.com/willmcgugan) + +![Logo](https://github.com/willmcgugan/rich/raw/master/imgs/logo.svg) + +[English readme](https://github.com/willmcgugan/rich/blob/master/README.md) + • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-cn.md) + • [正體中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-tw.md) + • [Lengua española readme](https://github.com/willmcgugan/rich/blob/master/README.es.md) + • [Deutsche readme](https://github.com/willmcgugan/rich/blob/master/README.de.md) + • [Läs på svenska](https://github.com/willmcgugan/rich/blob/master/README.sv.md) + • [日本語 readme](https://github.com/willmcgugan/rich/blob/master/README.ja.md) + • [한국어 readme](https://github.com/willmcgugan/rich/blob/master/README.kr.md) + • [Français readme](https://github.com/willmcgugan/rich/blob/master/README.fr.md) + • [Schwizerdütsch readme](https://github.com/willmcgugan/rich/blob/master/README.de-ch.md) + • [हिन्दी readme](https://github.com/willmcgugan/rich/blob/master/README.hi.md) + • [Português brasileiro readme](https://github.com/willmcgugan/rich/blob/master/README.pt-br.md) + • [Italian readme](https://github.com/willmcgugan/rich/blob/master/README.it.md) + • [Русский readme](https://github.com/willmcgugan/rich/blob/master/README.ru.md) + +Rich is a Python library for _rich_ text and beautiful formatting in the terminal. + +The [Rich API](https://rich.readthedocs.io/en/latest/) makes it easy to add color and style to terminal output. Rich can also render pretty tables, progress bars, markdown, syntax highlighted source code, tracebacks, and more — out of the box. + +![Features](https://github.com/willmcgugan/rich/raw/master/imgs/features.png) + +For a video introduction to Rich see [calmcode.io](https://calmcode.io/rich/introduction.html) by [@fishnets88](https://twitter.com/fishnets88). + +See what [people are saying about Rich](https://www.willmcgugan.com/blog/pages/post/rich-tweets/). + +## Compatibility + +Rich works with Linux, OSX, and Windows. True color / emoji works with new Windows Terminal, classic terminal is limited to 16 colors. Rich requires Python 3.6.1 or later. + +Rich works with [Jupyter notebooks](https://jupyter.org/) with no additional configuration required. + +## Installing + +Install with `pip` or your favorite PyPI package manager. + +```sh +python -m pip install rich +``` + +Run the following to test Rich output on your terminal: + +```sh +python -m rich +``` + +## Rich Print + +To effortlessly add rich output to your application, you can import the [rich print](https://rich.readthedocs.io/en/latest/introduction.html#quick-start) method, which has the same signature as the builtin Python function. Try this: + +```python +from rich import print + +print("Hello, [bold magenta]World[/bold magenta]!", ":vampire:", locals()) +``` + +![Hello World](https://github.com/willmcgugan/rich/raw/master/imgs/print.png) + +## Rich REPL + +Rich can be installed in the Python REPL, so that any data structures will be pretty printed and highlighted. + +```python +>>> from rich import pretty +>>> pretty.install() +``` + +![REPL](https://github.com/willmcgugan/rich/raw/master/imgs/repl.png) + +## Using the Console + +For more control over rich terminal content, import and construct a [Console](https://rich.readthedocs.io/en/latest/reference/console.html#rich.console.Console) object. + +```python +from rich.console import Console + +console = Console() +``` + +The Console object has a `print` method which has an intentionally similar interface to the builtin `print` function. Here's an example of use: + +```python +console.print("Hello", "World!") +``` + +As you might expect, this will print `"Hello World!"` to the terminal. Note that unlike the builtin `print` function, Rich will word-wrap your text to fit within the terminal width. + +There are a few ways of adding color and style to your output. You can set a style for the entire output by adding a `style` keyword argument. Here's an example: + +```python +console.print("Hello", "World!", style="bold red") +``` + +The output will be something like the following: + +![Hello World](https://github.com/willmcgugan/rich/raw/master/imgs/hello_world.png) + +That's fine for styling a line of text at a time. For more finely grained styling, Rich renders a special markup which is similar in syntax to [bbcode](https://en.wikipedia.org/wiki/BBCode). Here's an example: + +```python +console.print("Where there is a [bold cyan]Will[/bold cyan] there [u]is[/u] a [i]way[/i].") +``` + +![Console Markup](https://github.com/willmcgugan/rich/raw/master/imgs/where_there_is_a_will.png) + +You can use a Console object to generate sophisticated output with minimal effort. See the [Console API](https://rich.readthedocs.io/en/latest/console.html) docs for details. + +## Rich Inspect + +Rich has an [inspect](https://rich.readthedocs.io/en/latest/reference/init.html?highlight=inspect#rich.inspect) function which can produce a report on any Python object, such as class, instance, or builtin. + +```python +>>> my_list = ["foo", "bar"] +>>> from rich import inspect +>>> inspect(my_list, methods=True) +``` + +![Log](https://github.com/willmcgugan/rich/raw/master/imgs/inspect.png) + +See the [inspect docs](https://rich.readthedocs.io/en/latest/reference/init.html#rich.inspect) for details. + +# Rich Library + +Rich contains a number of builtin _renderables_ you can use to create elegant output in your CLI and help you debug your code. + +Click the following headings for details: + +
+Log + +The Console object has a `log()` method which has a similar interface to `print()`, but also renders a column for the current time and the file and line which made the call. By default Rich will do syntax highlighting for Python structures and for repr strings. If you log a collection (i.e. a dict or a list) Rich will pretty print it so that it fits in the available space. Here's an example of some of these features. + +```python +from rich.console import Console +console = Console() + +test_data = [ + {"jsonrpc": "2.0", "method": "sum", "params": [None, 1, 2, 4, False, True], "id": "1",}, + {"jsonrpc": "2.0", "method": "notify_hello", "params": [7]}, + {"jsonrpc": "2.0", "method": "subtract", "params": [42, 23], "id": "2"}, +] + +def test_log(): + enabled = False + context = { + "foo": "bar", + } + movies = ["Deadpool", "Rise of the Skywalker"] + console.log("Hello from", console, "!") + console.log(test_data, log_locals=True) + + +test_log() +``` + +The above produces the following output: + +![Log](https://github.com/willmcgugan/rich/raw/master/imgs/log.png) + +Note the `log_locals` argument, which outputs a table containing the local variables where the log method was called. + +The log method could be used for logging to the terminal for long running applications such as servers, but is also a very nice debugging aid. + +
+
+Logging Handler + +You can also use the builtin [Handler class](https://rich.readthedocs.io/en/latest/logging.html) to format and colorize output from Python's logging module. Here's an example of the output: + +![Logging](https://github.com/willmcgugan/rich/raw/master/imgs/logging.png) + +
+ +
+Emoji + +To insert an emoji in to console output place the name between two colons. Here's an example: + +```python +>>> console.print(":smiley: :vampire: :pile_of_poo: :thumbs_up: :raccoon:") +😃 🧛 💩 👍 🦝 +``` + +Please use this feature wisely. + +
+ +
+Tables + +Rich can render flexible [tables](https://rich.readthedocs.io/en/latest/tables.html) with unicode box characters. There is a large variety of formatting options for borders, styles, cell alignment etc. + +![table movie](https://github.com/willmcgugan/rich/raw/master/imgs/table_movie.gif) + +The animation above was generated with [table_movie.py](https://github.com/willmcgugan/rich/blob/master/examples/table_movie.py) in the examples directory. + +Here's a simpler table example: + +```python +from rich.console import Console +from rich.table import Table + +console = Console() + +table = Table(show_header=True, header_style="bold magenta") +table.add_column("Date", style="dim", width=12) +table.add_column("Title") +table.add_column("Production Budget", justify="right") +table.add_column("Box Office", justify="right") +table.add_row( + "Dec 20, 2019", "Star Wars: The Rise of Skywalker", "$275,000,000", "$375,126,118" +) +table.add_row( + "May 25, 2018", + "[red]Solo[/red]: A Star Wars Story", + "$275,000,000", + "$393,151,347", +) +table.add_row( + "Dec 15, 2017", + "Star Wars Ep. VIII: The Last Jedi", + "$262,000,000", + "[bold]$1,332,539,889[/bold]", +) + +console.print(table) +``` + +This produces the following output: + +![table](https://github.com/willmcgugan/rich/raw/master/imgs/table.png) + +Note that console markup is rendered in the same way as `print()` and `log()`. In fact, anything that is renderable by Rich may be included in the headers / rows (even other tables). + +The `Table` class is smart enough to resize columns to fit the available width of the terminal, wrapping text as required. Here's the same example, with the terminal made smaller than the table above: + +![table2](https://github.com/willmcgugan/rich/raw/master/imgs/table2.png) + +
+ +
+Progress Bars + +Rich can render multiple flicker-free [progress](https://rich.readthedocs.io/en/latest/progress.html) bars to track long-running tasks. + +For basic usage, wrap any sequence in the `track` function and iterate over the result. Here's an example: + +```python +from rich.progress import track + +for step in track(range(100)): + do_step(step) +``` + +It's not much harder to add multiple progress bars. Here's an example taken from the docs: + +![progress](https://github.com/willmcgugan/rich/raw/master/imgs/progress.gif) + +The columns may be configured to show any details you want. Built-in columns include percentage complete, file size, file speed, and time remaining. Here's another example showing a download in progress: + +![progress](https://github.com/willmcgugan/rich/raw/master/imgs/downloader.gif) + +To try this out yourself, see [examples/downloader.py](https://github.com/willmcgugan/rich/blob/master/examples/downloader.py) which can download multiple URLs simultaneously while displaying progress. + +
+ +
+Status + +For situations where it is hard to calculate progress, you can use the [status](https://rich.readthedocs.io/en/latest/reference/console.html#rich.console.Console.status) method which will display a 'spinner' animation and message. The animation won't prevent you from using the console as normal. Here's an example: + +```python +from time import sleep +from rich.console import Console + +console = Console() +tasks = [f"task {n}" for n in range(1, 11)] + +with console.status("[bold green]Working on tasks...") as status: + while tasks: + task = tasks.pop(0) + sleep(1) + console.log(f"{task} complete") +``` + +This generates the following output in the terminal. + +![status](https://github.com/willmcgugan/rich/raw/master/imgs/status.gif) + +The spinner animations were borrowed from [cli-spinners](https://www.npmjs.com/package/cli-spinners). You can select a spinner by specifying the `spinner` parameter. Run the following command to see the available values: + +``` +python -m rich.spinner +``` + +The above command generates the following output in the terminal: + +![spinners](https://github.com/willmcgugan/rich/raw/master/imgs/spinners.gif) + +
+ +
+Tree + +Rich can render a [tree](https://rich.readthedocs.io/en/latest/tree.html) with guide lines. A tree is ideal for displaying a file structure, or any other hierarchical data. + +The labels of the tree can be simple text or anything else Rich can render. Run the following for a demonstration: + +``` +python -m rich.tree +``` + +This generates the following output: + +![markdown](https://github.com/willmcgugan/rich/raw/master/imgs/tree.png) + +See the [tree.py](https://github.com/willmcgugan/rich/blob/master/examples/tree.py) example for a script that displays a tree view of any directory, similar to the linux `tree` command. + +
+ +
+Columns + +Rich can render content in neat [columns](https://rich.readthedocs.io/en/latest/columns.html) with equal or optimal width. Here's a very basic clone of the (MacOS / Linux) `ls` command which displays a directory listing in columns: + +```python +import os +import sys + +from rich import print +from rich.columns import Columns + +directory = os.listdir(sys.argv[1]) +print(Columns(directory)) +``` + +The following screenshot is the output from the [columns example](https://github.com/willmcgugan/rich/blob/master/examples/columns.py) which displays data pulled from an API in columns: + +![columns](https://github.com/willmcgugan/rich/raw/master/imgs/columns.png) + +
+ +
+Markdown + +Rich can render [markdown](https://rich.readthedocs.io/en/latest/markdown.html) and does a reasonable job of translating the formatting to the terminal. + +To render markdown import the `Markdown` class and construct it with a string containing markdown code. Then print it to the console. Here's an example: + +```python +from rich.console import Console +from rich.markdown import Markdown + +console = Console() +with open("README.md") as readme: + markdown = Markdown(readme.read()) +console.print(markdown) +``` + +This will produce output something like the following: + +![markdown](https://github.com/willmcgugan/rich/raw/master/imgs/markdown.png) + +
+ +
+Syntax Highlighting + +Rich uses the [pygments](https://pygments.org/) library to implement [syntax highlighting](https://rich.readthedocs.io/en/latest/syntax.html). Usage is similar to rendering markdown; construct a `Syntax` object and print it to the console. Here's an example: + +```python +from rich.console import Console +from rich.syntax import Syntax + +my_code = ''' +def iter_first_last(values: Iterable[T]) -> Iterable[Tuple[bool, bool, T]]: + """Iterate and generate a tuple with a flag for first and last value.""" + iter_values = iter(values) + try: + previous_value = next(iter_values) + except StopIteration: + return + first = True + for value in iter_values: + yield first, False, previous_value + first = False + previous_value = value + yield first, True, previous_value +''' +syntax = Syntax(my_code, "python", theme="monokai", line_numbers=True) +console = Console() +console.print(syntax) +``` + +This will produce the following output: + +![syntax](https://github.com/willmcgugan/rich/raw/master/imgs/syntax.png) + +
+ +
+Tracebacks + +Rich can render [beautiful tracebacks](https://rich.readthedocs.io/en/latest/traceback.html) which are easier to read and show more code than standard Python tracebacks. You can set Rich as the default traceback handler so all uncaught exceptions will be rendered by Rich. + +Here's what it looks like on OSX (similar on Linux): + +![traceback](https://github.com/willmcgugan/rich/raw/master/imgs/traceback.png) + +
+ +All Rich renderables make use of the [Console Protocol](https://rich.readthedocs.io/en/latest/protocol.html), which you can also use to implement your own Rich content. + +# Rich for enterprise + +Available as part of the Tidelift Subscription. + +The maintainers of Rich and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source packages you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact packages you use. [Learn more.](https://tidelift.com/subscription/pkg/pypi-rich?utm_source=pypi-rich&utm_medium=referral&utm_campaign=enterprise&utm_term=repo) + +# Projects using Rich + +Here are a few projects using Rich: + +- [BrancoLab/BrainRender](https://github.com/BrancoLab/BrainRender) + a python package for the visualization of three dimensional neuro-anatomical data +- [Ciphey/Ciphey](https://github.com/Ciphey/Ciphey) + Automated decryption tool +- [emeryberger/scalene](https://github.com/emeryberger/scalene) + a high-performance, high-precision CPU and memory profiler for Python +- [hedythedev/StarCli](https://github.com/hedythedev/starcli) + Browse GitHub trending projects from your command line +- [intel/cve-bin-tool](https://github.com/intel/cve-bin-tool) + This tool scans for a number of common, vulnerable components (openssl, libpng, libxml2, expat and a few others) to let you know if your system includes common libraries with known vulnerabilities. +- [nf-core/tools](https://github.com/nf-core/tools) + Python package with helper tools for the nf-core community. +- [cansarigol/pdbr](https://github.com/cansarigol/pdbr) + pdb + Rich library for enhanced debugging +- [plant99/felicette](https://github.com/plant99/felicette) + Satellite imagery for dummies. +- [seleniumbase/SeleniumBase](https://github.com/seleniumbase/SeleniumBase) + Automate & test 10x faster with Selenium & pytest. Batteries included. +- [smacke/ffsubsync](https://github.com/smacke/ffsubsync) + Automagically synchronize subtitles with video. +- [tryolabs/norfair](https://github.com/tryolabs/norfair) + Lightweight Python library for adding real-time 2D object tracking to any detector. +- [ansible/ansible-lint](https://github.com/ansible/ansible-lint) Ansible-lint checks playbooks for practices and behaviour that could potentially be improved +- [ansible-community/molecule](https://github.com/ansible-community/molecule) Ansible Molecule testing framework +- +[Many more](https://github.com/willmcgugan/rich/network/dependents)! + + From 317125a86046c06e8da422c92b6d089aa79f4083 Mon Sep 17 00:00:00 2001 From: toto6038 <50100922+toto6038@users.noreply.github.com> Date: Sun, 23 Jan 2022 03:27:34 +0800 Subject: [PATCH 03/15] Add Traditional Chinese text --- rich/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rich/__main__.py b/rich/__main__.py index 132e80941..78f3f7b00 100644 --- a/rich/__main__.py +++ b/rich/__main__.py @@ -97,7 +97,7 @@ def comparison(renderable1: RenderableType, renderable2: RenderableType) -> Tabl table.add_row( "Asian\nlanguage\nsupport", - ":flag_for_china: 该库支持中文,日文和韩文文本!\n:flag_for_japan: ライブラリは中国語、日本語、韓国語のテキストをサポートしています\n:flag_for_south_korea: 이 라이브러리는 중국어, 일본어 및 한국어 텍스트를 지원합니다", + ":flag_for_china: 该库支持中文,日文和韩文文本!\n:flag_for_japan: ライブラリは中国語、日本語、韓国語のテキストをサポートしています\n:flag_for_south_korea: 이 라이브러리는 중국어, 일본어 및 한국어 텍스트를 지원합니다\n:flag_for_taiwan: 本函式庫支援中日韓文字元!", ) markup_example = ( From ecb18d4c9323ccfb71a4030b3ab4261a46f84ddc Mon Sep 17 00:00:00 2001 From: toto6038 <50100922+toto6038@users.noreply.github.com> Date: Sun, 23 Jan 2022 03:28:48 +0800 Subject: [PATCH 04/15] Translate Traditional Chinese readme --- README.zh-tw.md | 144 ++++++++++++++++++++++++------------------------ 1 file changed, 72 insertions(+), 72 deletions(-) diff --git a/README.zh-tw.md b/README.zh-tw.md index 189b1fada..2e4b857b0 100644 --- a/README.zh-tw.md +++ b/README.zh-tw.md @@ -21,31 +21,31 @@ • [Italian readme](https://github.com/willmcgugan/rich/blob/master/README.it.md) • [Русский readme](https://github.com/willmcgugan/rich/blob/master/README.ru.md) -Rich is a Python library for _rich_ text and beautiful formatting in the terminal. +Rich 是一款 Python 函式庫,提供終端機介面中 _豐富的_ 文字效果及精美的格式設定。 -The [Rich API](https://rich.readthedocs.io/en/latest/) makes it easy to add color and style to terminal output. Rich can also render pretty tables, progress bars, markdown, syntax highlighted source code, tracebacks, and more — out of the box. +[Rich API](https://rich.readthedocs.io/en/latest/) 讓終端機介面加上色彩及樣式變得易如反掌。Rich 也可以繪製漂亮的表格、進度條、Markdown、語法突顯的程式碼、Traceback(追溯)……。 ![Features](https://github.com/willmcgugan/rich/raw/master/imgs/features.png) -For a video introduction to Rich see [calmcode.io](https://calmcode.io/rich/introduction.html) by [@fishnets88](https://twitter.com/fishnets88). +關於 Rich 的介紹,請參見 [@fishnets88](https://twitter.com/fishnets88) 在 [calmcode.io](https://calmcode.io/rich/introduction.html) 錄製的影片。 -See what [people are saying about Rich](https://www.willmcgugan.com/blog/pages/post/rich-tweets/). +[看看其他人對於 Rich 的討論](https://www.willmcgugan.com/blog/pages/post/rich-tweets/)。 -## Compatibility +## 相容性 -Rich works with Linux, OSX, and Windows. True color / emoji works with new Windows Terminal, classic terminal is limited to 16 colors. Rich requires Python 3.6.1 or later. +Rich 可在 Linux、macOS、Windows 上運作。在新的 Windows Terminal 中可支援顯示全彩及 Emoji,但傳統的終端機中僅支援 16 色。Rich 需要的 Python 最低版本為 3.6.1。 -Rich works with [Jupyter notebooks](https://jupyter.org/) with no additional configuration required. +Rich 可在 [Jupyter notebooks](https://jupyter.org/) 上使用,無須額外設定。 -## Installing +## 安裝 -Install with `pip` or your favorite PyPI package manager. +以 `pip` 或 PyPI 套件管理器安裝。 ```sh python -m pip install rich ``` -Run the following to test Rich output on your terminal: +以此命令測試 Rich 在終端機的輸出效果: ```sh python -m rich @@ -53,7 +53,7 @@ python -m rich ## Rich Print -To effortlessly add rich output to your application, you can import the [rich print](https://rich.readthedocs.io/en/latest/introduction.html#quick-start) method, which has the same signature as the builtin Python function. Try this: +匯入 [rich print](https://rich.readthedocs.io/en/latest/introduction.html#quick-start) 方法就可以輕鬆地讓程式進行 rich 輸出,rich print 與 Python 內建的函式用法相似。試試: ```python from rich import print @@ -65,7 +65,7 @@ print("Hello, [bold magenta]World[/bold magenta]!", ":vampire:", locals()) ## Rich REPL -Rich can be installed in the Python REPL, so that any data structures will be pretty printed and highlighted. +Rich 可以安裝在 Python REPL 中,如此一來任何資料結構都能被漂亮的輸出及突顯標示。 ```python >>> from rich import pretty @@ -74,9 +74,9 @@ Rich can be installed in the Python REPL, so that any data structures will be pr ![REPL](https://github.com/willmcgugan/rich/raw/master/imgs/repl.png) -## Using the Console +## 使用 Console -For more control over rich terminal content, import and construct a [Console](https://rich.readthedocs.io/en/latest/reference/console.html#rich.console.Console) object. +匯入並建構 [Console](https://rich.readthedocs.io/en/latest/reference/console.html#rich.console.Console) 物件,以更全面地控制 rich 終端機內容。 ```python from rich.console import Console @@ -84,25 +84,25 @@ from rich.console import Console console = Console() ``` -The Console object has a `print` method which has an intentionally similar interface to the builtin `print` function. Here's an example of use: +Console 物件有個 `print` 方法,且刻意設計的與內建 `print` 函式相似。參考此範例: ```python console.print("Hello", "World!") ``` -As you might expect, this will print `"Hello World!"` to the terminal. Note that unlike the builtin `print` function, Rich will word-wrap your text to fit within the terminal width. +如同預期的,這會將 `"Hello World!"` 印在終端機。須注意不同於內建的 `print` 函式,Rich 會自動將過長的文字換行,以符合終端機的寬度。 -There are a few ways of adding color and style to your output. You can set a style for the entire output by adding a `style` keyword argument. Here's an example: +有幾種加上顏色及樣式的方式。您可以用 `style` 引數設定輸出內容的樣式,參考此範例: ```python console.print("Hello", "World!", style="bold red") ``` -The output will be something like the following: +輸出結果如下圖: ![Hello World](https://github.com/willmcgugan/rich/raw/master/imgs/hello_world.png) -That's fine for styling a line of text at a time. For more finely grained styling, Rich renders a special markup which is similar in syntax to [bbcode](https://en.wikipedia.org/wiki/BBCode). Here's an example: +介紹完了如何對整行文字設定樣式,接著來看看更細部的使用。Rich 可以接受類似 [bbcode](https://en.wikipedia.org/wiki/BBCode) 的語法,對個別文字設定樣式。參考此範例: ```python console.print("Where there is a [bold cyan]Will[/bold cyan] there [u]is[/u] a [i]way[/i].") @@ -110,11 +110,11 @@ console.print("Where there is a [bold cyan]Will[/bold cyan] there [u]is[/u] a [i ![Console Markup](https://github.com/willmcgugan/rich/raw/master/imgs/where_there_is_a_will.png) -You can use a Console object to generate sophisticated output with minimal effort. See the [Console API](https://rich.readthedocs.io/en/latest/console.html) docs for details. +您可以用 Console 物件不費吹灰之力地達成細膩的輸出效果。參閱 [Console API](https://rich.readthedocs.io/en/latest/console.html) 說明文件以了解細節。 ## Rich Inspect -Rich has an [inspect](https://rich.readthedocs.io/en/latest/reference/init.html?highlight=inspect#rich.inspect) function which can produce a report on any Python object, such as class, instance, or builtin. +Rich 提供了 [inspect](https://rich.readthedocs.io/en/latest/reference/init.html?highlight=inspect#rich.inspect) 函式,可以對任何 Python 物件,如 class、instance 或 builtin ,為其產生一份報告。 ```python >>> my_list = ["foo", "bar"] @@ -124,18 +124,18 @@ Rich has an [inspect](https://rich.readthedocs.io/en/latest/reference/init.html? ![Log](https://github.com/willmcgugan/rich/raw/master/imgs/inspect.png) -See the [inspect docs](https://rich.readthedocs.io/en/latest/reference/init.html#rich.inspect) for details. +參閱 [inspect 說明文件](https://rich.readthedocs.io/en/latest/reference/init.html#rich.inspect) 以了解細節。 -# Rich Library +# Rich 函式庫 Rich contains a number of builtin _renderables_ you can use to create elegant output in your CLI and help you debug your code. -Click the following headings for details: +按一下子標題以了解細節:
Log -The Console object has a `log()` method which has a similar interface to `print()`, but also renders a column for the current time and the file and line which made the call. By default Rich will do syntax highlighting for Python structures and for repr strings. If you log a collection (i.e. a dict or a list) Rich will pretty print it so that it fits in the available space. Here's an example of some of these features. +Console 物件提供了 `log()` 方法,使用方式與 `print()` 類似,但還多了一欄來顯示目前時間、進行呼叫的檔案及行號。預設情況下 Rich 會語法突顯標示 Python 的結構及 repr 字串。若使用於字典或串列這類集合性物件,Rich 會將其漂亮地印出來,以符合可用空間。此範例示範了這些功能。 ```python from rich.console import Console @@ -160,19 +160,19 @@ def test_log(): test_log() ``` -The above produces the following output: +上面的程式碼會產生下圖結果: ![Log](https://github.com/willmcgugan/rich/raw/master/imgs/log.png) -Note the `log_locals` argument, which outputs a table containing the local variables where the log method was called. +注意到 `log_locals` 引數,可用來輸出一張表格,用來顯示 log 方法被呼叫時,區域變數的內容。 -The log method could be used for logging to the terminal for long running applications such as servers, but is also a very nice debugging aid. +log 方法可用於伺服器上長時間運作的程式,也很適合一般程式偵錯用途。
Logging Handler -You can also use the builtin [Handler class](https://rich.readthedocs.io/en/latest/logging.html) to format and colorize output from Python's logging module. Here's an example of the output: +您也可以使用內建的 [Handler 類別](https://rich.readthedocs.io/en/latest/logging.html) 來將 Python logging 模組的輸出內容格式化並賦予色彩: ![Logging](https://github.com/willmcgugan/rich/raw/master/imgs/logging.png) @@ -181,27 +181,27 @@ You can also use the builtin [Handler class](https://rich.readthedocs.io/en/late
Emoji -To insert an emoji in to console output place the name between two colons. Here's an example: +以一對冒號包住表情符號的名稱,來透過 console 插入 Emoji。參考範例: ```python >>> console.print(":smiley: :vampire: :pile_of_poo: :thumbs_up: :raccoon:") 😃 🧛 💩 👍 🦝 ``` -Please use this feature wisely. +請謹慎使用此功能。
-Tables +表格 -Rich can render flexible [tables](https://rich.readthedocs.io/en/latest/tables.html) with unicode box characters. There is a large variety of formatting options for borders, styles, cell alignment etc. +Rich 可以用 unicode box 字元繪製彈性的 [表格](https://rich.readthedocs.io/en/latest/tables.html)。格式設定十分多元,包含框線、樣式、儲存格對齊……。 ![table movie](https://github.com/willmcgugan/rich/raw/master/imgs/table_movie.gif) -The animation above was generated with [table_movie.py](https://github.com/willmcgugan/rich/blob/master/examples/table_movie.py) in the examples directory. +上圖的動畫效果是以 [table_movie.py](https://github.com/willmcgugan/rich/blob/master/examples/table_movie.py) 產生的,該檔案位於 examples 資料夾。 -Here's a simpler table example: +參考這個簡單的表格範例: ```python from rich.console import Console @@ -233,24 +233,24 @@ table.add_row( console.print(table) ``` -This produces the following output: +執行結果如圖: ![table](https://github.com/willmcgugan/rich/raw/master/imgs/table.png) -Note that console markup is rendered in the same way as `print()` and `log()`. In fact, anything that is renderable by Rich may be included in the headers / rows (even other tables). +請留意,主控台標記的呈現方式與 `print()`、`log()` 相同。事實上,由 Rich 繪製的任何東西都可以被放在任何標題、列,甚至其他表格裡。 -The `Table` class is smart enough to resize columns to fit the available width of the terminal, wrapping text as required. Here's the same example, with the terminal made smaller than the table above: +`Table` 類別很聰明,能夠自動調整欄寬來配合終端機的大小,也會在需要時自動將文字換行。此範例的程式碼與上一個相同,然而終端機變小了一點: ![table2](https://github.com/willmcgugan/rich/raw/master/imgs/table2.png)
-Progress Bars +進度條 -Rich can render multiple flicker-free [progress](https://rich.readthedocs.io/en/latest/progress.html) bars to track long-running tasks. +Rich 可繪製多個不閃爍的 [進度條](https://rich.readthedocs.io/en/latest/progress.html),以追蹤需時較久的工作。 -For basic usage, wrap any sequence in the `track` function and iterate over the result. Here's an example: +基本的使用方式,是將序列放在 `track` 函式中,再對其結果疊代。參考此範例: ```python from rich.progress import track @@ -259,22 +259,22 @@ for step in track(range(100)): do_step(step) ``` -It's not much harder to add multiple progress bars. Here's an example taken from the docs: +新增多個進度條也不是難事,來看看說明文件中的範例: ![progress](https://github.com/willmcgugan/rich/raw/master/imgs/progress.gif) -The columns may be configured to show any details you want. Built-in columns include percentage complete, file size, file speed, and time remaining. Here's another example showing a download in progress: +您可以調整要顯示的狀態欄位。內建的欄位包含完成百分比、檔案大小、讀寫速度及剩餘時間。來看看另一個用來顯示下載進度的範例: ![progress](https://github.com/willmcgugan/rich/raw/master/imgs/downloader.gif) -To try this out yourself, see [examples/downloader.py](https://github.com/willmcgugan/rich/blob/master/examples/downloader.py) which can download multiple URLs simultaneously while displaying progress. +想嘗試看看嗎?您可以在 [examples/downloader.py](https://github.com/willmcgugan/rich/blob/master/examples/downloader.py) 取得此範例程式。此程式可以在下載多個檔案時顯示各自的進度。
-Status +狀態 -For situations where it is hard to calculate progress, you can use the [status](https://rich.readthedocs.io/en/latest/reference/console.html#rich.console.Console.status) method which will display a 'spinner' animation and message. The animation won't prevent you from using the console as normal. Here's an example: +有些狀況下很難估計進度,就可以使用 [status](https://rich.readthedocs.io/en/latest/reference/console.html#rich.console.Console.status) 方法,此方法會顯示「spinner」動畫及訊息。該動畫播放時,仍可正常操作主控台。參考此範例: ```python from time import sleep @@ -290,45 +290,45 @@ with console.status("[bold green]Working on tasks...") as status: console.log(f"{task} complete") ``` -This generates the following output in the terminal. +終端機的顯示效果如下: ![status](https://github.com/willmcgugan/rich/raw/master/imgs/status.gif) -The spinner animations were borrowed from [cli-spinners](https://www.npmjs.com/package/cli-spinners). You can select a spinner by specifying the `spinner` parameter. Run the following command to see the available values: +該 spinner 動畫乃借用自 [cli-spinners](https://www.npmjs.com/package/cli-spinners)。可以用 `spinner` 參數指定 spinner 樣式。執行此命令以顯示可用的值: ``` python -m rich.spinner ``` -The above command generates the following output in the terminal: +此命令在終端機的輸出結果如下圖: ![spinners](https://github.com/willmcgugan/rich/raw/master/imgs/spinners.gif)
-Tree + -Rich can render a [tree](https://rich.readthedocs.io/en/latest/tree.html) with guide lines. A tree is ideal for displaying a file structure, or any other hierarchical data. +Rich 可以用導引線繪製一棵 [樹](https://rich.readthedocs.io/en/latest/tree.html)。樹很適合用來顯示檔案結構,或其他繼承性的資料。 -The labels of the tree can be simple text or anything else Rich can render. Run the following for a demonstration: +可以用文字或其他 Rich 能繪製的元素作為樹的標籤。執行下列程式碼來看看效果: ``` python -m rich.tree ``` -This generates the following output: +這會產生下圖的結果: ![markdown](https://github.com/willmcgugan/rich/raw/master/imgs/tree.png) -See the [tree.py](https://github.com/willmcgugan/rich/blob/master/examples/tree.py) example for a script that displays a tree view of any directory, similar to the linux `tree` command. +您可以參考 [tree.py](https://github.com/willmcgugan/rich/blob/master/examples/tree.py) 範例程式,此程式可以樹狀圖展示目錄結構,如同 Linux 的 `tree` 命令。
-Columns +資料欄 -Rich can render content in neat [columns](https://rich.readthedocs.io/en/latest/columns.html) with equal or optimal width. Here's a very basic clone of the (MacOS / Linux) `ls` command which displays a directory listing in columns: +Rich 可以將內容呈現於整齊的 [資料欄](https://rich.readthedocs.io/en/latest/columns.html) 中,其欄寬可為等寬或最適寬度。此範例仿作了 macOS / Linux 系統中 `ls` 命令的基本功能,可以用資料欄列出目錄: ```python import os @@ -341,7 +341,7 @@ directory = os.listdir(sys.argv[1]) print(Columns(directory)) ``` -The following screenshot is the output from the [columns example](https://github.com/willmcgugan/rich/blob/master/examples/columns.py) which displays data pulled from an API in columns: +此螢幕截圖為 [資料欄範例](https://github.com/willmcgugan/rich/blob/master/examples/columns.py) 的輸出結果。此程式從某 API 取得資料,並以資料欄呈現: ![columns](https://github.com/willmcgugan/rich/raw/master/imgs/columns.png) @@ -350,9 +350,9 @@ The following screenshot is the output from the [columns example](https://github
Markdown -Rich can render [markdown](https://rich.readthedocs.io/en/latest/markdown.html) and does a reasonable job of translating the formatting to the terminal. +Rich 可以繪製 [Markdown](https://rich.readthedocs.io/en/latest/markdown.html) 並處理了將其轉換為終端機格式的大量工作。 -To render markdown import the `Markdown` class and construct it with a string containing markdown code. Then print it to the console. Here's an example: +先匯入 `Markdown` 類別,再以內容為 Markdown 語言的字串建構一個物件,接著將其印到 console。參考此範例: ```python from rich.console import Console @@ -364,16 +364,16 @@ with open("README.md") as readme: console.print(markdown) ``` -This will produce output something like the following: +執行結果如下圖: ![markdown](https://github.com/willmcgugan/rich/raw/master/imgs/markdown.png)
-Syntax Highlighting +語法突顯 -Rich uses the [pygments](https://pygments.org/) library to implement [syntax highlighting](https://rich.readthedocs.io/en/latest/syntax.html). Usage is similar to rendering markdown; construct a `Syntax` object and print it to the console. Here's an example: +Rich 使用了 [pygments](https://pygments.org/) 函式庫來實作 [語法突顯](https://rich.readthedocs.io/en/latest/syntax.html) 功能。使用方式與繪製 Markdown 相似,先建構 `Syntax` 物件並將其印到 console。參考此範例: ```python from rich.console import Console @@ -399,34 +399,34 @@ console = Console() console.print(syntax) ``` -This will produce the following output: +執行結果如下圖: ![syntax](https://github.com/willmcgugan/rich/raw/master/imgs/syntax.png)
-Tracebacks +Tracebacks(追溯) -Rich can render [beautiful tracebacks](https://rich.readthedocs.io/en/latest/traceback.html) which are easier to read and show more code than standard Python tracebacks. You can set Rich as the default traceback handler so all uncaught exceptions will be rendered by Rich. +Rich 可以繪製 [漂亮的 tracebacks](https://rich.readthedocs.io/en/latest/traceback.html),相較標準的 Python traceback 顯示了更多程式碼且更好懂。您可以將 Rich 設為預設的 traceback handler(處理常式),如此一來所有未接住的例外都由 Rich 呈現。 -Here's what it looks like on OSX (similar on Linux): +它在 macOS 上執行的效果如圖(Linux 上差異不大): ![traceback](https://github.com/willmcgugan/rich/raw/master/imgs/traceback.png)
-All Rich renderables make use of the [Console Protocol](https://rich.readthedocs.io/en/latest/protocol.html), which you can also use to implement your own Rich content. +所有可由 Rich 繪製的物件都用到了 [Console 協定](https://rich.readthedocs.io/en/latest/protocol.html),您也可以依此實作自訂的 Rich 內容。 -# Rich for enterprise +# Rich 企業版 -Available as part of the Tidelift Subscription. +可在 Tidelift 訂閱方案取得。 -The maintainers of Rich and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source packages you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact packages you use. [Learn more.](https://tidelift.com/subscription/pkg/pypi-rich?utm_source=pypi-rich&utm_medium=referral&utm_campaign=enterprise&utm_term=repo) +Rich 及其他數以千計的套件維護者正與 Tidelift 合作,以提供開放原始碼套件的商業性支援。此計畫能協助您節省時間、避開風險,同時也讓套件的維護者獲得報酬。[了解更多。](https://tidelift.com/subscription/pkg/pypi-rich?utm_source=pypi-rich&utm_medium=referral&utm_campaign=enterprise&utm_term=repo) -# Projects using Rich +# 使用 Rich 的專案 -Here are a few projects using Rich: +以下列出幾個使用 Rich 的專案: - [BrancoLab/BrainRender](https://github.com/BrancoLab/BrainRender) a python package for the visualization of three dimensional neuro-anatomical data From 7fe872bc9f659e9fc18bc4d9a6c093c28bd5c138 Mon Sep 17 00:00:00 2001 From: toto6038 <50100922+toto6038@users.noreply.github.com> Date: Sun, 23 Jan 2022 03:48:32 +0800 Subject: [PATCH 05/15] Update `README.zh-tw.md` --- README.zh-tw.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.zh-tw.md b/README.zh-tw.md index 2e4b857b0..8ff4b4c00 100644 --- a/README.zh-tw.md +++ b/README.zh-tw.md @@ -128,7 +128,7 @@ Rich 提供了 [inspect](https://rich.readthedocs.io/en/latest/reference/init.ht # Rich 函式庫 -Rich contains a number of builtin _renderables_ you can use to create elegant output in your CLI and help you debug your code. +Rich 包含了一系列可繪製的物件,您可以使用它們來印出精美的畫面,或者協助偵錯程式碼。 按一下子標題以了解細節: From 14333a49daf18fc504403578db2708eec790fde0 Mon Sep 17 00:00:00 2001 From: toto6038 <50100922+toto6038@users.noreply.github.com> Date: Sun, 23 Jan 2022 23:55:44 +0800 Subject: [PATCH 06/15] Change wording and update `README.zh-tw.md` --- README.zh-tw.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.zh-tw.md b/README.zh-tw.md index 8ff4b4c00..29b5e1028 100644 --- a/README.zh-tw.md +++ b/README.zh-tw.md @@ -21,9 +21,9 @@ • [Italian readme](https://github.com/willmcgugan/rich/blob/master/README.it.md) • [Русский readme](https://github.com/willmcgugan/rich/blob/master/README.ru.md) -Rich 是一款 Python 函式庫,提供終端機介面中 _豐富的_ 文字效果及精美的格式設定。 +Rich 是一款提供終端機介面中 _豐富的_ 文字效果及精美的格式設定的 Python 函式庫。 -[Rich API](https://rich.readthedocs.io/en/latest/) 讓終端機介面加上色彩及樣式變得易如反掌。Rich 也可以繪製漂亮的表格、進度條、Markdown、語法突顯的程式碼、Traceback(追溯)……。 +[Rich API](https://rich.readthedocs.io/en/latest/) 讓終端機介面加上色彩及樣式變得易如反掌。Rich 也可以繪製漂亮的表格、進度條、Markdown、語法醒目標示的程式碼、Traceback(追溯)……。 ![Features](https://github.com/willmcgugan/rich/raw/master/imgs/features.png) @@ -33,7 +33,7 @@ Rich 是一款 Python 函式庫,提供終端機介面中 _豐富的_ 文字效 ## 相容性 -Rich 可在 Linux、macOS、Windows 上運作。在新的 Windows Terminal 中可支援顯示全彩及 Emoji,但傳統的終端機中僅支援 16 色。Rich 需要的 Python 最低版本為 3.6.1。 +Rich 可在 Linux、macOS、Windows 上運作。在新的 Windows Terminal 中可支援顯示全彩及 Emoji,但傳統的終端機中僅支援 16 色。Rich 最低需要的 Python 版本為 3.6.1。 Rich 可在 [Jupyter notebooks](https://jupyter.org/) 上使用,無須額外設定。 @@ -65,7 +65,7 @@ print("Hello, [bold magenta]World[/bold magenta]!", ":vampire:", locals()) ## Rich REPL -Rich 可以安裝在 Python REPL 中,如此一來任何資料結構都能被漂亮的輸出及突顯標示。 +Rich 可以安裝在 Python REPL 中,如此一來就可以漂亮的輸出與突顯標示任何資料結構。 ```python >>> from rich import pretty @@ -135,7 +135,7 @@ Rich 包含了一系列可繪製的物件,您可以使用它們來印出精美
Log -Console 物件提供了 `log()` 方法,使用方式與 `print()` 類似,但還多了一欄來顯示目前時間、進行呼叫的檔案及行號。預設情況下 Rich 會語法突顯標示 Python 的結構及 repr 字串。若使用於字典或串列這類集合性物件,Rich 會將其漂亮地印出來,以符合可用空間。此範例示範了這些功能。 +Console 物件提供了 `log()` 方法,使用方式與 `print()` 類似,但還多了一欄來顯示目前時間、進行呼叫的檔案及行號。預設情況下 Rich 會語法醒目標示 Python 的結構及 repr 字串。若使用於字典或串列這類集合性物件,Rich 會將其漂亮地印出來,以符合可用空間。此範例示範了這些功能。 ```python from rich.console import Console @@ -371,9 +371,9 @@ console.print(markdown)
-語法突顯 +語法醒目標示 -Rich 使用了 [pygments](https://pygments.org/) 函式庫來實作 [語法突顯](https://rich.readthedocs.io/en/latest/syntax.html) 功能。使用方式與繪製 Markdown 相似,先建構 `Syntax` 物件並將其印到 console。參考此範例: +Rich 使用了 [pygments](https://pygments.org/) 函式庫來實作 [語法醒目標示](https://rich.readthedocs.io/en/latest/syntax.html) 功能。使用方式與繪製 Markdown 相似,先建構 `Syntax` 物件並將其印到 console。參考此範例: ```python from rich.console import Console From 31bd59ec7137c8117c5075f02f9553a70a3b6bb1 Mon Sep 17 00:00:00 2001 From: toto6038 <50100922+toto6038@users.noreply.github.com> Date: Mon, 24 Jan 2022 00:07:34 +0800 Subject: [PATCH 07/15] Update CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f3819a781..b86171830 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Workaround for edge case of object from Faiss with no `__class__` https://github.com/Textualize/rich/issues/1838 +- Add Traditional Chinese readme ### Added @@ -27,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **breaking** Deprecated rich.console.RenderGroup, now named rich.console.Group - **breaking** `Syntax.__init__` parameter `lexer_name` renamed to `lexer` - Syntax constructor accepts both str and now a pygments lexer https://github.com/Textualize/rich/pull/1748 +- Rename the file name of Simplified Chinese readme to `README.zh-cn.md` (original `README.cn.md`) to reflect the variants of Chinese. ## [10.16.2] - 2021-01-02 From de093e5552cd3909778c52d411786746f2508f5c Mon Sep 17 00:00:00 2001 From: toto6038 <50100922+toto6038@users.noreply.github.com> Date: Mon, 24 Jan 2022 21:10:31 +0800 Subject: [PATCH 08/15] Update link in `README.md` --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f5365e7d0..23822026d 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,8 @@ ![Logo](https://github.com/willmcgugan/rich/raw/master/imgs/logo.svg) [English readme](https://github.com/willmcgugan/rich/blob/master/README.md) - • [中文 readme](https://github.com/willmcgugan/rich/blob/master/README.cn.md) + • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-cn.md) + • [正體中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-tw.md) • [Lengua española readme](https://github.com/willmcgugan/rich/blob/master/README.es.md) • [Deutsche readme](https://github.com/willmcgugan/rich/blob/master/README.de.md) • [Läs på svenska](https://github.com/willmcgugan/rich/blob/master/README.sv.md) From 70ebda06ee3d924c5c2d647adc148430127b4075 Mon Sep 17 00:00:00 2001 From: toto6038 <50100922+toto6038@users.noreply.github.com> Date: Wed, 26 Jan 2022 20:38:13 +0800 Subject: [PATCH 09/15] Revert Simplified Chinese readme to old name --- CHANGELOG.md | 1 - README.zh-cn.md => README.cn.md | 2 +- README.de-ch.md | 2 +- README.de.md | 2 +- README.es.md | 2 +- README.fr.md | 2 +- README.hi.md | 2 +- README.it.md | 2 +- README.ja.md | 2 +- README.kr.md | 2 +- README.md | 2 +- README.pt-br.md | 2 +- README.ru.md | 2 +- README.sv.md | 2 +- README.zh-tw.md | 2 +- 15 files changed, 14 insertions(+), 15 deletions(-) rename README.zh-cn.md => README.cn.md (99%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8272ba640..f7dfca356 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,7 +29,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **breaking** Deprecated rich.console.RenderGroup, now named rich.console.Group - **breaking** `Syntax.__init__` parameter `lexer_name` renamed to `lexer` - Syntax constructor accepts both str and now a pygments lexer https://github.com/Textualize/rich/pull/1748 -- Rename the file name of Simplified Chinese readme to `README.zh-cn.md` (original `README.cn.md`) to reflect the variants of Chinese. ## [10.16.2] - 2021-01-02 diff --git a/README.zh-cn.md b/README.cn.md similarity index 99% rename from README.zh-cn.md rename to README.cn.md index 97f099634..a5c7c5b66 100644 --- a/README.zh-cn.md +++ b/README.cn.md @@ -7,7 +7,7 @@ ![Logo](https://github.com/willmcgugan/rich/raw/master/imgs/logo.svg) [English readme](https://github.com/willmcgugan/rich/blob/master/README.md) - • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-cn.md) + • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.cn.md) • [正體中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-tw.md) • [Lengua española readme](https://github.com/willmcgugan/rich/blob/master/README.es.md) • [Deutsche readme](https://github.com/willmcgugan/rich/blob/master/README.de.md) diff --git a/README.de-ch.md b/README.de-ch.md index 4d6359ff5..6c1d7d278 100644 --- a/README.de-ch.md +++ b/README.de-ch.md @@ -7,7 +7,7 @@ ![Logo](https://github.com/willmcgugan/rich/raw/master/imgs/logo.svg) [English readme](https://github.com/willmcgugan/rich/blob/master/README.md) - • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-cn.md) + • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.cn.md) • [正體中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-tw.md) • [Lengua española readme](https://github.com/willmcgugan/rich/blob/master/README.es.md) • [Deutsche readme](https://github.com/willmcgugan/rich/blob/master/README.de.md) diff --git a/README.de.md b/README.de.md index 148f146f2..34a99a64e 100644 --- a/README.de.md +++ b/README.de.md @@ -7,7 +7,7 @@ ![Logo](https://github.com/willmcgugan/rich/raw/master/imgs/logo.svg) [English readme](https://github.com/willmcgugan/rich/blob/master/README.md) - • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-cn.md) + • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.cn.md) • [正體中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-tw.md) • [Lengua española readme](https://github.com/willmcgugan/rich/blob/master/README.es.md) • [Deutsche readme](https://github.com/willmcgugan/rich/blob/master/README.de.md) diff --git a/README.es.md b/README.es.md index ec4e4f425..c9cb2af14 100644 --- a/README.es.md +++ b/README.es.md @@ -7,7 +7,7 @@ ![Logo](https://github.com/willmcgugan/rich/raw/master/imgs/logo.svg) [English readme](https://github.com/willmcgugan/rich/blob/master/README.md) - • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-cn.md) + • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.cn.md) • [正體中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-tw.md) • [Lengua española readme](https://github.com/willmcgugan/rich/blob/master/README.es.md) • [Deutsche readme](https://github.com/willmcgugan/rich/blob/master/README.de.md) diff --git a/README.fr.md b/README.fr.md index 0fbea94fc..1a09c054a 100644 --- a/README.fr.md +++ b/README.fr.md @@ -7,7 +7,7 @@ ![Logo](https://github.com/willmcgugan/rich/raw/master/imgs/logo.svg) [English readme](https://github.com/willmcgugan/rich/blob/master/README.md) - • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-cn.md) + • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.cn.md) • [正體中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-tw.md) • [Lengua española readme](https://github.com/willmcgugan/rich/blob/master/README.es.md) • [Deutsche readme](https://github.com/willmcgugan/rich/blob/master/README.de.md) diff --git a/README.hi.md b/README.hi.md index 443472c5c..c3c62f532 100644 --- a/README.hi.md +++ b/README.hi.md @@ -7,7 +7,7 @@ ![Logo](https://github.com/willmcgugan/rich/raw/master/imgs/logo.svg) [English readme](https://github.com/willmcgugan/rich/blob/master/README.md) - • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-cn.md) + • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.cn.md) • [正體中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-tw.md) • [Lengua española readme](https://github.com/willmcgugan/rich/blob/master/README.es.md) • [Deutsche readme](https://github.com/willmcgugan/rich/blob/master/README.de.md) diff --git a/README.it.md b/README.it.md index cf2e2c5fe..c6e8b5620 100644 --- a/README.it.md +++ b/README.it.md @@ -6,7 +6,7 @@ ![Logo](https://github.com/willmcgugan/rich/raw/master/imgs/logo.svg) [English readme](https://github.com/willmcgugan/rich/blob/master/README.md) - • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-cn.md) + • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.cn.md) • [正體中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-tw.md) • [Lengua española readme](https://github.com/willmcgugan/rich/blob/master/README.es.md) • [Deutsche readme](https://github.com/willmcgugan/rich/blob/master/README.de.md) diff --git a/README.ja.md b/README.ja.md index 0429d1150..300f779d3 100644 --- a/README.ja.md +++ b/README.ja.md @@ -7,7 +7,7 @@ ![Logo](https://github.com/willmcgugan/rich/raw/master/imgs/logo.svg) [English readme](https://github.com/willmcgugan/rich/blob/master/README.md) - • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-cn.md) + • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.cn.md) • [正體中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-tw.md) • [Lengua española readme](https://github.com/willmcgugan/rich/blob/master/README.es.md) • [Deutsche readme](https://github.com/willmcgugan/rich/blob/master/README.de.md) diff --git a/README.kr.md b/README.kr.md index e3aa03134..b55529af7 100644 --- a/README.kr.md +++ b/README.kr.md @@ -7,7 +7,7 @@ ![Logo](https://github.com/willmcgugan/rich/raw/master/imgs/logo.svg) [English readme](https://github.com/willmcgugan/rich/blob/master/README.md) - • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-cn.md) + • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.cn.md) • [正體中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-tw.md) • [Lengua española readme](https://github.com/willmcgugan/rich/blob/master/README.es.md) • [Deutsche readme](https://github.com/willmcgugan/rich/blob/master/README.de.md) diff --git a/README.md b/README.md index 23822026d..f7cf6368f 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ ![Logo](https://github.com/willmcgugan/rich/raw/master/imgs/logo.svg) [English readme](https://github.com/willmcgugan/rich/blob/master/README.md) - • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-cn.md) + • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.cn.md) • [正體中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-tw.md) • [Lengua española readme](https://github.com/willmcgugan/rich/blob/master/README.es.md) • [Deutsche readme](https://github.com/willmcgugan/rich/blob/master/README.de.md) diff --git a/README.pt-br.md b/README.pt-br.md index 3d888ee44..55f366caf 100644 --- a/README.pt-br.md +++ b/README.pt-br.md @@ -7,7 +7,7 @@ ![Logo](https://github.com/willmcgugan/rich/raw/master/imgs/logo.svg) [English readme](https://github.com/willmcgugan/rich/blob/master/README.md) - • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-cn.md) + • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.cn.md) • [正體中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-tw.md) • [Lengua española readme](https://github.com/willmcgugan/rich/blob/master/README.es.md) • [Deutsche readme](https://github.com/willmcgugan/rich/blob/master/README.de.md) diff --git a/README.ru.md b/README.ru.md index d9a02c21c..b6ff2d255 100644 --- a/README.ru.md +++ b/README.ru.md @@ -8,7 +8,7 @@ ![Logo](https://github.com/willmcgugan/rich/raw/master/imgs/logo.svg) [English readme](https://github.com/willmcgugan/rich/blob/master/README.md) - • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-cn.md) + • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.cn.md) • [正體中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-tw.md) • [Lengua española readme](https://github.com/willmcgugan/rich/blob/master/README.es.md) • [Deutsche readme](https://github.com/willmcgugan/rich/blob/master/README.de.md) diff --git a/README.sv.md b/README.sv.md index b630b3e7f..b2685a705 100644 --- a/README.sv.md +++ b/README.sv.md @@ -7,7 +7,7 @@ ![Logo](https://github.com/willmcgugan/rich/raw/master/imgs/logo.svg) [English readme](https://github.com/willmcgugan/rich/blob/master/README.md) - • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-cn.md) + • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.cn.md) • [正體中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-tw.md) • [Lengua española readme](https://github.com/willmcgugan/rich/blob/master/README.es.md) • [Deutsche readme](https://github.com/willmcgugan/rich/blob/master/README.de.md) diff --git a/README.zh-tw.md b/README.zh-tw.md index 29b5e1028..207f3260f 100644 --- a/README.zh-tw.md +++ b/README.zh-tw.md @@ -7,7 +7,7 @@ ![Logo](https://github.com/willmcgugan/rich/raw/master/imgs/logo.svg) [English readme](https://github.com/willmcgugan/rich/blob/master/README.md) - • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-cn.md) + • [简体中文 readme](https://github.com/willmcgugan/rich/blob/master/README.cn.md) • [正體中文 readme](https://github.com/willmcgugan/rich/blob/master/README.zh-tw.md) • [Lengua española readme](https://github.com/willmcgugan/rich/blob/master/README.es.md) • [Deutsche readme](https://github.com/willmcgugan/rich/blob/master/README.de.md) From 1ea00c3c473e6f187b8a24963bef0682fac81142 Mon Sep 17 00:00:00 2001 From: toto6038 <50100922+toto6038@users.noreply.github.com> Date: Thu, 27 Jan 2022 20:13:46 +0800 Subject: [PATCH 10/15] Remove Trad. Chinese texts in `__main__.py` --- rich/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rich/__main__.py b/rich/__main__.py index 78f3f7b00..5b69ac354 100644 --- a/rich/__main__.py +++ b/rich/__main__.py @@ -97,7 +97,7 @@ def comparison(renderable1: RenderableType, renderable2: RenderableType) -> Tabl table.add_row( "Asian\nlanguage\nsupport", - ":flag_for_china: 该库支持中文,日文和韩文文本!\n:flag_for_japan: ライブラリは中国語、日本語、韓国語のテキストをサポートしています\n:flag_for_south_korea: 이 라이브러리는 중국어, 일본어 및 한국어 텍스트를 지원합니다\n:flag_for_taiwan: 本函式庫支援中日韓文字元!", + ":flag_for_china: 该库支持中文,日文和韩文文本!\n:flag_for_japan: ライブラリは中国語、日本語、韓国語のテキストをサポートしています\n:flag_for_south_korea: 이 라이브러리는 중국어, 일본어 및 한국어 텍스트를 지원합니다\n", ) markup_example = ( From e9cf4caa5836fa721af8c967eb63289c499af45e Mon Sep 17 00:00:00 2001 From: toto6038 <50100922+toto6038@users.noreply.github.com> Date: Thu, 27 Jan 2022 20:18:26 +0800 Subject: [PATCH 11/15] Remove trailing LF character --- rich/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rich/__main__.py b/rich/__main__.py index 5b69ac354..132e80941 100644 --- a/rich/__main__.py +++ b/rich/__main__.py @@ -97,7 +97,7 @@ def comparison(renderable1: RenderableType, renderable2: RenderableType) -> Tabl table.add_row( "Asian\nlanguage\nsupport", - ":flag_for_china: 该库支持中文,日文和韩文文本!\n:flag_for_japan: ライブラリは中国語、日本語、韓国語のテキストをサポートしています\n:flag_for_south_korea: 이 라이브러리는 중국어, 일본어 및 한국어 텍스트를 지원합니다\n", + ":flag_for_china: 该库支持中文,日文和韩文文本!\n:flag_for_japan: ライブラリは中国語、日本語、韓国語のテキストをサポートしています\n:flag_for_south_korea: 이 라이브러리는 중국어, 일본어 및 한국어 텍스트를 지원합니다", ) markup_example = ( From b0794522a6a8f85d9110db2c1768d1c4f48162d9 Mon Sep 17 00:00:00 2001 From: ptmcg Date: Mon, 31 Jan 2022 08:29:01 -0600 Subject: [PATCH 12/15] Add default_columns classmethod to Progress class --- rich/progress.py | 21 +++++++++++---------- tests/test_progress.py | 26 ++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/rich/progress.py b/rich/progress.py index 1f670db43..8b9713c7a 100644 --- a/rich/progress.py +++ b/rich/progress.py @@ -588,12 +588,7 @@ def __init__( refresh_per_second is None or refresh_per_second > 0 ), "refresh_per_second must be > 0" self._lock = RLock() - self.columns = columns or ( - TextColumn("[progress.description]{task.description}"), - BarColumn(), - TextColumn("[progress.percentage]{task.percentage:>3.0f}%"), - TimeRemainingColumn(), - ) + self.columns = columns or self.default_columns() self.speed_estimate_period = speed_estimate_period self.disable = disable @@ -613,6 +608,15 @@ def __init__( self.print = self.console.print self.log = self.console.log + @classmethod + def default_columns(cls) -> Tuple[ProgressColumn, ...]: + return ( + TextColumn("[progress.description]{task.description}"), + BarColumn(), + TextColumn("[progress.percentage]{task.percentage:>3.0f}%"), + TimeRemainingColumn(), + ) + @property def console(self) -> Console: return self.live.console @@ -1015,10 +1019,7 @@ def remove_task(self, task_id: TaskID) -> None: with Progress( SpinnerColumn(), - TextColumn("[progress.description]{task.description}"), - BarColumn(), - TextColumn("[progress.percentage]{task.percentage:>3.0f}%"), - TimeRemainingColumn(), + *Progress.default_columns(), TimeElapsedColumn(), console=console, transient=True, diff --git a/tests/test_progress.py b/tests/test_progress.py index 2020f91ff..876e5d99b 100644 --- a/tests/test_progress.py +++ b/tests/test_progress.py @@ -334,6 +334,32 @@ def test_columns() -> None: assert result == expected +def test_using_default_columns() -> None: + # can only check types, as the instances do not '==' each other + expected_default_types = [ + TextColumn, + BarColumn, + TextColumn, + TimeRemainingColumn, + ] + + progress = Progress() + assert [type(c) for c in progress.columns] == expected_default_types + + progress = Progress( + SpinnerColumn(), + *Progress.default_columns(), + "Elapsed:", + TimeElapsedColumn(), + ) + assert [type(c) for c in progress.columns] == [ + SpinnerColumn, + *expected_default_types, + str, + TimeElapsedColumn, + ] + + def test_task_create() -> None: task = Task(TaskID(1), "foo", 100, 0, _get_time=lambda: 1) assert task.elapsed is None From 76e234b79d8e8ae2c922c6576856bb5c613ce1e0 Mon Sep 17 00:00:00 2001 From: ptmcg Date: Mon, 31 Jan 2022 13:09:51 -0600 Subject: [PATCH 13/15] Rename default_columns to get_default_columns, and add docstring --- rich/progress.py | 28 +++++++++++++++++++++++++--- tests/test_progress.py | 2 +- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/rich/progress.py b/rich/progress.py index 8b9713c7a..fe35b6c17 100644 --- a/rich/progress.py +++ b/rich/progress.py @@ -588,7 +588,7 @@ def __init__( refresh_per_second is None or refresh_per_second > 0 ), "refresh_per_second must be > 0" self._lock = RLock() - self.columns = columns or self.default_columns() + self.columns = columns or self.get_default_columns() self.speed_estimate_period = speed_estimate_period self.disable = disable @@ -609,7 +609,29 @@ def __init__( self.log = self.console.log @classmethod - def default_columns(cls) -> Tuple[ProgressColumn, ...]: + def get_default_columns(cls) -> Tuple[ProgressColumn, ...]: + """Get the default columns used for a new Progress instance: + - a text column for the description (TextColumn) + - the bar itself (BarColumn) + - a text column showing completion percentage (TextColumn) + - an estimated-time-remaining column (TimeRemainingColumn) + If the Progress instance is created without passing a columns argument, + the default columns defined here will be used. + + You can also create a Progress instance using custom columns before + and/or after the defaults, as in this example: + + progress = Progress( + SpinnerColumn(), + *Progress.default_columns(), + "Elapsed:", + TimeElapsedColumn(), + ) + + This code shows the creation of a Progress display, containing + a spinner to the left, the default columns, and a labeled elapsed + time column. + """ return ( TextColumn("[progress.description]{task.description}"), BarColumn(), @@ -1019,7 +1041,7 @@ def remove_task(self, task_id: TaskID) -> None: with Progress( SpinnerColumn(), - *Progress.default_columns(), + *Progress.get_default_columns(), TimeElapsedColumn(), console=console, transient=True, diff --git a/tests/test_progress.py b/tests/test_progress.py index 876e5d99b..20b9d32ed 100644 --- a/tests/test_progress.py +++ b/tests/test_progress.py @@ -348,7 +348,7 @@ def test_using_default_columns() -> None: progress = Progress( SpinnerColumn(), - *Progress.default_columns(), + *Progress.get_default_columns(), "Elapsed:", TimeElapsedColumn(), ) From e1c595c7e5bd00fc7900471ea13f6de2fa8d165d Mon Sep 17 00:00:00 2001 From: ptmcg Date: Sun, 6 Feb 2022 13:53:06 -0600 Subject: [PATCH 14/15] task._progress change default_factory to create deque(maxlen=1000), to avoid run-time while loop to trim to length 1000 --- rich/progress.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/rich/progress.py b/rich/progress.py index fe35b6c17..115ae8160 100644 --- a/rich/progress.py +++ b/rich/progress.py @@ -475,7 +475,7 @@ class Task: """Optional[float]: The last speed for a finished task.""" _progress: Deque[ProgressSample] = field( - default_factory=deque, init=False, repr=False + default_factory=lambda: deque(maxlen=1000), init=False, repr=False ) _lock: RLock = field(repr=False, default_factory=RLock) @@ -813,8 +813,6 @@ def update( popleft = _progress.popleft while _progress and _progress[0].timestamp < old_sample_time: popleft() - while len(_progress) > 1000: - popleft() if update_completed > 0: _progress.append(ProgressSample(current_time, update_completed)) if task.completed >= task.total and task.finished_time is None: From e4f48cc612e35d2fb6bfe9c8c946a80aa2dad564 Mon Sep 17 00:00:00 2001 From: ptmcg Date: Sun, 6 Feb 2022 14:03:39 -0600 Subject: [PATCH 15/15] Update CONTRIBUTORS.md and CHANGELOG.md with changes related to adding Progress.get_default_columns --- CHANGELOG.md | 1 + CONTRIBUTORS.md | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ece575ab..154decdc2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Add support for US spelling of "gray" in ANSI color names https://github.com/Textualize/rich/issues/1890 +- Added classmethod `Progress.get_default_columns()` to get the default list of progress bar columns https://github.com/Textualize/rich/pull/1894 ## [11.1.0] - 2022-01-28 diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index c29cd7904..0c0f891fd 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -16,6 +16,7 @@ The following people have contributed to the development of Rich: - [Hedy Li](https://github.com/hedythedev) - [Alexander Mancevice](https://github.com/amancevice) - [Will McGugan](https://github.com/willmcgugan) +- [Paul McGuire](https://github.com/ptmcg) - [Nathan Page](https://github.com/nathanrpage97) - [Avi Perl](https://github.com/avi-perl) - [Laurent Peuch](https://github.com/psycojoker)