import App from "./app.js";
import { dumpLocalStorage, loadLocalStorage } from "../src/runtime/node.js";

async function main() {
  await loadLocalStorage();
  globalThis.dumpLocalStorage = async () => await dumpLocalStorage();

  const app = new App();
  app.io(
    (repl) => process.stdin.on("data", (data) => repl(data.toString().trim())),
    (data, isRepl) => process.stdout.write(`${data}${isRepl ? "\n>" : ""}`),
    (code) => process.exit(code),
  );
  await app.initial();
}

main();

// process.stdin.setRawMode(true);

// process.openStdin().on('keypress', function (chunk, key) {
//   process.stdout.write('Get Chunk: ' + chunk + '\n');
//   if (key && key.ctrl && key.name == 'c') process.exit();
// });
