summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorkotfu <kotfu@kotfu.net>2019-11-29 16:10:20 -0700
committerkotfu <kotfu@kotfu.net>2019-11-29 16:10:20 -0700
commit029afe48b09bf32001d830c880fb32ca9defb8ef (patch)
tree6239e2b2b198444bc65fa1c50bafb2e7042beec7 /docs
parent965d46bd60557efca3e75cf46c8aa76194c4039b (diff)
downloadcmd2-git-029afe48b09bf32001d830c880fb32ca9defb8ef.tar.gz
Show various options for documenting attributes
Diffstat (limited to 'docs')
-rw-r--r--docs/api/cmd.rst4
-rw-r--r--docs/features/generating_output.rst58
2 files changed, 44 insertions, 18 deletions
diff --git a/docs/api/cmd.rst b/docs/api/cmd.rst
index 4f88101e..ebec17c3 100644
--- a/docs/api/cmd.rst
+++ b/docs/api/cmd.rst
@@ -3,3 +3,7 @@ cmd2.Cmd
.. autoclass:: cmd2.cmd2.Cmd
:members:
+
+ .. attribute:: default_error
+
+
diff --git a/docs/features/generating_output.rst b/docs/features/generating_output.rst
index 16ff044d..58e53962 100644
--- a/docs/features/generating_output.rst
+++ b/docs/features/generating_output.rst
@@ -38,18 +38,25 @@ TODO:
Ordinary Output
---------------
-The ``poutput()`` method is almost like using the Python built-in ``print()``
-function. ``poutput()`` adds two conveniences.
+The :meth:`.cmd2.Cmd.poutput` method is similar to the Python
+`built-in print function <https://docs.python.org/3/library/functions.html#print>`_. :meth:`~cmd2.cmd2.Cmd.poutput` adds two
+conveniences.
-Since users can pipe output to a shell command, it catches ``BrokenPipeError``
-and outputs the contents of ``self.broken_pipe_warning`` to ``stderr``.
-``self.broken_pipe_warning`` defaults to an empty string so this method will
-just swallow the exception. If you want to show some error message, put it in
-``self.broken_pipe_warning`` when you initialize ``Cmd2.cmd``.
+ 1. Since users can pipe output to a shell command, it catches
+ ``BrokenPipeError`` and outputs the contents of
+ ``self.broken_pipe_warning`` to ``stderr``. ``self.broken_pipe_warning``
+ defaults to an empty string so this method will just swallow the exception.
+ If you want to show an error message, put it in
+ ``self.broken_pipe_warning`` when you initialize ``Cmd2.cmd``.
-``poutput()`` also honors the :ref:`features/settings:allow_ansi` setting,
-which controls whether ANSI escape sequences that instruct the terminal to
-colorize output are stripped from the output.
+ 2. It examines and honors the :ref:`features/settings:allow_ansi` setting.
+ See :ref:`features/generating_output:Colored Output` below for more details.
+
+Here's a simple command that shows this method in action::
+
+ def do_echo(self, args):
+ """A simple command showing how poutput() works"""
+ self.poutput(args)
Colored Output
@@ -68,17 +75,35 @@ running on Windows, it wraps ``stdout``, looks for ANSI escape sequences, and
converts them into the appropriate ``win32`` calls to modify the state of the
terminal.
-``cmd2`` imports and uses Colorama and also provides a number of convenience
-methods for generating colorized output, measuring the screen width of
-colorized output, setting the window title in the terminal, and removing ANSI
-escape codes from a string. These functions are all documentated in
-:ref:`api/ansi:cmd2.ansi`.
+``cmd2`` imports and uses Colorama and provides a number of convenience methods
+for generating colorized output, measuring the screen width of colorized
+output, setting the window title in the terminal, and removing ANSI escape
+codes from a string. These functions are all documentated in
+:mod:`cmd2.ansi`.
+
+:mod:`cmd2.cmd2.Cmd` includes an :ref:`features/settings:allow_ansi` setting,
+which controls whether ANSI escape sequences that instruct the terminal to
+colorize output are stripped from the output. The recommended approach is to
+construct your application so that it generates colorized output, and then
+allow your users to use this setting to remove the colorization if they do not
+want it.
+
+Output generated by any of these
+methods will honor the :ref:`features/settings:allow_ansi` setting:
+
+- :meth:`cmd2.cmd2.Cmd.poutput`
+- :meth:`cmd2.cmd2.Cmd.perror`
+- :meth:`cmd2.cmd2.Cmd.pwarning`
+- :meth:`cmd2.cmd2.Cmd.pexcept`
+- :meth:`cmd2.cmd2.Cmd.pfeedback`
+- :meth:`cmd2.cmd2.Cmd.ppaged`
Error Messages
--------------
+
Warning Messages
----------------
@@ -121,6 +146,3 @@ Columnar Output
---------------
Using wcswidth() and ansi.ansi_safe_wcswidth()
-
-
-