.. _message_types:
Message types and animations
==============================
You can view example output of the library using the
python scripts in the provided examples directory.
Basic Message Types
--------------------
``cliasi`` provides several methods for common message types, each with its own symbol and color.
Here is how they look in the console:
.. code-block:: python
:caption: examples/basic_messages.py
from cliasi import cli
cli.info("Starting process...")
cli.success("Process completed!")
cli.warn("Disk space is low.")
cli.fail("Failed to connect to server.")
cli.log("Debug info")
cli.list("List item")
.. warning::
The actual colors and symbols below may vary depending on your terminal and its settings.
.. raw:: html
i [CLI] | Starting process...
✔ [CLI] | Process completed!
! [CLI] | Disk space is low.
X [CLI] | Failed to connect to server.
LOG [CLI] | Debug info
- [CLI] | List item
Exception and Traceback Formatting
"""""""""""""""""""""""""""""""""""""
If an exception is raised or a traceback is logged, it will be formatted using the ``fail`` message style:
.. code-block:: python
:caption: examples/exception_message.py
import cliasi
# Importing cliasi automatically installs the logging handler
raise ValueError("An example error")
.. raw:: html
.. note::
X [CLI] | Uncaught exception:
X [CLI] | Traceback (most recent call last):
| File "examples/exception_message.py", line 7, in <module>
| raise ValueError("An example error")
| ValueError: An example error
Animations and Progress Bars
----------------------------
Blocking Animation
"""""""""""""""""""""
Blocking animations run in the main thread and block further execution until complete.
.. code-block:: python
:caption: examples/blocking_animation.py
from cliasi import cli
import time
cli.animate_message_blocking("Saving...", time=3, message_right="[CTRL-C] to stop")
# You cant do anything else while the animation is running
# Useful if you save something to a file at the end of a program
# User can CTRL-C while this is running
cli.success("Data saved!")
.. raw:: html
i
[CLI]
|
This is a left-aligned message.
✔
[CLI]
|
This is a right-aligned message.
!
[CLI]
|
This is a centered message.
i
[CLI]
|
From left
to the middle
to the right
.. _max_dead_space:
max_dead_space parameter
"""""""""""""""""""""""""
If you send a short message with short left text and short right text they might
end up very far apart on wide terminals. Users might not read the text on the right.
To prevent this you can set the :attr:`~cliasi.cliasi.Cliasi.max_dead_space`
parameter to a number of characters.
If the dead space between left and right aligned text exceeds this number,
the right or center aligned text put next to the left aligned text.
If you deliberately disable the left aligned text or
set :attr:`~cliasi.cliasi.Cliasi.max_dead_space` to ``None``
the check will be skipped