A simple CLI menu and output utility for python.
Project description
cli_utility
Cli_utility is a python module whitch provide a high-level API to generate an appealing colorful single/multiple selection menu and informational logging output. Cli-utility brings a new life to boring command-line menus and log output programming.
What can I do?
Most things that you can do with cli_utility module! Here are a few examples to get you started:
- Generate a single/multiple selection menu and get the result easily
- Logging messages with colorful
[+]
[-]
[!]
[*]
symbol by using built-in functions - Free logging output of custom foreground colors and meaningful symbols
- Using call chain to log messages
Issues or pull requests are welcome.
Table of Contents
Features
- Beautiful single/multiple selection menu with default value
- Highlight the selection line
- Standardized color log tools
- Highly customizable color log output
- Log tools supports chain call
- Support for all types of output supported by standard print functions
Getting Started
Installation
This module can be easily installed with pip
:
pip install cli_utility
Or you can just use git clone
:
git colne https://github.com/bluewingtan/cli_utility.git
Usage
Example 1 - generate a single/multiple selection menu and get the result
Use direction key up
, down
to move cursor. In single selection mode, use key enter
to select and confirm. Comparatively, in multiple selection mode, use key space
to select and key enter
to confirm.
Here goes the single selection menu code:
Code 1.1
import cli_utility
menu = cli_utility.cli_menu(False)
logger = cli_utility.output_manager()
choices = ['Haruhi Suzumiya', 'Yuki Nagato', 'Mikuru Asahina']
title = 'Who do you love?'
selected = menu.show(title, choices)
logger.print('Girls you selected:',
fore_color=cli_utility.colorama.Fore.LIGHTCYAN_EX)
logger.print_success(choices[selected])
Result 1.1
Here goes the multiple selection menu code:
Code 1.2
import cli_utility
menu = cli_utility.cli_menu()
logger = cli_utility.output_manager()
choices = ['Haruhi Suzumiya', 'Yuki Nagato', 'Mikuru Asahina']
default_selection = [1]
title = 'Who do you love?'
selected = menu.show(title, choices, default_selection)
logger.print('Girls you selected:',
fore_color=cli_utility.colorama.Fore.LIGHTCYAN_EX)
for index, choice in enumerate(choices):
if index in selected:
logger.print_success(choices[index])
Result 1.2
Example 2 - logging messages with colorful symbol
Here goes the code:
Code 2.1
import cli_utility
logger = cli_utility.output_manager()
logger.print('What if you woke up one morning')
logger.print('and everything changed?')
logger.print_success('Yuki Nagato')
logger.print_error('Haruhi Suzumiya')
logger.print_info('Mikuru Asahina')
logger.print_warn('Itsuki Koizumi')
Result 2.1
Example 3 - free logging output of custom foreground colors and meaningful symbols
Here goes the code:
Code 3.1
import cli_utility
logger = cli_utility.output_manager()
Kyon1 = logger.print_string_constructor(
'What if you woke up one morning',
'[^] ',
cli_utility.colorama.Fore.LIGHTGREEN_EX,
cli_utility.colorama.Fore.LIGHTBLUE_EX)
Kyon2 = logger.print_string_constructor(
'and everything changed?',
'[%] ',
cli_utility.colorama.Fore.LIGHTRED_EX,
cli_utility.colorama.Fore.RED)
logger.print(Kyon1)
logger.print(Kyon2)
logger.print_success('Yuki Nagato')
logger.print_error('Haruhi Suzumiya')
logger.print_info('Mikuru Asahina')
logger.print_warn('Itsuki Koizumi')
Result 3.1
Example 4 - using call chain to log messages
Here goes the code:
Code 4.1
import cli_utility
logger = cli_utility.output_manager()
Kyon1 = logger.print_string_constructor(
'What if you woke up one morning',
'[^] ',
cli_utility.colorama.Fore.LIGHTGREEN_EX,
cli_utility.colorama.Fore.LIGHTBLUE_EX)
Kyon2 = logger.print_string_constructor(
'and everything changed?',
'[%] ',
cli_utility.colorama.Fore.LIGHTRED_EX,
cli_utility.colorama.Fore.RED)
logger.print(Kyon1)\
.print(Kyon2)\
.print_success('Yuki Nagato')\
.print_error('Haruhi Suzumiya')\
.print_info('Mikuru Asahina')\
.print_warn('Itsuki Koizumi')
Result 3.1
Dependences
Cli_utility depend on colorama version 0.4.1 and above version.
Change Log
version | simple description |
---|---|
1.0.0 | Initial repo |
Alternatives
tty_menu - python terminal memu (一个快速创建命令行菜单的工具)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for cli_utility-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 912e4b18838249207d4a99ccc171ba6e3917342cbb551fdddeea7b27629d8920 |
|
MD5 | 8638ac71797645298a329253405627c1 |
|
BLAKE2b-256 | a5220a8efe16f1e8eccc74c1473dc13c1d1a519f8d75792c5bec7493b2e11c6e |