Sleek dmenu alternative written in Python and powered by curses.
Project description
pmenu
Sleek dmenu alternative written in Python and powered by curses.
pip install pmenu-lib
This package provides both a command-line tool and a Python library for creating interactive terminal menus.
Usage
Library Usage
The pmenu(list_of_options) function displays a menu and returns the selected option as a str, or None if the menu is closed without selecting an option.
from pmenu_lib import pmenu
options = ["Option 1", "Option 2", "Option 3"]
selected_option = pmenu(options)
if selected_option:
print(f"You selected: {selected_option}")
else:
print("No option selected")
CLI Usage
After installation, you can use pmenu from the command line:
pmenu "line1\nline2\nline3..."
Or pass multiple arguments:
pmenu "option1" "option2" "option3"
The selected option will be written to /tmp/pmenu (or equivalent temp directory on Windows).
Exit Codes
0: Option selected successfully1: Menu closed without selection (ESC pressed)2: Invalid usage (no arguments provided)
Menu Bindings
- Up arrow: Highlight the previous menu entry
- Down arrow: Highlight the next menu entry
- Type to search: Filter options in real-time
- Backspace: Delete search characters
- Enter: Select the highlighted entry
- Esc: Close the menu without selecting
pmenu_fm: A Practical Use Case (Linux)
The pmenu_fm script included in this repository is an example of how pmenu can be integrated into a bash script to implement a simple file selector.
It uses lsd, a modern ls replacement, to get the list of files in the current directory and their associated icons. The list is then passed to pmenu, which displays a menu in the terminal window.
You can highlight a directory with the Up and Down keys, and change to the selected directory or xdg-open the selected file with the Enter key. The menu can be closed with the Esc key.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters