This Python Msg
class handle printing of simple, coloured, and formatted messages to the terminal. Features include automatic terminal size detection, global message prefix, custom formatting, colour and style control, and optional text wrapping.
- Automatic Terminal Size Detection: Adjusts to the current terminal's size.
- Global Message Prefix: Prefixes can be added, removed, and manipulated.
- Message Types: Standard, info, warning, and error messages with custom formatting.
- Colour and Style Control: Customisable foreground, background, and styles.
- Text Wrapping: Optional text wrapping based on terminal width.
The class requires the colorama
package for colour handling.
```bash pip install colorama ```
Import the Msg
class and create an instance to begin printing messages:
```python from msg import Msg m = Msg() m.info('This is an info message.') m.set_columns(40) # reset columns to 40 m.enable_color(True) m.warn('This is a warning message.') m.line() ```
Sets the number of screen columns for the terminal.
Sets the number of rows for the terminal screen.
Sets whether to print messages in colour.
Print messages of different types.
Print lines.
See the examples provided at the end of the msg.py
file to explore various ways to use the Msg
class.
For more detailed examples and comprehensive method documentation, please refer to the docstrings within the msg.py
file.
The unittests
subdirectory contains msg-test.py
for testing and validation.
- Colours can also be set using abbreviations (see
set_colors()
method in the code). - Ensure you have the required dependencies installed.
This project is released under the GPL 3 License. See the LICENSE file for more details.
Feel free to submit pull requests or open issues to improve the modules in this package.