build_tools.tui_common.interactive
Shared interactive mode utilities for syllable extractors.
This module provides common interactive mode prompts and UI helpers used by both pyphen and NLTK syllable extractors.
Usage:
from build_tools.tui_common.interactive import (
prompt_extraction_settings,
prompt_input_file,
print_banner,
print_section,
)
# Display tool banner
print_banner("PYPHEN SYLLABLE EXTRACTOR", [
"This tool extracts syllables using dictionary-based hyphenation.",
"Output is saved to _working/output/ by default.",
])
# Get extraction settings
min_len, max_len = prompt_extraction_settings(
default_min=2,
default_max=8,
)
# Get input file
input_path = prompt_input_file()
Functions
|
Print a formatted banner with title and description. |
|
Print a section header. |
|
Prompt for an integer value with validation. |
|
Prompt for min/max syllable length extraction settings. |
|
Prompt for an input file path with tab completion. |
|
Print extraction completion message with output paths. |
Module Contents
- build_tools.tui_common.interactive.print_banner(title, description_lines, width=70)[source]
Print a formatted banner with title and description.
- Parameters:
Example
>>> print_banner("MY TOOL", [ ... "This tool does something useful.", ... "Output is saved to output/ by default.", ... ]) ====================================================================== MY TOOL ======================================================================
This tool does something useful. Output is saved to output/ by default. ======================================================================
- build_tools.tui_common.interactive.print_section(title, width=70)[source]
Print a section header.
- Parameters:
Example
>>> print_section("EXTRACTION SETTINGS") ---------------------------------------------------------------------- EXTRACTION SETTINGS ----------------------------------------------------------------------
- build_tools.tui_common.interactive.prompt_integer(prompt_text, default, min_value=1, max_value=None, compare_to=None, compare_label='minimum')[source]
Prompt for an integer value with validation.
- Parameters:
prompt_text (str) – Text to display in the prompt
default (int) – Default value if user presses Enter
min_value (int) – Minimum allowed value (default: 1)
max_value (int | None) – Maximum allowed value (optional)
compare_to (int | None) – Value that this must be >= (for max > min validation)
compare_label (str) – Label for compare_to value in error message
- Returns:
Validated integer value
- Return type:
Example
>>> min_len = prompt_integer( ... "Minimum syllable length", ... default=2, ... min_value=1, ... ) >>> max_len = prompt_integer( ... "Maximum syllable length", ... default=8, ... min_value=1, ... compare_to=min_len, ... compare_label="minimum", ... )
- build_tools.tui_common.interactive.prompt_extraction_settings(default_min=2, default_max=8, min_label='Minimum syllable length', max_label='Maximum syllable length')[source]
Prompt for min/max syllable length extraction settings.
- Parameters:
- Returns:
Tuple of (min_len, max_len)
- Return type:
Example
>>> print_section("EXTRACTION SETTINGS") >>> min_len, max_len = prompt_extraction_settings() >>> print(f"✓ Settings: syllables between {min_len}-{max_len} characters")
- build_tools.tui_common.interactive.prompt_input_file(prompt_text="Enter input file path (or 'quit' to exit): ")[source]
Prompt for an input file path with tab completion.
Includes: - Tab completion hint (if readline available) - Home directory expansion (~) - File existence validation - ‘quit’ command to exit
- Parameters:
prompt_text (str) – Text to display in the prompt
- Returns:
Validated Path to the input file
- Raises:
SystemExit – If user types ‘quit’
- Return type:
Example
>>> print_section("INPUT FILE SELECTION") >>> input_path = prompt_input_file()
- build_tools.tui_common.interactive.print_extraction_complete(syllables_path, metadata_path, output_base_dir)[source]
Print extraction completion message with output paths.
- Parameters:
syllables_path (pathlib.Path) – Path to saved syllables file
metadata_path (pathlib.Path) – Path to saved metadata file
output_base_dir (pathlib.Path) – Base output directory for relative path display
Example
>>> print_extraction_complete( ... syllables_path=Path("output/20260110/syllables/test.txt"), ... metadata_path=Path("output/20260110/meta/test.txt"), ... output_base_dir=Path("output/"), ... )