summaryrefslogtreecommitdiff
path: root/docs/features
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2021-10-11 15:20:46 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2021-10-18 13:06:20 -0400
commitf57b08672af97f9d973148b6c30d74fe4e712d14 (patch)
treeb314ff432f7d6a6657f0e8a578c6424487319204 /docs/features
parente35ab9c169eccc7af3e4ec604e2ddd2e668bdc2c (diff)
downloadcmd2-git-f57b08672af97f9d973148b6c30d74fe4e712d14.tar.gz
Added support for 8-bit/256-colors with the cmd2.EightBitFg and cmd2.EightBitBg classes.
Added support for 24-bit/RGB colors with the cmd2.RgbFg and cmd2.RgbBg classes. Removed dependency on colorama. Deprecated cmd2.fg. Use cmd2.Fg instead. Deprecated cmd2.bg. Use cmd2.Bg instead. Changed type of ansi.allow_style from a string to an ansi.AllowStyle Enum class. Fixed bug where using choices on a Settable didn't verify that a valid choice had been entered.
Diffstat (limited to 'docs/features')
-rw-r--r--docs/features/builtin_commands.rst2
-rw-r--r--docs/features/generating_output.rst19
-rw-r--r--docs/features/initialization.rst31
3 files changed, 25 insertions, 27 deletions
diff --git a/docs/features/builtin_commands.rst b/docs/features/builtin_commands.rst
index 97b160b5..eb14e9ab 100644
--- a/docs/features/builtin_commands.rst
+++ b/docs/features/builtin_commands.rst
@@ -106,7 +106,7 @@ within a running application:
Name Value Description
==================================================================================================================
allow_style Terminal Allow ANSI text style sequences in output (valid values:
- Terminal, Always, Never)
+ Always, Never, Terminal)
always_show_hint False Display tab completion hint even when completion suggestions
print
debug True Show full traceback on exception
diff --git a/docs/features/generating_output.rst b/docs/features/generating_output.rst
index d6484c26..7a6f047d 100644
--- a/docs/features/generating_output.rst
+++ b/docs/features/generating_output.rst
@@ -106,21 +106,10 @@ Colored Output
You can add your own `ANSI escape sequences
<https://en.wikipedia.org/wiki/ANSI_escape_code#Colors>`_ to your output which
-tell the terminal to change the foreground and background colors. If you want
-to give yourself a headache, you can generate these by hand. You could also use
-a Python color library like `plumbum.colors
-<https://plumbum.readthedocs.io/en/latest/colors.html>`_, `colored
-<https://gitlab.com/dslackw/colored>`_, or `colorama
-<https://github.com/tartley/colorama>`_. Colorama is unique because when it's
-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 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 text style
-escape codes from a string. These functions are all documentated in
-:mod:`cmd2.ansi`.
+tell the terminal to change the foreground and background colors.
+
+``cmd2`` provides a number of convenience functions and classes for adding
+color and other styles to text. These are all documented in :mod:`cmd2.ansi`.
After adding the desired escape sequences to your output, you should use one of
these methods to present the output to the user:
diff --git a/docs/features/initialization.rst b/docs/features/initialization.rst
index e51f87b2..06967a46 100644
--- a/docs/features/initialization.rst
+++ b/docs/features/initialization.rst
@@ -19,17 +19,26 @@ capabilities which you may wish to utilize while initializing the app::
10) How to make custom attributes settable at runtime
"""
import cmd2
- from cmd2 import style, fg, bg
+ from cmd2 import (
+ Bg,
+ Fg,
+ style,
+ )
+
class BasicApp(cmd2.Cmd):
CUSTOM_CATEGORY = 'My Custom Commands'
def __init__(self):
- super().__init__(multiline_commands=['echo'], persistent_history_file='cmd2_history.dat',
- startup_script='scripts/startup.txt', include_ipy=True)
+ super().__init__(
+ multiline_commands=['echo'],
+ persistent_history_file='cmd2_history.dat',
+ startup_script='scripts/startup.txt',
+ include_ipy=True,
+ )
# Prints an intro banner once upon application startup
- self.intro = style('Welcome to cmd2!', fg=fg.red, bg=bg.white, bold=True)
+ self.intro = style('Welcome to cmd2!', fg=Fg.RED, bg=Bg.WHITE, bold=True)
# Show this as the prompt when asking for input
self.prompt = 'myapp> '
@@ -44,14 +53,13 @@ capabilities which you may wish to utilize while initializing the app::
self.default_category = 'cmd2 Built-in Commands'
# Color to output text in with echo command
- self.foreground_color = 'cyan'
+ self.foreground_color = Fg.CYAN.name.lower()
# Make echo_fg settable at runtime
- self.add_settable(cmd2.Settable('foreground_color',
- str,
- 'Foreground color to use with echo command',
- self,
- choices=fg.colors()))
+ fg_colors = [c.name.lower() for c in Fg]
+ self.add_settable(
+ cmd2.Settable('foreground_color', str, 'Foreground color to use with echo command', self, choices=fg_colors)
+ )
@cmd2.with_category(CUSTOM_CATEGORY)
def do_intro(self, _):
@@ -61,7 +69,8 @@ capabilities which you may wish to utilize while initializing the app::
@cmd2.with_category(CUSTOM_CATEGORY)
def do_echo(self, arg):
"""Example of a multiline command"""
- self.poutput(style(arg, fg=self.foreground_color))
+ fg_color = Fg[self.foreground_color.upper()]
+ self.poutput(style(arg, fg=fg_color))
if __name__ == '__main__':