From: Svjatoslav Agejenko Date: Mon, 26 Jan 2026 21:19:13 +0000 (+0200) Subject: Add documentation for `Menu` class with example usage and detailed instructions X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=2c8875400115a8b954bc530ed1cbfe0dc2e2d8db;p=cli-helper.git Add documentation for `Menu` class with example usage and detailed instructions --- diff --git a/doc/index.org b/doc/index.org index 1b4459e..9adfd45 100644 --- a/doc/index.org +++ b/doc/index.org @@ -57,6 +57,44 @@ public class Demo { See [[https://www3.svjatoslav.eu/projects/cli-helper/apidocs/eu/svjatoslav/commons/cli_helper/CLIHelper.html][Javadoc]] for complete API reference. +** Interactive Menu Selection + +The =Menu= class provides an interactive menu for selecting options +from a list using fuzzy matching and cursor keys. It supports +navigation with arrow keys, filtering by typing, and selection with +Enter or cancellation with Escape. + +*Important:* This functionality requires the terminal to be in raw +mode for proper operation. On Unix-like systems, this is automatically +handled by the library, but it will not work correctly in standard +line-buffered terminal mode or IDE consoles. + +Example usage: + +#+BEGIN_SRC java +import java.util.Arrays; +import java.util.List; +import eu.svjatoslav.commons.cli_helper.Menu; + +public class MenuExample { + public static void main(String[] args) throws IOException { + List options = Arrays.asList("Option A", "Option B", "Option C"); + String selected = Menu.askSelection("Choose an option:", options); + if (selected != null) { + System.out.println("You selected: " + selected); + } else { + System.out.println("Selection canceled."); + } + } +} +#+END_SRC + +In this example, the user is presented with a menu where they can: +- Navigate options using up/down arrow keys +- Filter options by typing (case-insensitive fuzzy matching; e.g., typing "abc" matches "aXbYc" but not "acb") +- Press Enter to select the highlighted option +- Press Escape to cancel the selection (returns null) + * CLI argument helper :PROPERTIES: :ID: eb7d5632-6152-4d37-8e55-1cf4da21c204