Skip to main content

A Python package which creates simple interactive menus on the command line.

Project description

Simple Terminal Menu

Overview

simple-term-menu creates simple menus for interactive command line programs. It can be used to offer a choice of different options to the user. Menu entries can be selected with the arrow or j/k keys. The module uses the terminfo database to detect terminal features automatically and disables styles that are not available. Currently, Linux and macOS are supported.

Installation

simple-term-menu is available on PyPI for Python 3.3+ and can be installed with pip:

python3 -m pip install simple-term-menu

Usage

Create a menu with the default style

Create an instance of the class TerminalMenu and pass the menu entries as a list of strings to the constructor. Call the show method to output the menu and wait for keyboard input:

#!/usr/bin/env python3

from simple_term_menu import TerminalMenu


def main():
    terminal_menu = TerminalMenu(["entry 1", "entry 2", "entry 3"])
    terminal_menu.show()


if __name__ == "__main__":
    main()

You will get an output like:

screenshot_basic

You can now select a menu entry and accept your choice by hitting enter or cancel the menu with escape or <Ctrl>-C. show returns the selected menu entry index or None if the menu was canceled.

Styling

You can pass styling arguments to the TerminalMenu constructor. Each style is a tuple of keyword strings. Currently the following keywords are accepted:

  • bg_black
  • bg_blue
  • bg_cyan
  • bg_gray
  • bg_green
  • bg_purple
  • bg_red
  • bg_yellow
  • fg_black
  • fg_blue
  • fg_cyan
  • fg_gray
  • fg_green
  • fg_purple
  • fg_red
  • fg_yellow
  • bold
  • italics
  • standout
  • underline

You can alter the following styles:

  • menu_cursor_style: The style of the shown cursor. The default style is ("fg_red", "bold").

  • menu_highlight_style: The style of the selected menu entry. The default style is ("standout",)

By setting menu_cursor you can define another cursor or disable it (None). The default cursor is "> ".

Command line program

simple-term-menu can be used as a terminal program in shell scripts. The exit code of the script is the 1-based index of the selected menu entry. The exit code 0 reports the cancel action. The following command line arguments are supported:

usage: simple-term-menu [-h] [-c CURSOR] [-s CURSOR_STYLE]
                        [-m HIGHLIGHT_STYLE] [-C] [-V]
                        entries [entries ...]

simple-term-menu creates simple interactive menus in the terminal and returns the selected entry as exit code.

positional arguments:
  entries               the menu entries to show

optional arguments:
  -h, --help            show this help message and exit
  -c CURSOR, --cursor CURSOR
                        menu cursor (default: > )
  -s CURSOR_STYLE, --cursor_style CURSOR_STYLE
                        style for the menu cursor as comma separated list
                        (default: fg_red,bold)
  -m HIGHLIGHT_STYLE, --highlight_style HIGHLIGHT_STYLE
                        style for the selected menu entry as comma separated
                        list (default: standout)
  -C, --no-cycle        do not cycle the menu selection
  -V, --version         print the version number and exit

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simple-term-menu-0.2.1.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simple_term_menu-0.2.1-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file simple-term-menu-0.2.1.tar.gz.

File metadata

  • Download URL: simple-term-menu-0.2.1.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.4

File hashes

Hashes for simple-term-menu-0.2.1.tar.gz
Algorithm Hash digest
SHA256 1b188357feb5dba8e094ad12de60636653b1ef1aa66ee6c42a231a4e5fdb3c91
MD5 c26b1a1432e75842acfc2d7a514ab893
BLAKE2b-256 3b27368ce538a4c2177a571bbc3d9a7b0c24ce96d9146cd6e9b6f91333f47a56

See more details on using hashes here.

File details

Details for the file simple_term_menu-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: simple_term_menu-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.4

File hashes

Hashes for simple_term_menu-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 57eaf47fc57ad7119cb61e68947e2a98fa33cb60d967d10e328bc4a4df994b9f
MD5 654d29ac8356ba4ecae9003ae2017f4c
BLAKE2b-256 12ec2459042ce42882b571dec36d92d080e517e97ea714ead51bb41c1842d51d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page