From 0dfe1c9e2780469e3a4696e8fb3e6f717a7ebeb7 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 16 Sep 2022 11:09:35 +0200 Subject: Adding upstream version 3.1.0. Signed-off-by: Daniel Baumann --- docs/quickstart.rst | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 docs/quickstart.rst (limited to 'docs/quickstart.rst') diff --git a/docs/quickstart.rst b/docs/quickstart.rst new file mode 100644 index 0000000..83e9ee8 --- /dev/null +++ b/docs/quickstart.rst @@ -0,0 +1,110 @@ +.. _quickstart: + +========== +Quickstart +========== + +This section will go over the basics of terminaltables. + +Make sure that you've already :ref:`installed ` it. + +Table with Default Settings +=========================== + +Let's begin by importing AsciiTable, which just uses ``+``, ``-``, and ``|`` characters. + +.. code-block:: pycon + + >>> from terminaltables import AsciiTable + +Now let's define the table data in a variable called ``data``. We'll do it the long way by creating an empty list +representing the entire table. Then we'll add rows one by one. Each row is a list representing table cells. + +.. code-block:: pycon + + >>> data = [] + >>> data.append(['Row one column one', 'Row one column two']) + >>> data.append(['Row two column one', 'Row two column two']) + >>> data.append(['Row three column one', 'Row three column two']) + +Next we can use AsciiTable to format the table properly and then we can just print it. ``table.table`` gives you just +one long string with newline characters so you can easily print it. + +.. code-block:: pycon + + >>> table = AsciiTable(data) + >>> print table.table + +----------------------+----------------------+ + | Row one column one | Row one column two | + +----------------------+----------------------+ + | Row two column one | Row two column two | + | Row three column one | Row three column two | + +----------------------+----------------------+ + +By default the first row of the table is considered the heading. This can be turned off. + +Changing Table Settings +======================= + +There are more options available to change how your tables are formatted. Say your table doesn't really have a heading +row; all rows are just data. + +.. code-block:: pycon + + >>> table.inner_heading_row_border = False + >>> print table.table + +----------------------+----------------------+ + | Row one column one | Row one column two | + | Row two column one | Row two column two | + | Row three column one | Row three column two | + +----------------------+----------------------+ + +Now you want to add a title to the table: + +.. code-block:: pycon + + >>> table.title = 'My Table' + >>> print table.table + +My Table--------------+----------------------+ + | Row one column one | Row one column two | + | Row two column one | Row two column two | + | Row three column one | Row three column two | + +----------------------+----------------------+ + +Maybe you want lines in between all rows: + +.. code-block:: pycon + + >>> table.inner_row_border = True + >>> print table.table + +My Table--------------+----------------------+ + | Row one column one | Row one column two | + +----------------------+----------------------+ + | Row two column one | Row two column two | + +----------------------+----------------------+ + | Row three column one | Row three column two | + +----------------------+----------------------+ + +There are many more settings available. You can find out more by reading the :ref:`settings` section. Each table style +pretty much shares the same settings but there are a few minor exceptions. Refer to each table style's documentation on +the sidebar. + +Other Table Styles +================== + +Terminaltables comes with a few other table styles than just ``AsciiTable``. All table styles more or less have the same +API. + +.. code-block:: pycon + + >>> from terminaltables import SingleTable + >>> table = SingleTable(data) + >>> print table.table + ┌──────────────────────┬──────────────────────┐ + │ Row one column one │ Row one column two │ + ├──────────────────────┼──────────────────────┤ + │ Row two column one │ Row two column two │ + │ Row three column one │ Row three column two │ + └──────────────────────┴──────────────────────┘ + +You can find documentation for all table styles on the sidebar. -- cgit v1.2.3