@@ -17,12 +17,33 @@ public class ConsoleIOHelper {
1717 private static final String EXCLUDE_PROMPT = "Type in the number and/or range of numbers of packages to exclude "
1818 + "(comma-separated, i.e. 2,3,5..9)\n or press Enter to keep all: " ;
1919
20+ /**
21+ * Prompts the user for a yes/no confirmation based on the provided {@code prompt}.
22+ *
23+ * @param scanner {@link Scanner} used to read user input; must not be {@code null}
24+ * @param prompt The message displayed before the confirmation prompt
25+ * @return {@code true} if the user confirms with "y" or "yes" (case insensitive),
26+ * {@code false} otherwise
27+ */
2028 static boolean confirm (Scanner scanner , String prompt ) {
2129 System .out .print (prompt + " [y/N]: " );
2230 String input = scanner .nextLine ().trim ().toLowerCase ();
2331 return input .equals ("y" ) || input .equals ("yes" );
2432 }
2533
34+ /**
35+ * Prompts the user to specify which packages should be excluded from further processing.
36+ *
37+ * <p>The method prints an enumerated list of available package names and then reads a line
38+ * containing comma‑separated indices, ranges (e.g., "2..4"), or both. It validates that the
39+ * input is empty or contains number/s and/or range/s.
40+ * A list containing only the non‑excluded items is returned.
41+ *
42+ * @param packages A list of package identifiers presented for selection; must not be {@code null}
43+ * @param scanner {@link Scanner} used to read user input; must not be {@code null}
44+ * @return List of packages that were not selected for exclusion
45+ * @throws RuntimeException If the user input does not conform to the expected format
46+ */
2647 static List <String > promptForExclusions (List <String > packages , Scanner scanner ) {
2748 for (int i = 0 ; i < packages .size (); i ++) {
2849 System .out .printf ("%2d. %s\n " , i + 1 , packages .get (i ));
@@ -66,6 +87,13 @@ static List<String> promptForExclusions(List<String> packages, Scanner scanner)
6687 return filtered ;
6788 }
6889
90+ /**
91+ * Prints help documentation to standard output.
92+ *
93+ * <p>Retrieves help info from {@link ConfigManager#getHelpText()} and outputs it.
94+ * If an {@link IOException} occurs while reading the help file,
95+ * an error message is written to standard error.
96+ */
6997 static void printHelp () {
7098 try {
7199 List <String > lines = ConfigManager .getHelpText ();
@@ -75,10 +103,34 @@ static void printHelp() {
75103 }
76104 }
77105
106+ /**
107+ * Wraps a string in ANSI color codes when the underlying terminal supports it.
108+ *
109+ * <p>If ANSI escape sequences are supported for the given {@code term} and an active console is present,
110+ * the resulting string will be prefixed with {@code ansiColorCode} and suffixed with a reset code.
111+ * If coloring is not supported, the original string is returned unchanged.
112+ *
113+ * @param str The text to be colored; must not be {@code null}
114+ * @param ansiColorCode One of the predefined ANSI color codes (e.g., {@link #YELLOW});
115+ * may also be an empty string for no coloring
116+ * @return A possibly-colored version of {@code str}, or {@code str} itself if ANSI is unsupported
117+ */
78118 static String color (String str , String ansiColorCode ) {
79119 return isANSISupported (System .getenv ("TERM" ), System .console ()) ? ansiColorCode + str + RESET : str ;
80120 }
81121
122+ /**
123+ * Determines whether the current environment likely supports ANSI escape sequences.
124+ *
125+ * <p>Checks that the terminal type ({@code term}) is non‑null and not equal to "dumb",
126+ * and verifies that an active console stream exists. Returns {@code true} when these
127+ * conditions indicate that colored output can be rendered; otherwise returns {@code false}.
128+ *
129+ * @param term Value of the TERM environment variable
130+ * @param console Underlying console object from {@link Console}; may be {@code null}
131+ * on some platforms
132+ * @return {@code true} if ANSI escape sequences are supported, {@code false} otherwise
133+ */
82134 static boolean isANSISupported (String term , Console console ) {
83135 return console != null && term != null && !term .isEmpty () && !"dumb" .equals (term );
84136 }
0 commit comments