console


Nameconsole JSON
Version 0.9909 PyPI version JSON
download
home_pagehttps://github.com/mixmastamyk/console
SummaryComprehensive, composable utility library for ANSI terminals. Better, stronger, faster. Tch-tch-tch-tch…
upload_time2024-10-09 23:18:19
maintainerNone
docs_urlNone
authorMike Miller
requires_python>=3.4
licenseLGPL 3
keywords ansi terminal emulator console color detection escape sequence cursor style screen shell xterm
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
::

    ┌───────────────────────────┐
    │   ┏━╸┏━┓┏┓╻┏━┓┏━┓╻  ┏━╸   │
    │   ┃  ┃ ┃┃┗┫┗━┓┃ ┃┃  ┣╸    │
    │   ┗━╸┗━┛╹ ╹┗━┛┗━┛┗━╸┗━╸   │
    └───────────────────────────┘

*Tonight we're gonna party like it's 1979…*

╰─(˙𝀓˙)─╮  ╭─(^0^)─╯



Console
============

.. sidebar:: **Testimonials**

    - *"👍 Ayyyyyy… 👍"—The Fonz*
    - *"DYN-O-MITE!!" —J.J. from Good Times*
    - *“Better… Stronger… Faster” —Oscar Goldman*
    - *"There is nothing we won't try…" —Laverne and Shirley*
    - *"You're gonna eat lightning and crap thunder!"—Mickey Goldmill*
    - *"Nothin' can stand in our way…" —Olivia Newton-John*
    - *"Fightin' the system like a true modern-day Robin Hood" —Waylon Jennings*

|

Yet another package that makes it easy to generate the inline codes used to
display colors and character styles in ANSI-compatible terminals and emulators,
as well as other functionality such clearing screens,
moving cursors,
setting title bars,
and detecting capabilities.

How is this one different?
Well,
it's highly composable and more comprehensive than most.
How does it work?
It's a piece of cake.

    *"Piece of cake?
    Oh, I wish somebody would tell me what that means." —Dr. Huer*


␛\ [1;3m *Hello World* ␛\ [0m
----------------------------------------------------------


There are many flexible ways to use console's styling functionality.
Adding a little color with console might look like one of the snippets below.
Simply, import the styling palettes and go to town.

The entries (or attributes in Python lingo) of each palette can be used in
place of strings and handle everything a string might.
For example:

.. code-block:: python-console

    >>> from console import fg, bg, fx

    >>> fg.green + 'Hello World!' + fg.default
    '\x1b[32mHello World!\x1b[39m'

    >>> f'{fx.dim}Lo-key text:{fx.end}'
    '\x1b[2mLo-key text:\x1b[0m'

    >>> print(fg.red, fx.italic, '♥ Heart', fx.end,
    ...       ' of Glass…', sep='')

    ♥ Heart of Glass…  # ← not styled due to readme limits 😉



FYI, the string  ``'\x1b'`` represents the ASCII Escape character
(``27`` in decimal, ``1b`` hex).
Command ``[32m`` turns the text green
and ``[39m`` back to the default color.
But there's no need to worry about any of that gobbledy-gook.
That's why you're here, right?
See call() form below.


.. note::

    *Apologies, text output can't be styled due to PyPI/github readme
    limitations.
    Try the*
    `Sphinx docs <https://mixmastamyk.bitbucket.io/console/>`_
    *instead.
    When you see "😉" in a comment, that's a reminder you're not getting
    the 'full monty.'*

**Call() Form**


Above, ``fx.end`` is a convenient object to note---\
it ends all styles and fore/background colors at once,
where as ``fg.default`` or ``bg.default`` for example,
resets only the fore or background to its default color.
To avoid that responsibility
(while increasing specificity in what styles are deactivated),
one may also use the call-form instead,
where
`it's automatic <https://youtu.be/y5ybok6ZGXk>`_:

.. code-block:: python-console

    >>> fg.yellow('Far Out!')  # ◂ ends fg-color only
    '\x1b[33mFar Out!\x1b[39m'

    >>> fx.italic('Up ya nose with a rubber hose!')  # ◂ ends italic
    '\x1b[3mUp ya nose with a rubber hose!\x1b[23m'

This is neat because call-form will end *specific* colors/styles and not
interfere with others.

There's also a rich-text printer that handles basic HTML
(and even
`hyperlinks <https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda>`_
if your terminal supports it):

.. code-block:: python-console

    >>> from console.viewers import hprint as print
    >>> print('<i>Hello <b>Woirld!</b> ;-)</i>')

    *Hello Woirld! ;-)*  # 😉


But there's a shitload,^H^H^H^H^H, crap-ton,^H^H^H^H^H
err…
*lot more!*  Kindly read on.


.. _compose:

Composability++
~~~~~~~~~~~~~~~~

    | *We've got a long way to go, and a short time to get there…*
    | *I'm east bound, just watch ol' Bandit run"—Jerry Reed*

Console's palette entry objects are meant to be highly composable and useful in
multiple ways.
For example,
you might like to create your own compound styles to use over and over again.
How to? 
Just add 'em up:

.. ~ They can also be called (remember?) as functions if desired and have "mixin"
.. ~ styles added in as well.
.. ~ The callable form also automatically resets styles to their defaults at the end
.. ~ of each line in the string (to avoid breaking pagers),
.. ~ so those tasks no longer need to be managed manually:

.. code-block:: python-console

    >>> muy_importante = fg.white + fx.bold + bg.red
    >>> print(muy_importante('¡AHORITA!', fx.underline))  # ← mixin

    ¡AHORITA!  # ← not styled due to readme limits 😉

One nice feature---\
when palette objects are combined together as done above,
the list of codes to be rendered is kept on ice until final output as a string.
Meaning, there won't be redundant styling (Select Graphic Rendition) sequences
in the output,
no matter how many you add:

.. code-block:: python

    '\x1b[37;1;41;4m¡AHORITA!\x1b[0m'
    # ⇤-----------⇥  One compound sequence, not four 😎

Styles can be built on the fly as well, if need-be:

.. code-block:: python-console

    >>> print(
    ...   f'{fg.i208 + fx.reverse}Tangerine Dream{fx.end}',  # or
    ...     (fg.i208 + fx.reverse)('Tangerine Dream'),
    ... )
    Tangerine Dream  # 😉

.. rubric:: **Templating**

To build templates,
call a palette entry with placeholder strings,
with (or instead of) text:

.. code-block:: python-console

    >>> sam_template = bg.i22('{}')  # dark green
    >>> print(sam_template.format(' GREEN Eggs… '))

.. code-block:: python-console

    GREEN Eggs…   # No, I do not like… 😉

Other template formats are no problem either,
try ``%s`` or ``${}``.


.. rubric:: **Performance**

*Outta Sight!*

Console is lightweight,
but perhaps you'd like a pre-rendered string to be used in a tight loop for
performance reasons.
Simply use ``str()`` to finalize the output then use it in the loop.

.. code-block:: python-console

    >>> msg = str(muy_importante('¡AHORITA!'))

    >>> for i in range(100_000_000):
    ...     print(msg, end=' ')  # rapidinho, por favor


.. rubric:: **Managers**

Palette entries work as context-managers as well:

.. code-block:: python

    with bg.dodgerblue:
        print('Infield: Garvey, Lopes, Russel, Cey, Yeager')
        print('Outfield: Baker, Monday, Smith')
        print('Coach: Lasorda')


::

                                ⚾
    ¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.⫽⫽¸¸.·´¯`·.¸¸¸.·´¯`·.¸¸¸
                              ⫻⫻    Tok!


Color Palettes
~~~~~~~~~~~~~~~

    *"Looo-king Gooood!"—Chico and the Man*

The color palettes entries may be further broken down into three main
categories of available colors.
Unleash your inner
`Britto <https://web.archive.org/web/20150909152716/http://www.art.com/gallery/id--a266/Romero-Britto-posters.htm>`_
below:

    - Basic, the original 8/16 ANSI named colors
    - Extended, a set of 256 indexed colors
    - "True" or "Direct", a.k.a. 16 million colors, consisting of either:

      - RGB specified colors
      - X11-named colors (built-in), or
      - Webcolors-named colors

As mentioned,
the original palette,
X11,
and Webcolor palettes
may be accessed directly from a palette object by name.
For example:

.. code-block:: python

    # Basic                Comment
    fg.red                # One of the original 8 colors
    fg.lightred           # Another 8 brighter colors w/o bold

    # Truecolor variants
    fg.bisque             # Webcolors or X11 color name
    fg.navyblue           # Webcolors takes precedence, if installed


.. rubric:: Advanced Color Selection

*Specific* palettes/colors may be chosen via a prefix letter and number of digits
(or name) to specify the color.
For example:

.. code-block:: python

    # Extended     Format  Comment
    bg.i_123       iDDD   # Extended/indexed 256-color palette
    bg.n_f0f       nHHH   # Hex to *nearest* indexed color

    # Truecolor
    bg.t_ff00bb    tHHH   # Direct/true color, 3 or 6 digits
    bg.x_navyblue  x_NM   # Force an X11 color name (built-in)
    bg.w_bisque    w_NM   # Force Webcolors, if installed

(The underscores in the attribute names that are numbers are optional.
Choose depending whether brevity or readability are more important to you.)

The assorted truecolor forms are used to specify a color explicitly without
ambiguity—\
X11 and Webcolors
`differ <https://en.wikipedia.org/wiki/X11_color_names#Clashes_between_web_and_X11_colors_in_the_CSS_color_scheme>`_
on a few obscure colors.
Though nothing beats "þe auld" hexdigits for certainty.

.. note::

    Be aware,
    an unrecognized color name or index will result in an ``AttributeError``.


Installen-Sie, Bitte
~~~~~~~~~~~~~~~~~~~~~

.. code-block:: shell

    ⏵ pip3 install --user console

Suggested additional support packages,
some of which may be installed automatically if needed:

.. code-block:: shell

    webcolors             # Moar! color names
    colorama              # Needed for: Windows Version < 10
    jinxed                # terminfo, for SSH *into* Windows


Jah!
While console is cross-platform,
`colorama <https://pypi.python.org/pypi/colorama>`_
will need to be installed and .init() run beforehand to view these examples
under the lame (no-ANSI support) versions of Windows < 10

.. note::

    ``console`` supports Python 3.8 and over by default.
    Sorry, neither 2.X or 1.X is supported.  ``:-P``


Der ``console`` package has recently been tested on:

- Mint Linux 22 (24.04) - Python 3.12

  - xterm, mate-terminal, linux console, fbterm

- MacOS 11.7 - Python 3.12

  - Terminal.app, iTerm2

- Windows 10 - Python 3.7 - 64bit

  - Conhost, WSL, Windows Terminal

- Haiku R1/Beta5 - Python 3.12

Not so recently:

- Ubuntu Linux 20.04 - Python 3.8
- FreeBSD 11 - Python 3.7
- Windows 7 - Python 3.6 - 32 bit + colorama
- Windows XP - Python 3.4 - 32 bit + colorama, ansicon
- MacOS 10.13 - Python 3.6

- Very occasionally on kitty, guake

::

    ¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸¸.·´¯`·.¸¸¸


Package Overview
~~~~~~~~~~~~~~~~~~

    *"Hey, Mr. Kot-tair!"—Freddie "Boom Boom" Washington*

As mentioned,
console handles lots more than color and styles.

.. rubric:: **Utils Module**

`console.utils`
includes a number of nifty functions:

.. code-block:: python-console

    >>> from console.utils import cls, set_title

    >>> cls()  # whammo! a.k.a. clear screen, scrollback
    >>> set_title('Le Freak')  # c'est chic
    '\x1b]2;Le Freak\x07'

It can also ``strip_ansi`` from strings,
wait for keypresses,
clear a line or the screen (with or without scrollback),
make hyperlinks,
or easily ``pause`` a script like the old ``DOS`` commands of yesteryear.

There are also modules to print stylish progress bars:
`console.progress`,
or beep up a storm with
`console.beep`.


.. rubric:: **Screen Module**

With `console.screen` you can
save, create a new, or restore a screen.
Move the cursor around,
get its position,
and enable
`bracketed paste <https://cirw.in/blog/bracketed-paste>`_
if any of that floats your boat. 
`Blessings <https://pypi.org/project/blessings/>`_-\
compatible context managers are available for full-screen fun.

.. code-block:: python-console

    >>> from console.screen import sc

    >>> with sc.location(40, 20):
    ...     print('Hello, Woild.')


.. rubric:: **Detection Module**

Detect the terminal environment with
`console.detection`:

    - Determine palette support
    - Redirection---is this an interactive "``tty``" or not?
    - Check relevant user preferences through environment variables,
      such as
      `NO_COLOR <http://no-color.org/>`_,
      `COLORFGBG <https://unix.stackexchange.com/q/245378/159110>`_,
      and
      `CLICOLOR <https://bixense.com/clicolors/>`_,
      and even
      `TERM <https://www.gnu.org/software/gettext/manual/html_node/The-TERM-variable.html>`_.
    - Query terminal colors and themes—light or dark?
    - Get titles, cursor position, and more.
    - Legacy Windows routines are in `console.windows`

Console does its best to figure out what your terminal supports on startup
and will configure its convenience objects
(we imported above)
to do the right thing.
They will *deactivate themselves automatically* at startup when output is
redirected into a pipe,
for example.

Detection can be bypassed and handled manually when needed however.
Simply use the detection functions in the module or write your own as desired,
then create your own objects from the classes in the
`console.style` and
`console.screen`
modules.
(See the Environment Variables section for full deactivation.)

There's also logging done—\
enable the debug level before loading the console package and you'll see the
results of the queries from the detection module.
See below for a ready-made CLI example.


.. rubric:: **Constants**

A number of useful constants are provided in
`console.constants`,
such as
`CSI <https://en.wikipedia.org/wiki/ANSI_escape_code#Escape_sequences>`_
and
`OSC <https://en.wikipedia.org/wiki/ANSI_escape_code#Escape_sequences>`_
for building your own apps.
You can:

.. code-block:: python

    from console.constants import BEL

    print(f'Ring my {BEL}… Ring my {BEL}')  # ring-a-ling-a-ling…


.. rubric:: **ASCII Table, and Command-Line Interface**

A four-column ASCII table in fruity flavors is provided for your convenience
and learning opportunities.
This format is great for spotting Control key correspondence with letters,
e.g.: Ctrl+M=Enter, Ctrl+H=Backspace, etc.

This might be a good time for a quick mention of the console command-line
program that runs quite a few of these utility functions and methods:

.. code-block:: shell

    ⏵ console ascii --link

    00111   7 07  BEL         39 27  \'           71 47  G          103 67  g
    ...  # 😉

Remember the detection CLI we mentioned above?  Here's how to use it:

.. code-block:: shell

    ⏵ console detect -v


.. rubric:: **The Rest**

See the Advanced page for more details.


Demos and Tests
~~~~~~~~~~~~~~~~

    *"I got chills, they're multiplyin'…"—Danny Zuko*

A series of positively jaw-dropping demos (haha, ok maybe not) may be run at
the command-line with::

    ⏵ python3 -m console.demos

If you have pytest installed,
tests can be run from the install folder.

.. code-block:: shell

    ⏵ pytest --color=no --showlocals --verbose

The Makefile in the repo
`at github <https://github.com/mixmastamyk/console>`_
has more details on such topics.


WRapping Up
----------------

    *(image missing)*  # 😉

With a brand-new new sound called *hip hop.*


Contributions
~~~~~~~~~~~~~~~~

*"Use the Source, Luke!"—'Ben' Kenobi*

Could use some help testing on Windows and MacOS as my daily driver is a 🐧 Tux
racer.
Can you help?


Release Notes
~~~~~~~~~~~~~~~~

Breakages: should be rare before 1.0 and non-existent afterwards.

- Version 0.9909 - Pyupgrade to 3.8 idioms, probably doesn't fully support 3.6
  any longer.

- Version 0.9908 - Apologies, the progress bar has changed from a 0-99 scale to
  a 0-100.  Perhaps should use 0-1 ?

- Version 0.9907 - Apologies, the Screen class will have a few changes in the
  names of attributes to make them more consistent.
  Stick with 0.9906 until older code can be ported.


Documentation
~~~~~~~~~~~~~~~~

Additional docs may be found
`over/here at bitbucket. <https://mixmastamyk.bitbucket.io/console/>`_


Legalese
~~~~~~~~~~~~~~~~

*"Stickin' it to the Man"*

- Copyright 2018-2025, Mike Miller
- Released under the LGPL, version 3+.
- Enterprise Pricing:

  | 6 MEEllion dollars…  *Bwah-haha-ha!*
  | (only need to sell *one* copy!)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/mixmastamyk/console",
    "name": "console",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.4",
    "maintainer_email": null,
    "keywords": "ansi terminal emulator console color detection escape sequence cursor style screen shell xterm",
    "author": "Mike Miller",
    "author_email": "mixmastamyk@github.com",
    "download_url": "https://files.pythonhosted.org/packages/d9/c5/a8ffbf0fa4b712b3baaed3bc30ec1cbf4e462cc4958684c6283ed0ba163b/console-0.9909.tar.gz",
    "platform": null,
    "description": "\n::\n\n    \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n    \u2502   \u250f\u2501\u2578\u250f\u2501\u2513\u250f\u2513\u257b\u250f\u2501\u2513\u250f\u2501\u2513\u257b  \u250f\u2501\u2578   \u2502\n    \u2502   \u2503  \u2503 \u2503\u2503\u2517\u252b\u2517\u2501\u2513\u2503 \u2503\u2503  \u2523\u2578    \u2502\n    \u2502   \u2517\u2501\u2578\u2517\u2501\u251b\u2579 \u2579\u2517\u2501\u251b\u2517\u2501\u251b\u2517\u2501\u2578\u2517\u2501\u2578   \u2502\n    \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n\n*Tonight we're gonna party like it's 1979\u2026*\n\n\u2570\u2500(\u02d9\ud834\udc13\u02d9)\u2500\u256e  \u256d\u2500(\uff3e0\uff3e)\u2500\u256f\n\n\n\nConsole\n============\n\n.. sidebar:: **Testimonials**\n\n    - *\"\ud83d\udc4d Ayyyyyy\u2026 \ud83d\udc4d\"\u2014The\u00a0Fonz*\n    - *\"DYN-O-MITE!!\" \u2014J.J.\u00a0from\u00a0Good\u00a0Times*\n    - *\u201cBetter\u2026 Stronger\u2026 Faster\u201d \u2014Oscar\u00a0Goldman*\n    - *\"There is nothing we won't try\u2026\" \u2014Laverne\u00a0and\u00a0Shirley*\n    - *\"You're gonna eat lightning and crap thunder!\"\u2014Mickey Goldmill*\n    - *\"Nothin' can stand in our way\u2026\" \u2014Olivia\u00a0Newton-John*\n    - *\"Fightin' the system like a true modern-day Robin Hood\" \u2014Waylon\u00a0Jennings*\n\n|\n\nYet another package that makes it easy to generate the inline codes used to\ndisplay colors and character styles in ANSI-compatible terminals and emulators,\nas well as other functionality such clearing screens,\nmoving cursors,\nsetting title bars,\nand detecting capabilities.\n\nHow is this one different?\nWell,\nit's highly composable and more comprehensive than most.\nHow does it work?\nIt's a piece of cake.\n\n    *\"Piece of cake?\n    Oh, I wish somebody would tell me what that means.\" \u2014Dr. Huer*\n\n\n\u241b\\ [1;3m *Hello World* \u241b\\ [0m\n----------------------------------------------------------\n\n\nThere are many flexible ways to use console's styling functionality.\nAdding a little color with console might look like one of the snippets below.\nSimply, import the styling palettes and go to town.\n\nThe entries (or attributes in Python lingo) of each palette can be used in\nplace of strings and handle everything a string might.\nFor example:\n\n.. code-block:: python-console\n\n    >>> from console import fg, bg, fx\n\n    >>> fg.green + 'Hello World!' + fg.default\n    '\\x1b[32mHello World!\\x1b[39m'\n\n    >>> f'{fx.dim}Lo-key text:{fx.end}'\n    '\\x1b[2mLo-key text:\\x1b[0m'\n\n    >>> print(fg.red, fx.italic, '\u2665 Heart', fx.end,\n    ...       ' of Glass\u2026', sep='')\n\n    \u2665 Heart of Glass\u2026  # \u2190 not styled due to readme limits \ud83d\ude09\n\n\n\nFYI, the string  ``'\\x1b'`` represents the ASCII Escape character\n(``27`` in decimal, ``1b`` hex).\nCommand ``[32m`` turns the text green\nand ``[39m`` back to the default color.\nBut there's no need to worry about any of that gobbledy-gook.\nThat's why you're here, right?\nSee call() form below.\n\n\n.. note::\n\n    *Apologies, text output can't be styled due to PyPI/github readme\n    limitations.\n    Try the*\n    `Sphinx docs <https://mixmastamyk.bitbucket.io/console/>`_\n    *instead.\n    When you see \"\ud83d\ude09\" in a comment, that's a reminder you're not getting\n    the 'full monty.'*\n\n**Call() Form**\n\n\nAbove, ``fx.end`` is a convenient object to note---\\\nit ends all styles and fore/background colors at once,\nwhere as ``fg.default`` or ``bg.default`` for example,\nresets only the fore or background to its default color.\nTo avoid that responsibility\n(while increasing specificity in what styles are deactivated),\none may also use the call-form instead,\nwhere\n`it's automatic <https://youtu.be/y5ybok6ZGXk>`_:\n\n.. code-block:: python-console\n\n    >>> fg.yellow('Far Out!')  # \u25c2 ends fg-color only\n    '\\x1b[33mFar Out!\\x1b[39m'\n\n    >>> fx.italic('Up ya nose with a rubber hose!')  # \u25c2 ends italic\n    '\\x1b[3mUp ya nose with a rubber hose!\\x1b[23m'\n\nThis is neat because call-form will end *specific* colors/styles and not\ninterfere with others.\n\nThere's also a rich-text printer that handles basic HTML\n(and even\n`hyperlinks <https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda>`_\nif your terminal supports it):\n\n.. code-block:: python-console\n\n    >>> from console.viewers import hprint as print\n    >>> print('<i>Hello <b>Woirld!</b> ;-)</i>')\n\n    *Hello Woirld! ;-)*  # \ud83d\ude09\n\n\nBut there's a shitload,^H^H^H^H^H, crap-ton,^H^H^H^H^H\nerr\u2026\n*lot more!*\u00a0 Kindly read on.\n\n\n.. _compose:\n\nComposability++\n~~~~~~~~~~~~~~~~\n\n    | *We've got a long way to go, and a short time to get there\u2026*\n    | *I'm east bound, just watch ol' Bandit run\"\u2014Jerry Reed*\n\nConsole's palette entry objects are meant to be highly composable and useful in\nmultiple ways.\nFor example,\nyou might like to create your own compound styles to use over and over again.\nHow to?\u00a0\nJust add 'em up:\n\n.. ~ They can also be called (remember?) as functions if desired and have \"mixin\"\n.. ~ styles added in as well.\n.. ~ The callable form also automatically resets styles to their defaults at the end\n.. ~ of each line in the string (to avoid breaking pagers),\n.. ~ so those tasks no longer need to be managed manually:\n\n.. code-block:: python-console\n\n    >>> muy_importante = fg.white + fx.bold + bg.red\n    >>> print(muy_importante('\u00a1AHORITA!', fx.underline))  # \u2190 mixin\n\n    \u00a1AHORITA!  # \u2190 not styled due to readme limits \ud83d\ude09\n\nOne nice feature---\\\nwhen palette objects are combined together as done above,\nthe list of codes to be rendered is kept on ice until final output as a string.\nMeaning, there won't be redundant styling (Select Graphic Rendition) sequences\nin the output,\nno matter how many you add:\n\n.. code-block:: python\n\n    '\\x1b[37;1;41;4m\u00a1AHORITA!\\x1b[0m'\n    # \u21e4-----------\u21e5  One compound sequence, not four \ud83d\ude0e\n\nStyles can be built on the fly as well, if need-be:\n\n.. code-block:: python-console\n\n    >>> print(\n    ...   f'{fg.i208 + fx.reverse}Tangerine Dream{fx.end}',  # or\n    ...     (fg.i208 + fx.reverse)('Tangerine Dream'),\n    ... )\n    Tangerine Dream  # \ud83d\ude09\n\n.. rubric:: **Templating**\n\nTo build templates,\ncall a palette entry with placeholder strings,\nwith (or instead of) text:\n\n.. code-block:: python-console\n\n    >>> sam_template = bg.i22('{}')  #\u00a0dark green\n    >>> print(sam_template.format(' GREEN Eggs\u2026 '))\n\n.. code-block:: python-console\n\n    GREEN Eggs\u2026   # No, I do not like\u2026 \ud83d\ude09\n\nOther template formats are no problem either,\ntry ``%s`` or ``${}``.\n\n\n.. rubric:: **Performance**\n\n*Outta Sight!*\n\nConsole is lightweight,\nbut perhaps you'd like a pre-rendered string to be used in a tight loop for\nperformance reasons.\nSimply use ``str()`` to finalize the output then use it in the loop.\n\n.. code-block:: python-console\n\n    >>> msg = str(muy_importante('\u00a1AHORITA!'))\n\n    >>> for i in range(100_000_000):\n    ...     print(msg, end=' ')  # rapidinho, por favor\n\n\n.. rubric:: **Managers**\n\nPalette entries work as context-managers as well:\n\n.. code-block:: python\n\n    with bg.dodgerblue:\n        print('Infield: Garvey, Lopes, Russel, Cey, Yeager')\n        print('Outfield: Baker, Monday, Smith')\n        print('Coach: Lasorda')\n\n\n::\n\n                                \u26be\n    \u00b8\u00b8.\u00b7\u00b4\u00af`\u00b7.\u00b8\u00b8.\u00b7\u00b4\u00af`\u00b7.\u00b8\u00b8.\u00b7\u00b4\u00af`\u00b7.\u2afd\u2afd\u00b8\u00b8.\u00b7\u00b4\u00af`\u00b7.\u00b8\u00b8\u00b8.\u00b7\u00b4\u00af`\u00b7.\u00b8\u00b8\u00b8\n                              \u2afb\u2afb    Tok!\n\n\nColor Palettes\n~~~~~~~~~~~~~~~\n\n    *\"Looo-king Gooood!\"\u2014Chico and the Man*\n\nThe color palettes entries may be further broken down into three main\ncategories of available colors.\nUnleash your inner\n`Britto <https://web.archive.org/web/20150909152716/http://www.art.com/gallery/id--a266/Romero-Britto-posters.htm>`_\nbelow:\n\n    - Basic, the original 8/16 ANSI\u00a0named colors\n    - Extended, a set of 256 indexed colors\n    - \"True\" or \"Direct\", a.k.a. 16 million colors, consisting of either:\n\n      - RGB specified colors\n      - X11-named colors (built-in), or\n      - Webcolors-named colors\n\nAs mentioned,\nthe original palette,\nX11,\nand Webcolor palettes\nmay be accessed directly from a palette object by name.\nFor example:\n\n.. code-block:: python\n\n    # Basic                Comment\n    fg.red                # One of the original 8 colors\n    fg.lightred           # Another 8 brighter colors w/o bold\n\n    # Truecolor variants\n    fg.bisque             # Webcolors or X11 color name\n    fg.navyblue           # Webcolors takes precedence, if installed\n\n\n.. rubric:: Advanced Color Selection\n\n*Specific* palettes/colors may be chosen via a prefix letter and number of digits\n(or name) to specify the color.\nFor example:\n\n.. code-block:: python\n\n    # Extended     Format  Comment\n    bg.i_123       iDDD   # Extended/indexed 256-color palette\n    bg.n_f0f       nHHH   # Hex to *nearest* indexed color\n\n    # Truecolor\n    bg.t_ff00bb    tHHH   # Direct/true color, 3 or 6 digits\n    bg.x_navyblue  x_NM   # Force an X11 color name (built-in)\n    bg.w_bisque    w_NM   # Force Webcolors, if installed\n\n(The underscores in the attribute names that are numbers are optional.\nChoose depending whether brevity or readability are more important to you.)\n\nThe assorted truecolor forms are used to specify a color explicitly without\nambiguity\u2014\\\nX11 and Webcolors\n`differ <https://en.wikipedia.org/wiki/X11_color_names#Clashes_between_web_and_X11_colors_in_the_CSS_color_scheme>`_\non a few obscure colors.\nThough nothing beats \"\u00fee auld\" hexdigits for certainty.\n\n.. note::\n\n    Be aware,\n    an unrecognized color name or index will result in an ``AttributeError``.\n\n\nInstallen-Sie, Bitte\n~~~~~~~~~~~~~~~~~~~~~\n\n.. code-block:: shell\n\n    \u23f5 pip3 install --user console\n\nSuggested additional support packages,\nsome of which may be installed automatically if needed:\n\n.. code-block:: shell\n\n    webcolors             #\u00a0Moar! color names\n    colorama              # Needed for: Windows Version < 10\n    jinxed                # terminfo, for SSH *into* Windows\n\n\nJah!\nWhile console is cross-platform,\n`colorama <https://pypi.python.org/pypi/colorama>`_\nwill need to be installed and .init() run beforehand to view these examples\nunder the lame (no-ANSI support) versions of Windows < 10\n\n.. note::\n\n    ``console`` supports Python 3.8 and over by default.\n    Sorry, neither 2.X or 1.X is supported.\u00a0 ``:-P``\n\n\nDer ``console`` package has recently been tested on:\n\n- Mint Linux 22 (24.04) - Python 3.12\n\n  - xterm, mate-terminal, linux console, fbterm\n\n- MacOS 11.7 - Python 3.12\n\n  - Terminal.app, iTerm2\n\n- Windows 10 - Python 3.7 - 64bit\n\n  - Conhost, WSL, Windows Terminal\n\n- Haiku R1/Beta5 - Python 3.12\n\nNot so recently:\n\n- Ubuntu Linux 20.04 - Python 3.8\n- FreeBSD 11 - Python 3.7\n- Windows 7 - Python 3.6 - 32 bit + colorama\n- Windows XP - Python 3.4 - 32 bit + colorama, ansicon\n- MacOS 10.13 - Python 3.6\n\n- Very occasionally on kitty, guake\n\n::\n\n    \u00b8\u00b8.\u00b7\u00b4\u00af`\u00b7.\u00b8\u00b8.\u00b7\u00b4\u00af`\u00b7.\u00b8\u00b8.\u00b7\u00b4\u00af`\u00b7.\u00b8\u00b8.\u00b7\u00b4\u00af`\u00b7.\u00b8\u00b8\u00b8.\u00b7\u00b4\u00af`\u00b7.\u00b8\u00b8\u00b8\n\n\nPackage Overview\n~~~~~~~~~~~~~~~~~~\n\n    *\"Hey, Mr. Kot-tair!\"\u2014Freddie \"Boom Boom\" Washington*\n\nAs mentioned,\nconsole handles lots more than color and styles.\n\n.. rubric:: **Utils Module**\n\n`console.utils`\nincludes a number of nifty functions:\n\n.. code-block:: python-console\n\n    >>> from console.utils import cls, set_title\n\n    >>> cls()  #\u00a0whammo! a.k.a. clear screen, scrollback\n    >>> set_title('Le Freak')  # c'est chic\n    '\\x1b]2;Le Freak\\x07'\n\nIt can also ``strip_ansi`` from strings,\nwait for keypresses,\nclear a line or the screen (with or without scrollback),\nmake hyperlinks,\nor easily ``pause`` a script like the old ``DOS``\u00a0commands of yesteryear.\n\nThere are also modules to print stylish progress bars:\n`console.progress`,\nor beep up a storm with\n`console.beep`.\n\n\n.. rubric:: **Screen Module**\n\nWith `console.screen` you can\nsave, create a new, or restore a screen.\nMove the cursor around,\nget its position,\nand enable\n`bracketed paste <https://cirw.in/blog/bracketed-paste>`_\nif any of that floats your boat.\u00a0\n`Blessings <https://pypi.org/project/blessings/>`_-\\\ncompatible context managers are available for full-screen fun.\n\n.. code-block:: python-console\n\n    >>> from console.screen import sc\n\n    >>> with sc.location(40, 20):\n    ...     print('Hello, Woild.')\n\n\n.. rubric:: **Detection Module**\n\nDetect the terminal environment with\n`console.detection`:\n\n    - Determine palette support\n    - Redirection---is this an interactive \"``tty``\" or not?\n    - Check relevant user preferences through environment variables,\n      such as\n      `NO_COLOR <http://no-color.org/>`_,\n      `COLORFGBG <https://unix.stackexchange.com/q/245378/159110>`_,\n      and\n      `CLICOLOR <https://bixense.com/clicolors/>`_,\n      and even\n      `TERM <https://www.gnu.org/software/gettext/manual/html_node/The-TERM-variable.html>`_.\n    - Query terminal colors and themes\u2014light or dark?\n    - Get titles, cursor position, and more.\n    - Legacy Windows routines are in `console.windows`\n\nConsole does its best to figure out what your terminal supports on startup\nand will configure its convenience objects\n(we imported above)\nto do the right thing.\nThey will *deactivate themselves automatically* at startup when output is\nredirected into a pipe,\nfor example.\n\nDetection can be bypassed and handled manually when needed however.\nSimply use the detection functions in the module or write your own as desired,\nthen create your own objects from the classes in the\n`console.style` and\n`console.screen`\nmodules.\n(See the Environment Variables section for full deactivation.)\n\nThere's also logging done\u2014\\\nenable the debug level before loading the console package and you'll see the\nresults of the queries from the detection module.\nSee below for a ready-made CLI example.\n\n\n.. rubric:: **Constants**\n\nA number of useful constants are provided in\n`console.constants`,\nsuch as\n`CSI <https://en.wikipedia.org/wiki/ANSI_escape_code#Escape_sequences>`_\nand\n`OSC <https://en.wikipedia.org/wiki/ANSI_escape_code#Escape_sequences>`_\nfor building your own apps.\nYou can:\n\n.. code-block:: python\n\n    from console.constants import BEL\n\n    print(f'Ring my {BEL}\u2026 Ring my {BEL}')  # ring-a-ling-a-ling\u2026\n\n\n.. rubric:: **ASCII Table, and Command-Line Interface**\n\nA four-column ASCII table in fruity flavors is provided for your convenience\nand learning opportunities.\nThis format is great for spotting Control key correspondence with letters,\ne.g.: Ctrl+M=Enter, Ctrl+H=Backspace, etc.\n\nThis might be a good time for a quick mention of the console command-line\nprogram that runs quite a few of these utility functions and methods:\n\n.. code-block:: shell\n\n    \u23f5 console ascii --link\n\n    00111   7 07  BEL         39 27  \\'           71 47  G          103 67  g\n    ...  # \ud83d\ude09\n\nRemember the detection CLI we mentioned above?  Here's how to use it:\n\n.. code-block:: shell\n\n    \u23f5 console detect -v\n\n\n.. rubric:: **The Rest**\n\nSee the Advanced page for more details.\n\n\nDemos and Tests\n~~~~~~~~~~~~~~~~\n\n    *\"I got chills, they're multiplyin'\u2026\"\u2014Danny Zuko*\n\nA series of positively jaw-dropping demos (haha, ok maybe not) may be run at\nthe command-line with::\n\n    \u23f5 python3 -m console.demos\n\nIf you have pytest installed,\ntests can be run from the install folder.\n\n.. code-block:: shell\n\n    \u23f5 pytest --color=no --showlocals --verbose\n\nThe Makefile in the repo\n`at github <https://github.com/mixmastamyk/console>`_\nhas more details on such topics.\n\n\nWRapping Up\n----------------\n\n    *(image missing)*  # \ud83d\ude09\n\nWith a brand-new new sound called *hip hop.*\n\n\nContributions\n~~~~~~~~~~~~~~~~\n\n*\"Use the Source, Luke!\"\u2014'Ben' Kenobi*\n\nCould use some help testing on Windows and MacOS as my daily driver is a \ud83d\udc27 Tux\nracer.\nCan you help?\n\n\nRelease Notes\n~~~~~~~~~~~~~~~~\n\nBreakages: should be rare before 1.0 and non-existent afterwards.\n\n- Version 0.9909 - Pyupgrade to 3.8 idioms, probably doesn't fully support 3.6\n  any longer.\n\n- Version 0.9908 - Apologies, the progress bar has changed from a 0-99 scale to\n  a 0-100.  Perhaps should use 0-1 ?\n\n- Version 0.9907 - Apologies, the Screen class will have a few changes in the\n  names of attributes to make them more consistent.\n  Stick with 0.9906 until older code can be ported.\n\n\nDocumentation\n~~~~~~~~~~~~~~~~\n\nAdditional docs may be found\n`over/here at bitbucket. <https://mixmastamyk.bitbucket.io/console/>`_\n\n\nLegalese\n~~~~~~~~~~~~~~~~\n\n*\"Stickin' it to the Man\"*\n\n- Copyright 2018-2025, Mike Miller\n- Released under the LGPL, version 3+.\n- Enterprise Pricing:\n\n  | 6 MEEllion dollars\u2026  *Bwah-haha-ha!*\n  | (only need to sell *one* copy!)\n",
    "bugtrack_url": null,
    "license": "LGPL 3",
    "summary": "Comprehensive, composable utility library for ANSI terminals. Better, stronger, faster.  Tch-tch-tch-tch\u2026",
    "version": "0.9909",
    "project_urls": {
        "Documentation": "https://mixmastamyk.bitbucket.io/console/",
        "Homepage": "https://github.com/mixmastamyk/console",
        "Issues": "https://github.com/mixmastamyk/console/issues",
        "Repository": "https://github.com/mixmastamyk/console"
    },
    "split_keywords": [
        "ansi",
        "terminal",
        "emulator",
        "console",
        "color",
        "detection",
        "escape",
        "sequence",
        "cursor",
        "style",
        "screen",
        "shell",
        "xterm"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "05e67de760928add0aa4fcf1157e4e38cb3e7dd8c0c3eeab94c3a32b1ee240ea",
                "md5": "f322347b98ce06f7923cca5ee7df416a",
                "sha256": "376a03b786bedb73f5a063a1d852d0d2d353e03d82d23aa87ce31d1e963df124"
            },
            "downloads": -1,
            "filename": "console-0.9909-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f322347b98ce06f7923cca5ee7df416a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.4",
            "size": 96071,
            "upload_time": "2024-10-09T23:18:17",
            "upload_time_iso_8601": "2024-10-09T23:18:17.039296Z",
            "url": "https://files.pythonhosted.org/packages/05/e6/7de760928add0aa4fcf1157e4e38cb3e7dd8c0c3eeab94c3a32b1ee240ea/console-0.9909-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d9c5a8ffbf0fa4b712b3baaed3bc30ec1cbf4e462cc4958684c6283ed0ba163b",
                "md5": "d5484a2c86ad21b2ac6dcd1eb924feae",
                "sha256": "b9f26a019a67b0a7ce6c22d4b0e37ab500ec87b90ed4ac4dfcc7fad1570bca67"
            },
            "downloads": -1,
            "filename": "console-0.9909.tar.gz",
            "has_sig": false,
            "md5_digest": "d5484a2c86ad21b2ac6dcd1eb924feae",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.4",
            "size": 95926,
            "upload_time": "2024-10-09T23:18:19",
            "upload_time_iso_8601": "2024-10-09T23:18:19.504174Z",
            "url": "https://files.pythonhosted.org/packages/d9/c5/a8ffbf0fa4b712b3baaed3bc30ec1cbf4e462cc4958684c6283ed0ba163b/console-0.9909.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-09 23:18:19",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mixmastamyk",
    "github_project": "console",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "console"
}
        
Elapsed time: 1.67477s