diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2020-04-22 01:25:35 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2020-04-22 01:25:35 -0400 |
commit | 92c010d583b52be9728efca25c5f074a594e5392 (patch) | |
tree | 52ab144a7027834ac8abdf9a1bbab582c10e2db8 | |
parent | e1256ccb5a78d8cb3b4f2ab9904d80693b6959c9 (diff) | |
download | cmd2-git-92c010d583b52be9728efca25c5f074a594e5392.tar.gz |
Updating documentation for table creation
-rw-r--r-- | cmd2/table_creator.py | 8 | ||||
-rw-r--r-- | docs/api/index.rst | 1 | ||||
-rw-r--r-- | docs/features/index.rst | 1 | ||||
-rw-r--r-- | docs/features/table_creation.rst | 40 |
4 files changed, 47 insertions, 3 deletions
diff --git a/cmd2/table_creator.py b/cmd2/table_creator.py index b17bf452..70b7c1eb 100644 --- a/cmd2/table_creator.py +++ b/cmd2/table_creator.py @@ -84,14 +84,16 @@ class Column: class TableCreator: """ Base table creation class. This class handles ANSI style sequences and characters with display widths greater than 1 - when performing width calculations. It was designed with the ability to build tables 1 row at a time. This helps + when performing width calculations. It was designed with the ability to build tables one row at a time. This helps when you have large data sets that you don't want to hold in memory or when you receive portions of the data set incrementally. - TableCreator has 1 public method: generate_row() + TableCreator has one public method: generate_row() + This function and the Column class provide all features needed to build tables with headers, borders, colors, horizontal and vertical alignment, and wrapped text. However, it's generally easier to inherit from this class and - implement a more granular API rather than use TableCreator directly. There are examples of this defined after this class. + implement a more granular API rather than use TableCreator directly. There are ready-to-use examples of this + defined after this class. """ def __init__(self, cols: Sequence[Column], *, tab_width: int = 4) -> None: """ diff --git a/docs/api/index.rst b/docs/api/index.rst index 2bb1be2c..7b66a684 100644 --- a/docs/api/index.rst +++ b/docs/api/index.rst @@ -51,4 +51,5 @@ This documentation is for ``cmd2`` version |version|. - :ref:`api/plugin:cmd2.plugin` - data classes for hook methods - :ref:`api/py_bridge:cmd2.py_bridge` - classes for bridging calls from the embedded python environment to the host app +- :ref:`api/table_creator:cmd2.table_creator` - table creation module - :ref:`api/constants:cmd2.constants` - just like it says on the tin diff --git a/docs/features/index.rst b/docs/features/index.rst index dc64badd..efc0fe67 100644 --- a/docs/features/index.rst +++ b/docs/features/index.rst @@ -27,4 +27,5 @@ Features settings shortcuts_aliases_macros startup_commands + table_creation transcripts diff --git a/docs/features/table_creation.rst b/docs/features/table_creation.rst new file mode 100644 index 00000000..08bd5150 --- /dev/null +++ b/docs/features/table_creation.rst @@ -0,0 +1,40 @@ +Table Creation +============== + +``cmd2`` provides a table creation class called +:attr:`cmd2.table_creator.TableCreator`. This class handles ANSI style +sequences and characters with display widths greater than 1 when performing +width calculations. It was designed with the ability to build tables one row at +a time. This helps when you have large data sets that you don't want to hold +in memory or when you receive portions of the data set incrementally. + +``TableCreator`` has one public method: +:attr:`cmd2.table_creator.TableCreator.generate_row()` + +This function and the :attr:`cmd2.table_creator.Column` +class provide all features needed to build tables with headers, borders, +colors, horizontal and vertical alignment, and wrapped text. However, it's +generally easier to inherit from this class and implement a more granular API +rather than use ``TableCreator`` directly. + +The following table classes build upon ``TableCreator`` and are provided in +the :ref:`api/table_creator:cmd2.table_creator` module. They can be used as is +or as examples for how to build your own table classes. + +:attr:`cmd2.table_creator.SimpleTable` - Implementation of TableCreator which +generates a borderless table with an optional divider row after the header. +This class can be used to create the whole table at once or one row at a time. + +:attr:`cmd2.table_creator.BorderedTable` - Implementation of TableCreator which +generates a table with borders around the table and between rows. Borders +between columns can also be toggled. This class can be used to create the whole +table at once or one row at a time. + +:attr:`cmd2.table_creator.AlternatingTable` - Implementation of BorderedTable +which uses background colors to distinguish between rows instead of row border +lines. This class can be used to create the whole table at once or one row at a +time. + +See the table_creation_ example to see these classes in use + +.. _table_creation: https://github.com/python-cmd2/cmd2/blob/master/examples/table_creation.py
\ No newline at end of file |