Documentation Index
Fetch the complete documentation index at: https://docs.myspellchecker.com/llms.txt
Use this file to discover all available pages before exploring further.
The myspellchecker.utils.console module provides Rich-based terminal formatting used by the CLI. It includes custom themes for Myanmar text, pre-built table and panel formatters for spell checking output, and helper functions for consistent console styling.
Overview
from myspellchecker.utils.console import (
get_console,
create_error_table,
create_stats_table,
create_summary_panel,
)
# Get a themed console instance
console = get_console()
console.print("Checking Myanmar text...", style="info")
# Create a formatted error table
table = create_error_table(title="Spelling Errors")
console.print(table)
Theme System
MYSPELL_THEME
Custom Rich theme with styles for Myanmar spell checking:
from myspellchecker.utils.console import MYSPELL_THEME
# Theme includes these styles:
MYSPELL_THEME = Theme({
# Status styles
"error": "bold red",
"warning": "bold yellow",
"success": "bold green",
"info": "bold blue",
# Error type styles (underscore notation)
"syllable_error": "red",
"word_error": "#ff8c00", # Orange
"context_error": "yellow",
"tone_ambiguity": "cyan",
"syntax_error": "magenta",
# UI elements
"header": "bold cyan",
"muted": "dim",
"highlight": "bold white",
"myanmar": "white", # Myanmar text
})
Using the Theme
from myspellchecker.utils.console import get_console
console = get_console()
# Styled output
console.print("[info]Processing file...[/info]")
console.print("[error]Spelling error found[/error]")
console.print("[success]Check complete![/success]")
# Error-specific styles (underscore notation)
console.print("[syllable_error]Invalid syllable[/syllable_error]")
console.print("[context_error]Context mismatch[/context_error]")
console.print("[tone_ambiguity]Tone ambiguity[/tone_ambiguity]")
ERROR_STYLES
Mapping from error types to theme style names:
ERROR_STYLES = {
"syllable_error": "syllable_error",
"invalid_syllable": "syllable_error",
"word_error": "word_error",
"invalid_word": "word_error",
"context_error": "context_error",
"context_probability": "context_error",
"tone_ambiguity": "tone_ambiguity",
"syntax_error": "syntax_error",
}
ERROR_ICONS
Unicode icons for error types:
ERROR_ICONS = {
"syllable_error": "🔤", # letter symbols
"invalid_syllable": "🔤",
"word_error": "📝", # memo
"invalid_word": "📝",
"context_error": "🔗", # link
"context_probability": "🔗",
"tone_ambiguity": "🎵", # musical note
"syntax_error": "⚠️", # warning
}
Table Functions
create_error_table
Creates a formatted table for displaying spelling errors:
from myspellchecker.utils.console import create_error_table, get_console
console = get_console()
# Create an empty table with predefined columns
table = create_error_table(title="Spelling Errors")
# Add rows for each error (Line, Pos, Type, Error, Suggestions)
table.add_row("1", "5", "syllable", "ကျောင့်", "ကျောင်း")
table.add_row("3", "12", "word", "သြား", "သွား")
console.print(table)
Output:
| Type | Word | Suggestion | Context |
|---|
| syllable | ကျောင့် | ကျောင်း | …text… |
| word | သြား | သွား | …text… |
create_stats_table
Creates a statistics summary table:
from myspellchecker.utils.console import create_stats_table
stats = {
"total_words": 1234,
"errors_found": 45,
"error_rate": "3.6%",
"processing_time": "2.3s",
}
table = create_stats_table(stats, title="Check Statistics")
console.print(table)
Custom Suggestion Display
To display suggestions, create a custom table:
from rich.table import Table
from myspellchecker.utils.console import get_console
console = get_console()
# Create a custom table for suggestions
table = Table(title="Suggestions for ကျောင့်")
table.add_column("Word", style="myanmar")
table.add_column("Score", justify="right")
table.add_column("Frequency", justify="right")
table.add_row("ကျောင်း", "0.95", "12345")
table.add_row("ကြောင်း", "0.85", "8765")
console.print(table)
Panel Functions
create_summary_panel
Creates a summary panel for spell check results:
from myspellchecker.utils.console import create_summary_panel, get_console
console = get_console()
panel = create_summary_panel(
error_count=3,
line_count=150,
file_name="input.txt", # optional
)
console.print(panel)
Creates a header panel for build operations:
from myspellchecker.utils.console import create_build_header_panel, get_console
console = get_console()
panel = create_build_header_panel(
input_files=["corpus.txt", "extra.txt"],
database_path="mydict.db",
sample=False, # set True for sample generation mode
)
console.print(panel)
PipelineConsole
Console wrapper for pipeline output with Rich formatting (colors disabled for structured output). Constructed with PipelineConsole(force_plain=False).
Step Tracking
from myspellchecker.utils.console import PipelineConsole
pc = PipelineConsole()
# Track pipeline steps
pc.step_start(1, 5, "Ingesting corpus")
# ... do work ...
pc.step_complete(1, 5, "Ingesting corpus", duration="2.3s")
# Skip a step with a reason
pc.step_skipped(2, 5, "Incremental update", reason="No new files")
Schema and Statistics
# Record verified database tables
pc.table_verified("syllables")
pc.table_verified("words")
pc.table_verified("bigrams")
pc.show_schema_summary()
# Show statistics table
pc.show_stats({"Syllables": 5000, "Words": 12000}, title="Database Statistics")
# Show sample data from a list of dictionaries
pc.show_sample_data("Sample Syllables", [
{"Syllable": "ကျွန်", "Frequency": 1234},
{"Syllable": "တော်", "Frequency": 5678},
])
Pipeline-Specific Panels
# Show hydration results (incremental updates)
pc.show_hydration(syllables=5000, words=12000, files=3)
# Show word ID mapping results
pc.show_word_mapping(count=12000)
Message Methods
pc.info("Processing file...")
pc.success("Build completed")
pc.warning("Missing optional data")
pc.error("Failed to read corpus")
pc.step("Loading syllable rules") # indented with arrow
CLI Output Examples
Standard Check Output
def display_check_result(result):
"""Display spell check results in CLI."""
from myspellchecker.utils.console import (
get_console,
create_error_table,
create_summary_panel,
)
console = get_console()
if result.errors:
table = create_error_table(title="Spell Check Results")
for error in result.errors:
table.add_row(
str(error.line),
str(error.position),
error.error_type,
error.text,
", ".join(error.suggestions[:3]),
)
console.print(table)
panel = create_summary_panel(
error_count=len(result.errors),
line_count=result.line_count,
file_name=result.file_name,
)
console.print(panel)
Build Progress Output
def display_build_progress(stage, progress, message):
"""Display build pipeline progress."""
from myspellchecker.utils.console import get_console
console = get_console()
console.print(f"[info]{stage}[/info]: {message}")
console.print(f" Progress: [muted]{progress}%[/muted]")
Integration with argparse CLI
The console utilities integrate with the argparse-based CLI commands:
import argparse
from myspellchecker.utils.console import get_console, create_error_table
def check_command(args):
"""Check a file for spelling errors."""
console = get_console()
console.print(f"[info]Checking {args.file}...[/info]")
result = checker.check(text)
if result.errors:
table = create_error_table()
for error in result.errors:
table.add_row(
"1", # line
str(error.position),
error.error_type,
error.text,
", ".join(error.suggestions[:3]),
)
console.print(table)
console.print(f"[error]Found {len(result.errors)} errors[/error]")
else:
console.print("[success]No errors found![/success]")
parser = argparse.ArgumentParser()
parser.add_argument("file")
args = parser.parse_args()
check_command(args)
Configuration
Console Settings
from myspellchecker.utils.console import get_console
# Get console with specific settings
console = get_console(
force_plain=False, # Set True to disable colors/formatting
force_color=False, # Set True to force colors even when not a TTY
)
# Use the console for output
console.print("[success]Check complete![/success]")
Environment Variables
| Variable | Description | Default |
|---|
NO_COLOR | Disable color output (standard convention) | not set |
FORCE_COLOR | Force color output even when not a TTY | not set |
See Also