UNPKG

wxt

Version:

⚡ Next-gen Web Extension Framework

30 lines (29 loc) 831 B
import { wxt } from "./wxt.mjs"; import { styleText } from "node:util"; import readline from "node:readline"; //#region src/core/keyboard-shortcuts.ts /** Function that creates a keyboard shortcut handler for the extension. */ function createKeyboardShortcuts(server) { let rl; const handleInput = (line) => { if (line.trim() === "o") server.restartBrowser(); }; return { start() { this.stop(); rl ??= readline.createInterface({ input: process.stdin, terminal: false }); rl.on("line", handleInput); }, stop() { rl?.removeListener("line", handleInput); }, printHelp(flags) { if (flags.canReopenBrowser) wxt.logger.info(`${styleText("dim", "Press")} ${styleText("bold", "o + enter")} ${styleText("dim", "to reopen the browser")}`); } }; } //#endregion export { createKeyboardShortcuts };