from .util import get_package_index, installed_libs from .console import console from rich.table import Table from rich.box import ROUNDED def search(args): index = get_package_index() installed = installed_libs() matching_keys = [key for key in index if args.query in key and not (not args.show_installed and key in installed)] if args.limit >= 0: matching_keys = matching_keys[:args.limit] if len(matching_keys) == 0: console.print("Search returned no results.") return table = Table("Rock", "Description", header_style="bold blue", box=ROUNDED, title="Search Results") for i, key in enumerate(matching_keys): rock = index[key] table.add_row(f"[b]{key}[/]", rock.get("description", "")) console.print(table)