#!/usr/bin/env node
import color from "picocolors";
import { showMainMenu } from "./lib/menu.js";

while (true) {
  const selected = await showMainMenu();

  console.clear();
  console.log(color.cyan("\n正在启动: " + selected.name + "...\n"));

  try {
    const tool = await import(selected.module);
    const result = await tool.run();
    if (result === "back") continue;
    break;
  } catch (err) {
    console.log(color.yellow("\n⚠️ " + selected.name + " 模块尚未实现"));
    console.log(color.dim(err.message));
    console.log(color.dim("\n按任意键返回主菜单..."));
    await new Promise(resolve => {
      process.stdin.setRawMode(true);
      process.stdin.once("data", () => {
        process.stdin.setRawMode(false);
        resolve();
      });
    });
  }
}
