Debian Codegraph @

docs/source/columns.rst

raw
1 Columns
2 =======
3
4 Rich can render text or other Rich renderables in neat columns with the :class:`~rich.columns.Columns` class. To use, construct a Columns instance with an iterable of renderables and print it to the Console.
5
6 The following example is a very basic clone of the ``ls`` command in OSX / Linux to list directory contents::
7
8 import os
9 import sys
10
11 from rich import print
12 from rich.columns import Columns
13
14 if len(sys.argv) < 2:
15 print("Usage: python columns.py DIRECTORY")
16 else:
17 directory = os.listdir(sys.argv[1])
18 columns = Columns(directory, equal=True, expand=True)
19 print(columns)
20
21
22 See `columns.py <https://github.com/willmcgugan/rich/blob/master/examples/columns.py>`_ for an example which outputs columns containing more than just text.
23