### Install Git Hooks with Make Source: https://github.com/ingomeyer441/simple-term-menu/blob/develop/README.md This bash command installs pre-commit Git hooks for the project. It uses the 'make' utility to run the 'git-hooks-install' target, ensuring code quality and consistent styling by enforcing linters before commits. ```bash make git-hooks-install ``` -------------------------------- ### Install simple-term-menu from AUR Source: https://github.com/ingomeyer441/simple-term-menu/blob/develop/README.md Installs the simple-term-menu library from the Arch User Repository (AUR) using yay. This is an alternative installation method for Arch Linux users. ```bash yay -S python-simple-term-menu ``` -------------------------------- ### Preview File Contents with Pygments in Terminal Menu Source: https://github.com/ingomeyer441/simple-term-menu/blob/develop/README.md This Python example showcases creating a terminal menu with file previews using the Pygments library for syntax highlighting. It reads file content, determines the lexer based on the filename, and formats it for terminal output. This requires Pygments to be installed. ```python #!/usr/bin/env python3 import os from pygments import formatters, highlight, lexers from pygments.util import ClassNotFound from simple_term_menu import TerminalMenu def highlight_file(filepath): with open(filepath, "r") as f: file_content = f.read() try: lexer = lexers.get_lexer_for_filename(filepath, stripnl=False, stripall=False) except ClassNotFound: lexer = lexers.get_lexer_by_name("text", stripnl=False, stripall=False) formatter = formatters.TerminalFormatter(bg="dark") # dark or light highlighted_file_content = highlight(file_content, lexer, formatter) return highlighted_file_content def list_files(directory="."): return (file for file in os.listdir(directory) if os.path.isfile(os.path.join(directory, file))) def main(): terminal_menu = TerminalMenu(list_files(), preview_command=highlight_file, preview_size=0.75) menu_entry_index = terminal_menu.show() if __name__ == "__main__": main() ``` -------------------------------- ### Preview File Contents with Bat in Terminal Menu Source: https://github.com/ingomeyer441/simple-term-menu/blob/develop/README.md This example demonstrates how to create a terminal menu that lists files in the current directory and previews their contents using the 'bat' command. It requires the 'bat' utility to be installed. The menu displays file names, and selecting an entry shows its syntax-highlighted content. ```python #!/usr/bin/env python3 import os from simple_term_menu import TerminalMenu def list_files(directory="."): return (file for file in os.listdir(directory) if os.path.isfile(os.path.join(directory, file))) def main(): terminal_menu = TerminalMenu(list_files(), preview_command="bat --color=always {}", preview_size=0.75) menu_entry_index = terminal_menu.show() if __name__ == "__main__": main() ``` -------------------------------- ### Install simple-term-menu using pip Source: https://github.com/ingomeyer441/simple-term-menu/blob/develop/README.md Installs the simple-term-menu library using pip for Python 3.5+. This is the recommended way to install the package. ```bash python3 -m pip install simple-term-menu ``` -------------------------------- ### Preview Tmux Session Panes in Terminal Menu Source: https://github.com/ingomeyer441/simple-term-menu/blob/develop/README.md This example creates a terminal menu listing active tmux sessions, displaying their name and ID. When an entry is selected, it previews the active pane of that session using the 'tmux capture-pane' command. It requires 'tmux' to be installed and running. ```python #!/usr/bin/env python3 import subprocess from simple_term_menu import TerminalMenu def list_tmux_sessions(): tmux_command_output = subprocess.check_output( ["tmux", "list-sessions", "-F#{session_id}:#{session_name}"], universal_newlines=True ) tmux_sessions = [] for line in tmux_command_output.split("\n"): line = line.strip() if not line: continue session_id, session_name = tuple(line.split(":")) tmux_sessions.append((session_name, session_id)) return tmux_sessions def main(): terminal_menu = TerminalMenu( ("|".join(session) for session in list_tmux_sessions()), preview_command="tmux capture-pane -e -p -t {}", preview_size=0.75, ) menu_entry_index = terminal_menu.show() if __name__ == "__main__": main() ``` -------------------------------- ### Create Menu with File Preview using Bash Source: https://github.com/ingomeyer441/simple-term-menu/blob/develop/README.md An example demonstrating how to create a simple-term-menu from the command line that includes a file preview powered by 'bat'. It finds all files in the current directory and uses their names as menu entries. ```bash simple-term-menu -p "bat --color=always {}" \ --preview-size 0.75 \ $(find . -maxdepth 1 -type f | awk '{ print substr($0, 3) }') ``` -------------------------------- ### Python: Multi-select Terminal Menu Example Source: https://github.com/ingomeyer441/simple-term-menu/blob/develop/README.md Illustrates how to enable and configure multi-select functionality in a Python terminal menu using the `simple_term_menu` library. This allows users to select multiple items using space or tab, and view selected items as indices or strings. ```python #!/usr/bin/env python3 from simple_term_menu import TerminalMenu def main(): terminal_menu = TerminalMenu( ["dog", "cat", "mouse", "squirrel"], multi_select=True, show_multi_select_hint=True, ) menu_entry_indices = terminal_menu.show() print(menu_entry_indices) print(terminal_menu.chosen_menu_entries) if __name__ == "__main__": main() ``` -------------------------------- ### Python Advanced Terminal Menu with Sub-Menus Source: https://github.com/ingomeyer441/simple-term-menu/blob/develop/README.md This Python script creates a main menu with options that lead to sub-menus, demonstrating nested menu structures. It utilizes the simple-term-menu library for creating interactive command-line interfaces with customizable styles and cursor options. Requires Python 3 and 'simple-term-menu' installation. ```python #!/usr/bin/env python3 """ Demonstration example for GitHub Project at https://github.com/IngoMeyer441/simple-term-menu This code only works in python3. Install per sudo pip3 install simple-term-menu """ import time from simple_term_menu import TerminalMenu def main(): main_menu_title = " Main Menu.\n Press Q or Esc to quit. \n" main_menu_items = ["Edit Menu", "Second Item", "Third Item", "Quit"] main_menu_cursor = "> " main_menu_cursor_style = ("fg_red", "bold") main_menu_style = ("bg_red", "fg_yellow") main_menu_exit = False main_menu = TerminalMenu( menu_entries=main_menu_items, title=main_menu_title, menu_cursor=main_menu_cursor, menu_cursor_style=main_menu_cursor_style, menu_highlight_style=main_menu_style, cycle_cursor=True, clear_screen=True, ) edit_menu_title = " Edit Menu.\n Press Q or Esc to back to main menu. \n" edit_menu_items = ["Edit Config", "Save Settings", "Back to Main Menu"] edit_menu_back = False edit_menu = TerminalMenu( edit_menu_items, title=edit_menu_title, menu_cursor=main_menu_cursor, menu_cursor_style=main_menu_cursor_style, menu_highlight_style=main_menu_style, cycle_cursor=True, clear_screen=True, ) while not main_menu_exit: main_sel = main_menu.show() if main_sel == 0: while not edit_menu_back: edit_sel = edit_menu.show() if edit_sel == 0: print("Edit Config Selected") time.sleep(5) elif edit_sel == 1: print("Save Selected") time.sleep(5) elif edit_sel == 2 or edit_sel == None: edit_menu_back = True print("Back Selected") edit_menu_back = False elif main_sel == 1: print("option 2 selected") time.sleep(5) elif main_sel == 2: print("option 3 selected") time.sleep(5) elif main_sel == 3 or main_sel == None: main_menu_exit = True print("Quit Selected") if __name__ == "__main__": main() ``` -------------------------------- ### Command Line Usage for simple-term-menu Source: https://github.com/ingomeyer441/simple-term-menu/blob/develop/README.md Demonstrates the command-line interface for `simple-term-menu`, including supported arguments for menu customization, selection, and previewing. This helps users understand how to integrate the tool into shell scripts. ```text usage: simple-term-menu [-h] [-s] [-X] [-l] [--cursor CURSOR] [-i CURSOR_INDEX] [--cursor-style CURSOR_STYLE] [-C] [-E] [--highlight-style HIGHLIGHT_STYLE] [-m] [--multi-select-cursor MULTI_SELECT_CURSOR] [--multi-select-cursor-brackets-style MULTI_SELECT_CURSOR_BRACKETS_STYLE] [--multi-select-cursor-style MULTI_SELECT_CURSOR_STYLE] [--multi-select-keys MULTI_SELECT_KEYS] [--multi-select-no-select-on-accept] [--multi-select-empty-ok] [-p PREVIEW_COMMAND] [--no-preview-border] [--preview-size PREVIEW_SIZE] [--preview-title PREVIEW_TITLE] [--search-highlight-style SEARCH_HIGHLIGHT_STYLE] [--search-key SEARCH_KEY] [--shortcut-brackets-highlight-style SHORTCUT_BRACKETS_HIGHLIGHT_STYLE] [--shortcut-key-highlight-style SHORTCUT_KEY_HIGHLIGHT_STYLE] [--show-multi-select-hint] [--show-multi-select-hint-text SHOW_MULTI_SELECT_HINT_TEXT] [--show-search-hint] [--show-search-hint-text SHOW_SEARCH_HINT_TEXT] [--show-shortcut-hints] [--show-shortcut-hints-in-title] [--skip-empty-entries] [-b STATUS_BAR] [-d] [--status-bar-style STATUS_BAR_STYLE] [--stdout] [-t TITLE] [-V] [-r PRESELECTED_ENTRIES | -R PRESELECTED_INDICES] [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 options: -h, --help show this help message and exit -s, --case-sensitive searches are case sensitive -X, --no-clear-menu-on-exit do not clear the menu on exit -l, --clear-screen clear the screen before the menu is shown --cursor CURSOR menu cursor (default: "> ") -i CURSOR_INDEX, --cursor-index CURSOR_INDEX initially selected item index --cursor-style CURSOR_STYLE style for the menu cursor as comma separated list (default: "fg_red,bold") -C, --no-cycle do not cycle the menu selection -E, --no-exit-on-shortcut do not exit on shortcut keys --highlight-style HIGHLIGHT_STYLE style for the selected menu entry as comma separated list (default: "standout") -m, --multi-select Allow the selection of multiple entries (implies `--stdout`) --multi-select-cursor MULTI_SELECT_CURSOR multi-select menu cursor (default: "[*]") --multi-select-cursor-brackets-style MULTI_SELECT_CURSOR_BRACKETS_STYLE style for brackets of the multi-select menu cursor as comma separated list (default: "fg_gray") --multi-select-cursor-style MULTI_SELECT_CURSOR_STYLE style for the multi-select menu cursor as comma separated list (default: "fg_yellow,bold") --multi-select-keys MULTI_SELECT_KEYS key for toggling a selected item in a multi-selection (default: " ,tab", --multi-select-no-select-on-accept do not select the currently highlighted menu item when the accept key is pressed (it is still selected if no other item was selected before) --multi-select-empty-ok when used together with --multi-select-no-select-on- accept allows returning no selection at all -p PREVIEW_COMMAND, --preview PREVIEW_COMMAND Command to generate a preview for the selected menu entry. "{}" can be used as placeholder for the menu text. If the menu entry has a data component (separated by "|"), this is used instead. --no-preview-border do not draw a border around the preview window --preview-size PREVIEW_SIZE maximum height of the preview window in fractions of the terminal height (default: "0.25") --preview-title PREVIEW_TITLE title of the preview window (default: "preview") ``` -------------------------------- ### Show Search Hint Source: https://github.com/ingomeyer441/simple-term-menu/blob/develop/README.md Controls the visibility of a hint in the search line, providing guidance on how to initiate a search. ```bash --show-search-hint show a search hint in the search line ``` -------------------------------- ### Create a basic terminal menu in Python Source: https://github.com/ingomeyer441/simple-term-menu/blob/develop/README.md Demonstrates how to create a simple terminal menu using the TerminalMenu class. It takes a list of options, displays them, and returns the index of the selected option. ```python #!/usr/bin/env python3 from simple_term_menu import TerminalMenu def main(): options = ["entry 1", "entry 2", "entry 3"] terminal_menu = TerminalMenu(options) menu_entry_index = terminal_menu.show() print(f"You have selected {options[menu_entry_index]}!") if __name__ == "__main__": main() ``` -------------------------------- ### Custom Search Hint Text Source: https://github.com/ingomeyer441/simple-term-menu/blob/develop/README.md Enables the customization of the search hint text. The placeholder {key} can be used to display the configured search key. ```bash --show-search-hint-text SHOW_SEARCH_HINT_TEXT Custom text which will be shown as search hint. Use the placeholders {key} for the search key if appropriately. ``` -------------------------------- ### Python: Basic Menu with Shortcuts Source: https://github.com/ingomeyer441/simple-term-menu/blob/develop/README.md Demonstrates how to create a simple terminal menu with predefined shortcuts for each item. The first letter of each menu item is used as its shortcut. Pressing a shortcut key immediately selects the corresponding item. ```python #!/usr/bin/env python3 import os from simple_term_menu import TerminalMenu def main(): fruits = ["[a] apple", "[b] banana", "[o] orange"] terminal_menu = TerminalMenu(fruits, title="Fruits") menu_entry_index = terminal_menu.show() if __name__ == "__main__": main() ``` -------------------------------- ### Pre-select Entries by Name Source: https://github.com/ingomeyer441/simple-term-menu/blob/develop/README.md Allows pre-selecting menu items in a multi-select menu by providing a comma-separated list of strings that match the menu item text. ```bash -r PRESELECTED_ENTRIES, --preselected_entries PRESELECTED_ENTRIES Comma separated list of strings matching menu items to start pre-selected in a multi-select menu. ``` -------------------------------- ### Custom Multi-Select Hint Text Source: https://github.com/ingomeyer441/simple-term-menu/blob/develop/README.md Allows customization of the text displayed as a multi-select hint. Placeholders like {multi_select_keys} and {accept_keys} can be used to dynamically insert relevant information. ```bash --show-multi-select-hint-text SHOW_MULTI_SELECT_HINT_TEXT Custom text which will be shown as multi-select hint. Use the placeholders {multi_select_keys} and {accept_keys} if appropriately. ``` -------------------------------- ### Configure Search Key Source: https://github.com/ingomeyer441/simple-term-menu/blob/develop/README.md Defines the key used to initiate a search within the menu. A special value of 'none' allows any letter key to activate the search. The default key is '/'. ```bash --search-key SEARCH_KEY key to start a search (default: "/", "none" is treated a special value which activates the search on any letter key) ``` -------------------------------- ### Print Version Source: https://github.com/ingomeyer441/simple-term-menu/blob/develop/README.md Displays the version number of the simple-term-menu and then exits the program. ```bash -V, --version print the version number and exit ``` -------------------------------- ### Pre-select Entries by Index Source: https://github.com/ingomeyer441/simple-term-menu/blob/develop/README.md Enables pre-selecting menu items in a multi-select menu using a comma-separated list of numeric indices. ```bash -R PRESELECTED_INDICES, --preselected_indices PRESELECTED_INDICES Comma separated list of numeric indexes of menu items to start pre-selected in a multi-select menu. ``` -------------------------------- ### Set Menu Title Source: https://github.com/ingomeyer441/simple-term-menu/blob/develop/README.md Sets the title text that will be displayed at the top of the menu. ```bash -t TITLE, --title TITLE menu title ``` -------------------------------- ### Python: Custom Accept Keys for Terminal Menu Source: https://github.com/ingomeyer441/simple-term-menu/blob/develop/README.md Demonstrates how to configure custom keyboard shortcuts (accept keys) for confirming a menu selection in a Python terminal menu. It uses the `simple_term_menu` library and specifies 'enter', 'alt-d', and 'ctrl-i' as valid accept keys. ```python #!/usr/bin/env python3 from simple_term_menu import TerminalMenu def main(): terminal_menu = TerminalMenu(["entry 1", "entry 2", "entry 3"], accept_keys=("enter", "alt-d", "ctrl-i")) menu_entry_index = terminal_menu.show() print(terminal_menu.chosen_accept_key) if __name__ == "__main__": main() ``` -------------------------------- ### Configure Search Highlight Style Source: https://github.com/ingomeyer441/simple-term-menu/blob/develop/README.md Sets the visual style for matched search patterns within the menu. The default style is a combination of black foreground, yellow background, and bold text. ```bash --search-highlight-style SEARCH_HIGHLIGHT_STYLE style of matched search patterns (default: "fg_black,bg_yellow,bold") ``` -------------------------------- ### Skip Empty Entries in Terminal Menu Source: https://github.com/ingomeyer441/simple-term-menu/blob/develop/README.md This Python code demonstrates how to use the `skip_empty_entries` parameter in `simple_term_menu` to ignore empty strings or `None` values when displaying menu options. This prevents blank lines from appearing in the menu. ```python from simple_term_menu import TerminalMenu def main(): # Or use `None` instead of `""`: options = ["entry 1", "entry 2", "", "add", "edit"] # ["entry 1", "entry 2", None, "add", "edit"] terminal_menu = TerminalMenu(options, skip_empty_entries=True) # TerminalMenu(options) menu_entry_index = terminal_menu.show() print(f"You have selected {options[menu_entry_index]}!") if __name__ == "__main__": main() ``` -------------------------------- ### Show Shortcut Hints Source: https://github.com/ingomeyer441/simple-term-menu/blob/develop/README.md Toggles the display of shortcut hints in the status bar of the menu. ```bash --show-shortcut-hints show shortcut hints in the status bar ``` -------------------------------- ### Configure Shortcut Brackets Highlight Style Source: https://github.com/ingomeyer441/simple-term-menu/blob/develop/README.md Specifies the style for the brackets that enclose shortcut keys in the menu. The default style uses a gray foreground. ```bash --shortcut-brackets-highlight-style SHORTCUT_BRACKETS_HIGHLIGHT_STYLE style of brackets enclosing shortcut keys (default: "fg_gray") ``` -------------------------------- ### Configure Shortcut Key Highlight Style Source: https://github.com/ingomeyer441/simple-term-menu/blob/develop/README.md Determines the visual style for shortcut keys displayed in the menu. The default style uses a blue foreground. ```bash --shortcut-key-highlight-style SHORTCUT_KEY_HIGHLIGHT_STYLE style of shortcut keys (default: "fg_blue") ``` -------------------------------- ### Skip Empty Entries Source: https://github.com/ingomeyer441/simple-term-menu/blob/develop/README.md Configures how empty strings in menu entries are interpreted. When enabled, an empty string is treated as a distinct, empty menu entry. ```bash --skip-empty-entries Interpret an empty string in menu entries as an empty menu entry ``` -------------------------------- ### Position Status Bar Below Preview Source: https://github.com/ingomeyer441/simple-term-menu/blob/develop/README.md Specifies that the status bar should be displayed below the preview window, if a preview window is present. ```bash -d, --status-bar-below-preview show the status bar below the preview window if any ``` -------------------------------- ### Output Selected Indices to Stdout Source: https://github.com/ingomeyer441/simple-term-menu/blob/develop/README.md Enables printing the selected menu index or indices to standard output. Multiple selections are separated by semicolons. ```bash --stdout Print the selected menu index or indices to stdout (in addition to the exit status). Multiple indices are separated by ";". ``` -------------------------------- ### Show Shortcut Hints in Title Source: https://github.com/ingomeyer441/simple-term-menu/blob/develop/README.md Determines whether shortcut hints are displayed within the menu's title. ```bash --show-shortcut-hints-in-title show shortcut hints in the menu title ``` -------------------------------- ### Show Multi-Select Hint Source: https://github.com/ingomeyer441/simple-term-menu/blob/develop/README.md Enables or disables the display of a hint in the status bar indicating multi-select functionality. ```bash --show-multi-select-hint show a multi-select hint in the status bar ``` -------------------------------- ### Configure Status Bar Style Source: https://github.com/ingomeyer441/simple-term-menu/blob/develop/README.md Defines the visual style for the status bar lines, including foreground and background colors. The default is yellow foreground and black background. ```bash --status-bar-style STATUS_BAR_STYLE style of the status bar lines (default: "fg_yellow,bg_black") ``` -------------------------------- ### Set Status Bar Text Source: https://github.com/ingomeyer441/simple-term-menu/blob/develop/README.md Sets the text content to be displayed in the status bar of the menu. ```bash -b STATUS_BAR, --status-bar STATUS_BAR status bar text ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.