cli-utility

A simple CLI menu and output utility for python.


Keywords
menu, output, CLI
License
Apache-2.0
Install
pip install cli-utility==1.0.0

Documentation

cli_utility

GitHub GitHub pull requests GitHub last commit (branch) Language Travis (.com) branch Author

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

Peek 2019-10-25 01-45

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

Peek 2019-10-25 01-29

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

Peek 2019-10-25 01-45

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

2019-10-25_02-29

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

2019-10-25_17-44

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

2019-10-25_17-44

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 (一个快速创建命令行菜单的工具)