From 369dc3f66d2632773f0ac87175a4573bedad998f Mon Sep 17 00:00:00 2001 From: LoafyLemon Date: Sat, 18 May 2024 21:05:45 +0100 Subject: [PATCH] Console label finder * Pretty print and sort matching entries in a grid --- game/scripts/utility/console.rpy | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/game/scripts/utility/console.rpy b/game/scripts/utility/console.rpy index 3fdc3016..25948d96 100644 --- a/game/scripts/utility/console.rpy +++ b/game/scripts/utility/console.rpy @@ -299,8 +299,36 @@ init 1702 python in _console: partial = l.rest() labels = renpy.get_all_labels() - matching = find_matching_entries(labels, partial) - raise Exception("Matching labels:\n %s" % matching) + matching_entries = find_matching_entries(labels, partial) + + if not matching_entries: + return "No matching labels found." + + # Sort the matching entries alphabetically + matching_entries.sort() + + # Calculate the number of columns for the grid + num_columns = 3 + num_rows = (len(matching_entries) + num_columns - 1) // num_columns + + # Fill the grid by columns to preserve alphabetical order + grid = [[] for _ in range(num_rows)] + for i, entry in enumerate(matching_entries): + grid[i % num_rows].append(entry) + + # Find the maximum width of each column + column_widths = [max(len(grid[row][col]) if col < len(grid[row]) else 0 for row in range(num_rows)) for col in range(num_columns)] + + # Format the rows into a grid layout + formatted_rows = [] + for row in grid: + formatted_row = [] + for i, item in enumerate(row): + formatted_row.append(item.ljust(column_widths[i])) + formatted_rows.append(" | ".join(formatted_row)) + + matching = "\n".join(formatted_rows) + return "\n" + matching renpy.config.at_exit_callbacks.append(console.backup) renpy.config.stdout_callbacks.append(console.stdout_line)