mirror of
https://github.com/Textualize/rich.git
synced 2025-12-23 07:08:35 +00:00
Merge branch 'master' into case-insensitive-prompt-choices
This commit is contained in:
commit
9038abed04
20 changed files with 77 additions and 61 deletions
2
.github/workflows/codeql.yml
vendored
2
.github/workflows/codeql.yml
vendored
|
|
@ -29,7 +29,7 @@ jobs:
|
|||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
|
|
|
|||
2
.github/workflows/codespell.yml
vendored
2
.github/workflows/codespell.yml
vendored
|
|
@ -4,7 +4,7 @@ jobs:
|
|||
codespell:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- run: python3 -m pip install codespell
|
||||
- run: codespell --ignore-words-list="ba,fo,hel,revered,womens"
|
||||
--skip="./README.*.md,*.svg,*.ai,./benchmarks/snippets.py,./tests,./tools"
|
||||
|
|
|
|||
2
.github/workflows/newissue.yml
vendored
2
.github/workflows/newissue.yml
vendored
|
|
@ -8,7 +8,7 @@ jobs:
|
|||
permissions:
|
||||
issues: write
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
ref: master
|
||||
- name: Install FAQtory
|
||||
|
|
|
|||
2
.github/workflows/pythonpackage.yml
vendored
2
.github/workflows/pythonpackage.yml
vendored
|
|
@ -13,7 +13,7 @@ jobs:
|
|||
run:
|
||||
shell: bash
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
|
|
|
|||
2
.github/workflows/readmechanged.yml
vendored
2
.github/workflows/readmechanged.yml
vendored
|
|
@ -11,7 +11,7 @@ jobs:
|
|||
send_notification:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
- name: Send notification to README Authors
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GHP_README_WORKFLOW }}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
exclude: benchmarks/
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v4.0.1
|
||||
rev: v4.4.0
|
||||
hooks:
|
||||
- id: check-ast
|
||||
- id: check-builtin-literals
|
||||
|
|
@ -17,7 +17,7 @@ repos:
|
|||
- id: check-vcs-permalinks
|
||||
- id: check-shebang-scripts-are-executable
|
||||
- repo: https://github.com/pre-commit/pygrep-hooks
|
||||
rev: v1.9.0
|
||||
rev: v1.10.0
|
||||
hooks:
|
||||
- id: python-check-mock-methods
|
||||
- id: python-no-log-warn
|
||||
|
|
@ -25,12 +25,12 @@ repos:
|
|||
- id: rst-directive-colons
|
||||
- id: rst-inline-touching-normal
|
||||
- repo: https://github.com/hadialqattan/pycln
|
||||
rev: v1.2.5
|
||||
rev: v2.2.2
|
||||
hooks:
|
||||
- id: pycln
|
||||
args: [--all]
|
||||
- repo: https://github.com/psf/black
|
||||
rev: 22.3.0
|
||||
rev: 23.7.0
|
||||
hooks:
|
||||
- id: black
|
||||
exclude: ^benchmarks/
|
||||
|
|
|
|||
11
CHANGELOG.md
11
CHANGELOG.md
|
|
@ -5,13 +5,16 @@ All notable changes to this project will be documented in this file.
|
|||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
|
||||
## [Unreleased]
|
||||
## Unreleased
|
||||
|
||||
### Added
|
||||
|
||||
- Added a `case_insensitive` parameter to `prompt.Prompt`. This allows the
|
||||
`choices` list to be accepted without regard to case. Defaults to `False`.
|
||||
- Adds missing parameters to Panel.fit https://github.com/Textualize/rich/issues/3142
|
||||
- Adds a `case_insensitive` parameter to `prompt.Prompt`. This allows the `choices` list to be accepted without regard to case. Defaults to `False`.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Ensure font is correctly inherited in exported HTML https://github.com/Textualize/rich/issues/3104
|
||||
|
||||
## [13.6.0] - 2023-09-30
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ The following people have contributed to the development of Rich:
|
|||
- [Patrick Arminio](https://github.com/patrick91)
|
||||
- [Gregory Beauregard](https://github.com/GBeauregard/pyffstream)
|
||||
- [Artur Borecki](https://github.com/pufereq)
|
||||
- [Pedro Aaron](https://github.com/paaaron)
|
||||
- [Dennis Brakhane](https://github.com/brakhane)
|
||||
- [Darren Burns](https://github.com/darrenburns)
|
||||
- [Jim Crist-Harif](https://github.com/jcrist)
|
||||
|
|
@ -73,3 +74,4 @@ The following people have contributed to the development of Rich:
|
|||
- [James Addison](https://github.com/jayaddison)
|
||||
- [Pierro](https://github.com/xpierroz)
|
||||
- [Bernhard Wagner](https://github.com/bwagner)
|
||||
- [Aaron Beaudoin](https://github.com/AaronBeaudoin)
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ console.print("Where there is a [bold cyan]Will[/bold cyan] there [u]is[/u] a [i
|
|||
|
||||

|
||||
|
||||
Usted puede usar el objeto Console para generar salida sofisticada con mínimo esfuerzo. Ver la [API Console](https://rich.readthedocs.io/en/latest/console.html) docs para detalles.
|
||||
Usted puede usar el objeto Console para generar salida sofisticada con mínimo esfuerzo. Ver la documentación [API Console](https://rich.readthedocs.io/en/latest/console.html) para detalles.
|
||||
|
||||
## Rich Inspector
|
||||
|
||||
|
|
@ -127,7 +127,7 @@ Rich tiene ua función [inspeccionar](https://rich.readthedocs.io/en/latest/refe
|
|||
|
||||

|
||||
|
||||
Ver la [docs inspector](https://rich.readthedocs.io/en/latest/reference/init.html#rich.inspect) para detalles.
|
||||
Ver la [documentación inspector](https://rich.readthedocs.io/en/latest/reference/init.html#rich.inspect) para detalles.
|
||||
|
||||
# Paquete Rich
|
||||
|
||||
|
|
|
|||
40
README.tr.md
40
README.tr.md
|
|
@ -29,7 +29,7 @@
|
|||
|
||||
Bir Python kütüphanesi olan __rich__, terminal üzerinde gösterişli çıktılar almanızı sağlayan bir araçtır.
|
||||
|
||||
[Rich API](https://rich.readthedocs.io/en/latest/) kullanarak terminal çıktılarınıza sitil ekleyebilir ve renklendirebilirsiniz. Aynı zamanda tabloları, durum çubuklarını, markdown sitillerini, kaynak koddaki syntax gösterimlerini ve bir çok şeyi rich kullanarak yapabilirsiniz.
|
||||
[Rich API](https://rich.readthedocs.io/en/latest/) kullanarak terminal çıktılarınıza stil ekleyebilir ve renklendirebilirsiniz. Aynı zamanda tabloları, ilerleme çubuklarını, markdown stillerini, kaynak koddaki söz dizimi gösterimlerini ve bir çok şeyi rich kullanarak yapabilirsiniz.
|
||||
|
||||

|
||||
|
||||
|
|
@ -39,7 +39,7 @@ Rich'e video ile göz atmak için [@fishnets88](https://twitter.com/fishnets88)
|
|||
|
||||
## Uyumluluk
|
||||
|
||||
Rich Linux, OSX ve Windows üzerinde çalışabilir. Windows'un yeni terminali doğru bir şekilde çalışabilir, eski terminalde 16 renk olduğu için istenilen sonuçlar elde edilemeyebilir. Aynı zamanda Rich'in çalışabilmesi için ortamda minimum Python 3.6.3 veya daha yeni bir sürüm olması gerekmektedir.
|
||||
Rich Linux, OSX ve Windows üzerinde çalışabilir. Windows'un yeni terminalinde de doğru bir şekilde çalışabilir, eski terminalde 16 renk olduğu için istenilen sonuçlar elde edilemeyebilir. Aynı zamanda Rich'in çalışabilmesi için ortamda minimum Python 3.6.3 veya daha yeni bir sürüm olması gerekmektedir.
|
||||
|
||||
Rich [Jupyter notebook](https://jupyter.org/) üzerinde hiç bir ek yükleme gerektirmeden çalışabilir.
|
||||
|
||||
|
|
@ -73,7 +73,7 @@ Buradaki yazıyı değiştiremediğim için siz hello world olarak görüyorsunu
|
|||
|
||||
## Rich REPL
|
||||
|
||||
Rich Python REPL içerisine yüklenebilir, böylece her hangi bir veri tipini güzelce terminal çıktısı olarak verebilir.
|
||||
Rich Python REPL içerisine yüklenebilir, böylece herhangi bir veri tipini güzelce terminal çıktısı olarak verebilir.
|
||||
|
||||
```python
|
||||
>>> from rich import pretty
|
||||
|
|
@ -92,7 +92,7 @@ from rich.console import Console
|
|||
console = Console()
|
||||
```
|
||||
|
||||
Console objesi tıpkı Python içerisinde hazır gelen `print` methoduna benziyor, tabi bir kaç fazlası da var.
|
||||
Console objesi tıpkı Python içerisinde hazır gelen `print` methoduna benziyor, tabii daha fazlası da var.
|
||||
Kullanımı aşağıdaki örnek gibi olacaktır:
|
||||
|
||||
```python
|
||||
|
|
@ -111,7 +111,7 @@ Eğer çıktıyı değiştirmeseydim aşağıdaki gibi bir görüntü ile karş
|
|||
|
||||

|
||||
|
||||
Tek seferde bir yazıyı renklendirmek için kullanışlı bir yöntem olsa da, eğer çıktımızın sadece belirli bölgelerinde değişiklik yapacaksak [bbcode](https://en.wikipedia.org/wiki/BBCode) syntax'ını kullanmalıyız. Bunun içinde bir örnek:
|
||||
Tek seferde bir yazıyı renklendirmek için kullanışlı bir yöntem olsa da, eğer çıktımızın sadece belirli bölgelerinde değişiklik yapacaksak [bbcode](https://en.wikipedia.org/wiki/BBCode) söz dizimini kullanmalıyız. Bunun için de bir örnek:
|
||||
|
||||
```python
|
||||
console.print("[bold red]Mustafa Kemal Atatürk[/bold red] [u](1881 - 10 Kasım 1938)[/u], [i]Türk asker ve devlet adamıdır[/i]. [bold cyan]Türk Kurtuluş Savaşı'nın başkomutanı ve Türkiye Cumhuriyeti'nin kurucusudur[/bold cyan].")
|
||||
|
|
@ -119,7 +119,7 @@ console.print("[bold red]Mustafa Kemal Atatürk[/bold red] [u](1881 - 10 Kasım
|
|||
|
||||

|
||||
|
||||
Console objesini kullanarak sofistike bir çok çıktıyu minimum efor ile oluşturabilirsiniz. [Console API](https://rich.readthedocs.io/en/latest/console.html) dökümanına göz atarak daha fazla bilgi elde edebilirsiniz.
|
||||
Console objesini kullanarak sofistike bir çok çıktıyı minimum efor ile oluşturabilirsiniz. [Console API](https://rich.readthedocs.io/en/latest/console.html) dökümanına göz atarak daha fazla bilgi elde edebilirsiniz.
|
||||
|
||||
## Rich Inspect
|
||||
|
||||
|
|
@ -133,19 +133,19 @@ Rich [inspect](https://rich.readthedocs.io/en/latest/reference/init.html?highlig
|
|||
|
||||

|
||||
|
||||
[Bu dökümana](https://rich.readthedocs.io/en/latest/reference/init.html#rich.inspect) göz atarak daha fazla bilgi elde edebilirsiniz..
|
||||
[Bu dökümana](https://rich.readthedocs.io/en/latest/reference/init.html#rich.inspect) göz atarak daha fazla bilgi elde edebilirsiniz...
|
||||
|
||||
# Rich Kütüphaneleri
|
||||
|
||||
Rich içerisinde çok fazla sayıda terminal üzerinde kullandığınızda çıktılarınızı gösterişli kılacak yapıyalara sahiptir.
|
||||
Rich içerisinde terminal üzerinde kullandığınızda çıktılarınızı gösterişli kılacak çok fazla yapıya sahiptir.
|
||||
|
||||
Bu yapıların detayları için ilgili başlıklara tıklayın:
|
||||
|
||||
<details>
|
||||
<summary>Log</summary>
|
||||
|
||||
Console objesi içerisinde `log()` methodunu barındırır, bu tıpkı `print()` methodu gibi davranır fakat buna ek olarak bastırıldığı zamanı da ekrana yansıtır. Bu duruma ek olarak Rich Syntax Highlighting de gerçekleştirir.
|
||||
Aşağıda örnek kod parçasını:
|
||||
Console objesi içerisinde `log()` methodunu barındırır, bu tıpkı `print()` methodu gibi davranır fakat buna ek olarak bastırıldığı zamanı da ekrana yansıtır. Bu duruma ek olarak Rich Syntax Highlighting'de gerçekleştirir.
|
||||
Aşağıda örnek kod parçası:
|
||||
|
||||
```python
|
||||
from rich.console import Console
|
||||
|
|
@ -196,7 +196,7 @@ Emojileri de kullanabilirsiniz, kullanımı markdown emojileri ile aynı.
|
|||
😃 🧛 💩 👍 🦝
|
||||
```
|
||||
|
||||
Bu özelliği doğru yerlerde kullanmakta fayda var tabi.
|
||||
Bu özelliği doğru yerlerde kullanmakta fayda var tabii.
|
||||
|
||||
</details>
|
||||
|
||||
|
|
@ -258,7 +258,7 @@ Note that console markup is rendered in the same way as `print()` and `log()`. I
|
|||
|
||||
Uzun işlerinizi göstermek için Rich size birden fazla [progress](https://rich.readthedocs.io/en/latest/progress.html) bar sunuyor.
|
||||
|
||||
Basit bir kullanımı için, her hangi bir adımınızı `track` fonksiyonu ile kapsayıp döngüye alın.
|
||||
Basit bir kullanım için, herhangi bir adımınızı `track` fonksiyonu ile kapsayıp döngüye alın.
|
||||
|
||||
```python
|
||||
from rich.progress import track
|
||||
|
|
@ -267,15 +267,15 @@ for step in track(range(100)):
|
|||
do_step(step)
|
||||
```
|
||||
|
||||
Aşağıdaki görsellerde de görüleceği üzere birden fazla kez progress bar kullanabilirsiniz, ve dökümandan da anlışılacağı üzere bu hiç de zor bir iş değil.
|
||||
Aşağıdaki görsellerde de görüleceği üzere birden fazla kez progress bar kullanabilirsiniz, ve dökümandan da anlaşılacağı üzere bu hiç de zor bir iş değil.
|
||||
|
||||

|
||||
|
||||
Kolonlar kullanıcı tarafından ayarlanabilir, indirme hızını, dosya boyutunui yüzdesel olarak gösterimi gibi bir çok şekilde gösterim sağlayabilir.
|
||||
Kolonlar kullanıcı tarafından ayarlanabilir, indirme hızını, dosya boyutunu yüzdesel olarak gösterimi gibi bir çok şekilde gösterim sağlayabilir.
|
||||
|
||||

|
||||
|
||||
Eğer size de denemek siterseniz [examples/downloader.py](https://github.com/textualize/rich/blob/master/examples/downloader.py) koduna bakarak ve çalıştırarak indirme yapabilirsiniz.
|
||||
Eğer siz de denemek isterseniz [examples/downloader.py](https://github.com/textualize/rich/blob/master/examples/downloader.py) koduna bakarak ve çalıştırarak indirme yapabilirsiniz.
|
||||
|
||||
</details>
|
||||
|
||||
|
|
@ -329,7 +329,7 @@ Kodun çıkartacağı görüntü şu olacaktır:
|
|||
|
||||

|
||||
|
||||
[tree.py](https://github.com/textualize/rich/blob/master/examples/tree.py) örnek dosyası ile linux'de bulunan `tree` kodunu rich üzerinden simüle edebilirsiniz.
|
||||
[tree.py](https://github.com/textualize/rich/blob/master/examples/tree.py) örnek dosyası ile linux'da bulunan `tree` kodunu rich üzerinden simüle edebilirsiniz.
|
||||
|
||||
</details>
|
||||
|
||||
|
|
@ -419,9 +419,9 @@ Yukarıdaki kod parçası aşağıdaki gibi bir çıktı üretecektir.
|
|||
<details>
|
||||
<summary>Tracebacks</summary>
|
||||
|
||||
Rich sahip oldukları ile güzel [tracebakcs](https://rich.readthedocs.io/en/latest/traceback.html)'ler yaratabilir. Böylece daha okunabilir ve daha kolay anlaşılabilen bir yapıya sahip olursunuz.
|
||||
Rich sahip olduğu güzel [traceback](https://rich.readthedocs.io/en/latest/traceback.html)'ler yaratabilir. Böylece daha okunabilir ve daha kolay anlaşılabilen bir yapıya sahip olursunuz.
|
||||
|
||||
Burada OSX üzerinde (tıpkı Linux gibi) bir tracebacks çıktısı görüyorsunuz.
|
||||
Burada OSX üzerinde (tıpkı Linux gibi) bir traceback çıktısı görüyorsunuz.
|
||||
|
||||

|
||||
|
||||
|
|
@ -431,7 +431,7 @@ Tüm rich yapıları [Console Protocol](https://rich.readthedocs.io/en/latest/pr
|
|||
|
||||
# Rich CLI
|
||||
|
||||
Aynı zamanda [Rich CLI](https://github.com/textualize/rich-cli) uygulamasını da kontrol edin. Bu uygulama ile konsol çıktılarınızı renklendirebilir, kod çıktılarınıza syntax uygulayabilir, markdown gösterebilir, CSV dosyasını görüntüleyebilir ve bir çok şey daha yapabilirsiniz.
|
||||
Aynı zamanda [Rich CLI](https://github.com/textualize/rich-cli) uygulamasını da kontrol edin. Bu uygulama ile konsol çıktılarınızı renklendirebilir, kod çıktılarınıza syntax uygulayabilir, markdown gösterebilir, CSV dosyasını görüntüleyebilir ve daha bir çok şey yapabilirsiniz.
|
||||
|
||||
|
||||

|
||||
|
|
@ -444,7 +444,7 @@ Rich'in kardeş projesi olan [Textual](https://github.com/Textualize/textual)'a
|
|||
|
||||
# Rich kullanılan Projeler
|
||||
|
||||
[Rich Galeri](https://www.textualize.io/rich/gallery)'si üzerinden, rich kullanılan son uygulamalara [Textualize.io](https://www.textualize.io) üzerinden göz atabiirsiniz.
|
||||
[Rich Galeri](https://www.textualize.io/rich/gallery)si üzerinden, rich kullanılan son uygulamalara [Textualize.io](https://www.textualize.io) üzerinden göz atabiirsiniz.
|
||||
|
||||
Eğer siz de projenizi galeriye eklemek istiyorsanız [bu adımları](https://www.textualize.io/gallery-instructions) takip ederek ekleyebilirsiniz.
|
||||
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ The ``total`` value associated with a task is the number of steps that must be c
|
|||
Updating tasks
|
||||
~~~~~~~~~~~~~~
|
||||
|
||||
When you call :meth:`~rich.progress.Progress.add_task` you get back a `Task ID`. Use this ID to call :meth:`~rich.progress.Progress.update` whenever you have completed some work, or any information has changed. Typically you will need to update ``completed`` every time you have completed a step. You can do this by updated ``completed`` directly or by setting ``advance`` which will add to the current ``completed`` value.
|
||||
When you call :meth:`~rich.progress.Progress.add_task` you get back a `Task ID`. Use this ID to call :meth:`~rich.progress.Progress.update` whenever you have completed some work, or any information has changed. Typically you will need to update ``completed`` every time you have completed a step. You can do this by setting ``completed`` directly or by setting ``advance`` which will add to the current ``completed`` value.
|
||||
|
||||
The :meth:`~rich.progress.Progress.update` method collects keyword arguments which are also associated with the task. Use this to supply any additional information you would like to render in the progress display. The additional arguments are stored in ``task.fields`` and may be referenced in :ref:`Column classes<Columns>`.
|
||||
|
||||
|
|
@ -234,7 +234,7 @@ Here's an example that reads a url from the internet::
|
|||
|
||||
If you expect to be reading from multiple files, you can use :meth:`~rich.progress.Progress.open` or :meth:`~rich.progress.Progress.wrap_file` to add a file progress to an existing Progress instance.
|
||||
|
||||
See `cp_progress.py <https://github.com/willmcgugan/rich/blob/master/examples/cp_progress.py>` for a minimal clone of the ``cp`` command which shows a progress bar as the file is copied.
|
||||
See `cp_progress.py <https://github.com/willmcgugan/rich/blob/master/examples/cp_progress.py>`_ for a minimal clone of the ``cp`` command which shows a progress bar as the file is copied.
|
||||
|
||||
|
||||
Multiple Progress
|
||||
|
|
|
|||
|
|
@ -50,13 +50,13 @@ Table Options
|
|||
|
||||
There are a number of keyword arguments on the Table constructor you can use to define how a table should look.
|
||||
|
||||
- ``title`` Sets the title of the table (text show above the table).
|
||||
- ``caption`` Sets the table caption (text show below the table).
|
||||
- ``title`` Sets the title of the table (text shown above the table).
|
||||
- ``caption`` Sets the table caption (text shown below the table).
|
||||
- ``width`` Sets the desired width of the table (disables automatic width calculation).
|
||||
- ``min_width`` Sets a minimum width for the table.
|
||||
- ``box`` Sets one of the :ref:`appendix_box` styles for the table grid, or ``None`` for no grid.
|
||||
- ``safe_box`` Set to ``True`` to force the table to generate ASCII characters rather than unicode.
|
||||
- ``padding`` An integer, or tuple of 1, 2, or 4 values to set the padding on cells.
|
||||
- ``padding`` An integer, or tuple of 1, 2, or 4 values to set the padding on cells (see :ref:`Padding`).
|
||||
- ``collapse_padding`` If True the padding of neighboring cells will be merged.
|
||||
- ``pad_edge`` Set to False to remove padding around the edge of the table.
|
||||
- ``expand`` Set to True to expand the table to the full available size.
|
||||
|
|
|
|||
|
|
@ -28,12 +28,12 @@ Alternatively, you can construct styled text by calling :meth:`~rich.text.Text.a
|
|||
|
||||
If you would like to use text that is already formatted with ANSI codes, call :meth:`~rich.text.Text.from_ansi` to convert it to a ``Text`` object::
|
||||
|
||||
text = Text.from_ansi("\033[1mHello, World!\033[0m")
|
||||
text = Text.from_ansi("\033[1;35mHello\033[0m, World!")
|
||||
console.print(text.spans)
|
||||
|
||||
Since building Text instances from parts is a common requirement, Rich offers :meth:`~rich.text.Text.assemble` which will combine strings or pairs of string and Style, and return a Text instance. The follow example is equivalent to the code above::
|
||||
Since building Text instances from parts is a common requirement, Rich offers :meth:`~rich.text.Text.assemble` which will combine strings or pairs of string and Style, and return a Text instance. The following example is equivalent to the ANSI example above::
|
||||
|
||||
text = Text.assemble(("Hello", "bold magenta"), " World!")
|
||||
text = Text.assemble(("Hello", "bold magenta"), ", World!")
|
||||
console.print(text)
|
||||
|
||||
You can apply a style to given words in the text with :meth:`~rich.text.Text.highlight_words` or for ultimate control call :meth:`~rich.text.Text.highlight_regex` to highlight text matching a *regular expression*.
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ body {{
|
|||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<pre style="font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace"><code>{code}</code></pre>
|
||||
<pre style="font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace"><code style="font-family:inherit">{code}</code></pre>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
from itertools import zip_longest
|
||||
from typing import (
|
||||
Iterator,
|
||||
TYPE_CHECKING,
|
||||
Iterable,
|
||||
Iterator,
|
||||
List,
|
||||
Optional,
|
||||
TypeVar,
|
||||
Union,
|
||||
overload,
|
||||
TypeVar,
|
||||
TYPE_CHECKING,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
|
@ -119,7 +119,7 @@ class Lines:
|
|||
|
||||
Args:
|
||||
console (Console): Console instance.
|
||||
width (int): Number of characters per line.
|
||||
width (int): Number of cells available per line.
|
||||
justify (str, optional): Default justify method for text: "left", "center", "full" or "right". Defaults to "left".
|
||||
overflow (str, optional): Default overflow for text: "crop", "fold", or "ellipsis". Defaults to "fold".
|
||||
|
||||
|
|
|
|||
|
|
@ -113,7 +113,10 @@ def render(
|
|||
|
||||
Args:
|
||||
markup (str): A string containing console markup.
|
||||
style: (Union[str, Style]): The style to use.
|
||||
emoji (bool, optional): Also render emoji code. Defaults to True.
|
||||
emoji_variant (str, optional): Optional emoji variant, either "text" or "emoji". Defaults to None.
|
||||
|
||||
|
||||
Raises:
|
||||
MarkupError: If there is a syntax error in the markup.
|
||||
|
|
|
|||
|
|
@ -82,7 +82,9 @@ class Panel(JupyterMixin):
|
|||
style: StyleType = "none",
|
||||
border_style: StyleType = "none",
|
||||
width: Optional[int] = None,
|
||||
height: Optional[int] = None,
|
||||
padding: PaddingDimensions = (0, 1),
|
||||
highlight: bool = False,
|
||||
) -> "Panel":
|
||||
"""An alternative constructor that sets expand=False."""
|
||||
return cls(
|
||||
|
|
@ -96,7 +98,9 @@ class Panel(JupyterMixin):
|
|||
style=style,
|
||||
border_style=border_style,
|
||||
width=width,
|
||||
height=height,
|
||||
padding=padding,
|
||||
highlight=highlight,
|
||||
expand=False,
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -986,7 +986,7 @@ if __name__ == "__main__": # pragma: no cover
|
|||
|
||||
from rich import print
|
||||
|
||||
# print(Pretty(data, indent_guides=True, max_string=20))
|
||||
print(Pretty(data, indent_guides=True, max_string=20))
|
||||
|
||||
class Thing:
|
||||
def __repr__(self) -> str:
|
||||
|
|
|
|||
22
rich/text.py
22
rich/text.py
|
|
@ -271,7 +271,9 @@ class Text(JupyterMixin):
|
|||
|
||||
Args:
|
||||
text (str): A string containing console markup.
|
||||
style (Union[str, Style], optional): Base style for text. Defaults to "".
|
||||
emoji (bool, optional): Also render emoji code. Defaults to True.
|
||||
emoji_variant (str, optional): Optional emoji variant, either "text" or "emoji". Defaults to None.
|
||||
justify (str, optional): Justify method: "left", "center", "full", "right". Defaults to None.
|
||||
overflow (str, optional): Overflow method: "crop", "fold", "ellipsis". Defaults to None.
|
||||
end (str, optional): Character to end text with. Defaults to "\\\\n".
|
||||
|
|
@ -369,6 +371,7 @@ class Text(JupyterMixin):
|
|||
style (Union[str, Style], optional): Base style for text. Defaults to "".
|
||||
justify (str, optional): Justify method: "left", "center", "full", "right". Defaults to None.
|
||||
overflow (str, optional): Overflow method: "crop", "fold", "ellipsis". Defaults to None.
|
||||
no_wrap (bool, optional): Disable text wrapping, or None for default. Defaults to None.
|
||||
end (str, optional): Character to end text with. Defaults to "\\\\n".
|
||||
tab_size (int): Number of spaces per tab, or ``None`` to use ``console.tab_size``. Defaults to None.
|
||||
meta (Dict[str, Any], optional). Meta data to apply to text, or None for no meta data. Default to None
|
||||
|
|
@ -424,7 +427,7 @@ class Text(JupyterMixin):
|
|||
self._spans = spans[:]
|
||||
|
||||
def blank_copy(self, plain: str = "") -> "Text":
|
||||
"""Return a new Text instance with copied meta data (but not the string or spans)."""
|
||||
"""Return a new Text instance with copied metadata (but not the string or spans)."""
|
||||
copy_self = Text(
|
||||
plain,
|
||||
style=self.style,
|
||||
|
|
@ -505,7 +508,7 @@ class Text(JupyterMixin):
|
|||
def apply_meta(
|
||||
self, meta: Dict[str, Any], start: int = 0, end: Optional[int] = None
|
||||
) -> None:
|
||||
"""Apply meta data to the text, or a portion of the text.
|
||||
"""Apply metadata to the text, or a portion of the text.
|
||||
|
||||
Args:
|
||||
meta (Dict[str, Any]): A dict of meta information.
|
||||
|
|
@ -634,9 +637,9 @@ class Text(JupyterMixin):
|
|||
"""Highlight words with a style.
|
||||
|
||||
Args:
|
||||
words (Iterable[str]): Worlds to highlight.
|
||||
words (Iterable[str]): Words to highlight.
|
||||
style (Union[str, Style]): Style to apply.
|
||||
case_sensitive (bool, optional): Enable case sensitive matchings. Defaults to True.
|
||||
case_sensitive (bool, optional): Enable case sensitive matching. Defaults to True.
|
||||
|
||||
Returns:
|
||||
int: Number of words highlighted.
|
||||
|
|
@ -823,8 +826,6 @@ class Text(JupyterMixin):
|
|||
if tab_size is None:
|
||||
tab_size = 8
|
||||
|
||||
result = self.blank_copy()
|
||||
|
||||
new_text: List[Text] = []
|
||||
append = new_text.append
|
||||
|
||||
|
|
@ -899,6 +900,7 @@ class Text(JupyterMixin):
|
|||
|
||||
Args:
|
||||
count (int): Width of padding.
|
||||
character (str): The character to pad with. Must be a string of length 1.
|
||||
"""
|
||||
assert len(character) == 1, "Character must be a string of length 1"
|
||||
if count:
|
||||
|
|
@ -1005,6 +1007,9 @@ class Text(JupyterMixin):
|
|||
"""Append another Text instance. This method is more performant that Text.append, but
|
||||
only works for Text.
|
||||
|
||||
Args:
|
||||
text (Text): The Text instance to append to this instance.
|
||||
|
||||
Returns:
|
||||
Text: Returns self for chaining.
|
||||
"""
|
||||
|
|
@ -1026,7 +1031,7 @@ class Text(JupyterMixin):
|
|||
"""Append iterable of str and style. Style may be a Style instance or a str style definition.
|
||||
|
||||
Args:
|
||||
pairs (Iterable[Tuple[str, Optional[StyleType]]]): An iterable of tuples containing str content and style.
|
||||
tokens (Iterable[Tuple[str, Optional[StyleType]]]): An iterable of tuples containing str content and style.
|
||||
|
||||
Returns:
|
||||
Text: Returns self for chaining.
|
||||
|
|
@ -1204,8 +1209,7 @@ class Text(JupyterMixin):
|
|||
|
||||
Args:
|
||||
console (Console): Console instance.
|
||||
width (int): Number of characters per line.
|
||||
emoji (bool, optional): Also render emoji code. Defaults to True.
|
||||
width (int): Number of cells available per line.
|
||||
justify (str, optional): Justify method: "default", "left", "center", "full", "right". Defaults to "default".
|
||||
overflow (str, optional): Overflow method: "crop", "fold", or "ellipsis". Defaults to None.
|
||||
tab_size (int, optional): Default tab size. Defaults to 8.
|
||||
|
|
|
|||
|
|
@ -529,7 +529,7 @@ def test_export_html():
|
|||
console.print("[b]foo <script> 'test' [link=https://example.org]Click[/link]")
|
||||
html = console.export_html()
|
||||
print(repr(html))
|
||||
expected = '<!DOCTYPE html>\n<html>\n<head>\n<meta charset="UTF-8">\n<style>\n.r1 {font-weight: bold}\n.r2 {color: #ff00ff; text-decoration-color: #ff00ff; font-weight: bold}\n.r3 {color: #008000; text-decoration-color: #008000; font-weight: bold}\nbody {\n color: #000000;\n background-color: #ffffff;\n}\n</style>\n</head>\n<body>\n <pre style="font-family:Menlo,\'DejaVu Sans Mono\',consolas,\'Courier New\',monospace"><code><span class="r1">foo <</span><span class="r2">script</span><span class="r1">> </span><span class="r3">'test'</span><span class="r1"> </span><a class="r1" href="https://example.org">Click</a>\n</code></pre>\n</body>\n</html>\n'
|
||||
expected = '<!DOCTYPE html>\n<html>\n<head>\n<meta charset="UTF-8">\n<style>\n.r1 {font-weight: bold}\n.r2 {color: #ff00ff; text-decoration-color: #ff00ff; font-weight: bold}\n.r3 {color: #008000; text-decoration-color: #008000; font-weight: bold}\nbody {\n color: #000000;\n background-color: #ffffff;\n}\n</style>\n</head>\n<body>\n <pre style="font-family:Menlo,\'DejaVu Sans Mono\',consolas,\'Courier New\',monospace"><code style="font-family:inherit"><span class="r1">foo <</span><span class="r2">script</span><span class="r1">> </span><span class="r3">'test'</span><span class="r1"> </span><a class="r1" href="https://example.org">Click</a>\n</code></pre>\n</body>\n</html>\n'
|
||||
assert html == expected
|
||||
|
||||
|
||||
|
|
@ -538,7 +538,7 @@ def test_export_html_inline():
|
|||
console.print("[b]foo [link=https://example.org]Click[/link]")
|
||||
html = console.export_html(inline_styles=True)
|
||||
print(repr(html))
|
||||
expected = '<!DOCTYPE html>\n<html>\n<head>\n<meta charset="UTF-8">\n<style>\n\nbody {\n color: #000000;\n background-color: #ffffff;\n}\n</style>\n</head>\n<body>\n <pre style="font-family:Menlo,\'DejaVu Sans Mono\',consolas,\'Courier New\',monospace"><code><span style="font-weight: bold">foo </span><span style="font-weight: bold"><a href="https://example.org">Click</a></span>\n</code></pre>\n</body>\n</html>\n'
|
||||
expected = '<!DOCTYPE html>\n<html>\n<head>\n<meta charset="UTF-8">\n<style>\n\nbody {\n color: #000000;\n background-color: #ffffff;\n}\n</style>\n</head>\n<body>\n <pre style="font-family:Menlo,\'DejaVu Sans Mono\',consolas,\'Courier New\',monospace"><code style="font-family:inherit"><span style="font-weight: bold">foo </span><span style="font-weight: bold"><a href="https://example.org">Click</a></span>\n</code></pre>\n</body>\n</html>\n'
|
||||
assert html == expected
|
||||
|
||||
|
||||
|
|
@ -591,7 +591,7 @@ def test_save_text():
|
|||
|
||||
|
||||
def test_save_html():
|
||||
expected = "<!DOCTYPE html>\n<html>\n<head>\n<meta charset=\"UTF-8\">\n<style>\n\nbody {\n color: #000000;\n background-color: #ffffff;\n}\n</style>\n</head>\n<body>\n <pre style=\"font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><code>foo\n</code></pre>\n</body>\n</html>\n"
|
||||
expected = '<!DOCTYPE html>\n<html>\n<head>\n<meta charset="UTF-8">\n<style>\n\nbody {\n color: #000000;\n background-color: #ffffff;\n}\n</style>\n</head>\n<body>\n <pre style="font-family:Menlo,\'DejaVu Sans Mono\',consolas,\'Courier New\',monospace"><code style="font-family:inherit">foo\n</code></pre>\n</body>\n</html>\n'
|
||||
console = Console(record=True, width=100)
|
||||
console.print("foo")
|
||||
with tempfile.TemporaryDirectory() as path:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue