Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/developerstoolbox/notify-package
Provides a set of utility functions for printing formatted messages to the terminal
https://github.com/developerstoolbox/notify-package
error information notify success system warning wolfsoftware
Last synced: about 1 month ago
JSON representation
Provides a set of utility functions for printing formatted messages to the terminal
- Host: GitHub
- URL: https://github.com/developerstoolbox/notify-package
- Owner: DevelopersToolbox
- License: mit
- Created: 2024-05-22T20:27:00.000Z (8 months ago)
- Default Branch: master
- Last Pushed: 2024-06-10T04:58:12.000Z (7 months ago)
- Last Synced: 2024-06-10T11:27:29.064Z (7 months ago)
- Topics: error, information, notify, success, system, warning, wolfsoftware
- Language: Python
- Homepage:
- Size: 45.9 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Citation: CITATION.cff
- Codeowners: .github/CODEOWNERS
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
## Overview
The Notify package provides a set of utility functions for printing formatted messages to the terminal. The main purpose of this
module is to facilitate the display of success, warning, error, informational, and system messages with specific color and style
formatting using predefined constants.## Features
- Display success messages with green text.
- Display warning messages with yellow text.
- Display error messages with red text.
- Display informational messages with cyan text.
- Display system messages with grey text.
- Support for custom colors, prompts, and formatting scopes.
- Error handling for invalid colors and scopes.## Installation
To install the Notify package, use the following command:
```bash
pip install wolfsoftware.notify
```## Usage
Here is an example of how to use the notification functions provided by the Notify package:
```python
from wolfsoftware.notify import success_message, warning_message, error_message, info_message, system_messageprint(success_message("Operation completed successfully."))
print(warning_message("This is a warning message."))
print(error_message("An error occurred."))
print(info_message("This is some information."))
print(system_message("System update available."))
```## Functions
### `success_message`
Print a success message with a specific format.
```python
def success_message(
message: str,
color: str = 'green+bold',
prompt: str = 'Success',
scope: str = 'prompt_text',
prompt_prefix: str = '[ ',
prompt_suffix: str = ' ]'
) -> str:
```### `warning_message`
Print a warning message with a specific format.
```python
def warning_message(
message: str,
color: str = 'yellow+bold',
prompt: str = 'Warning',
scope: str = 'prompt_text',
prompt_prefix: str = '[ ',
prompt_suffix: str = ' ]'
) -> str:
```### `error_message`
Print an error message with a specific format.
```python
def error_message(
message: str,
color: str = 'red+bold',
prompt: str = 'Error',
scope: str = 'prompt_text',
prompt_prefix: str = '[ ',
prompt_suffix: str = ' ]'
) -> str:
```### `failure_message`
Alias for `error_message`, but with a prompt='Failure'.
```python
failure_message = error_message
```### `info_message`
Print an informational message with a specific format.
```python
def info_message(
message: str,
color: str = 'cyan+bold',
prompt: str = 'Info',
scope: str = 'prompt_text',
prompt_prefix: str = '[ ',
prompt_suffix: str = ' ]'
) -> str:
```### `system_message`
Print a system message with a specific format.
```python
def system_message(
message: str,
color: str = 'grey+bold',
prompt: str = 'System',
scope: str = 'prompt_text',
prompt_prefix: str = '[ ',
prompt_suffix: str = ' ]'
) -> str:
```## Customization
You can customize the color, prompt text, and the scope of the color application using the provided parameters. Here are some examples:
### Custom Colors
```python
print(success_message("Operation completed successfully.", color="blue+bold"))
```### Custom Prompts
```python
print(success_message("Operation completed successfully.", prompt="Completed"))
```### Custom Scopes
- `all`: Applies the color to the entire message.
- `prompt`: Applies the color to the prompt only.
- `prompt_text`: Applies the color to the text inside the brackets.```python
print(success_message("Operation completed successfully.", scope="prompt"))
print(success_message("Operation completed successfully.", scope="prompt_text"))
```### Custom Prefixes and Suffixes
You can also customize the prompt prefix and suffix.
```python
print(success_message("Operation completed successfully.", prompt_prefix="<<", prompt_suffix=">>"))
```## Error Handling
The Notify package includes error handling for invalid color and scope inputs. If an invalid color or scope is provided, a `NotifyValueError` will be raised with an appropriate error message.
```python
from wolfsoftware.notify import NotifyValueErrortry:
print(success_message("Operation completed successfully.", color="invalid"))
except NotifyValueError as e:
print(f"Error: {e}")
```## Testing
The Notify package includes a comprehensive test suite to ensure the correct functionality of all message formatting functions. The tests verify that the package version is defined, the message functions return correctly formatted strings, and exceptions are raised appropriately for invalid inputs.
### Running Tests
To run the tests, use a testing framework such as pytest:
```bash
pytest tests/test_notify.py
```## Acknowledgements
The Notify package uses the `colorama` library for cross-platform support of ANSI color codes. Many thanks to the contributors of the `colorama` project for their excellent work.