from rich import print
import os
from pathlib import Path
import sys

def get_extension(filepath):
    return Path(filepath).suffix.lstrip(".").lower()

def main(directory=None):
    directory = Path(directory or os.getcwd())

    if not directory.exists():
        print("[bold red]Directory not found![/bold red]")
        return

    files = {}

    for item in directory.iterdir():
        if not item.is_file():
            continue

        ext = get_extension(item.name)
        files.setdefault(ext, []).append(item.name)

    for extension in sorted(files):
        print(f"[bold red].{extension or 'No Extension'}[/bold red]")
        print("-" * 30)

        for i, file in enumerate(sorted(files[extension]), start=1):
            print(f"[bold cyan]{i}.[/bold cyan] [bold green]{file}[/bold green]")

        print()

    input("Press Enter to continue...")
