{"version":3,"names":["decodePasteBytes","StdinParser","startInput","callbacks","options","mouse","kittyKeyboard","bracketedPaste","parserOpts","armTimeouts","useKittyKeyboard","onTimeoutFlush","drain","parser","event","read","type","onKey","key","onMouse","onPaste","bytes","onResponse","protocol","sequence","onData","chunk","data","Buffer","isBuffer","from","push","process","stdin","isTTY","setRawMode","resume","on","stdout","write","stop","off","pause","destroy"],"sources":["index.ts"],"sourcesContent":["/**\n * Input handling: connects OpenTUI's StdinParser to the solid-tui screen.\n *\n * Vendored from OpenTUI (MIT): https://github.com/miunau/opentui\n * packages/core/src/lib/stdin-parser.ts + parse.keypress.ts + parse.keypress-kitty.ts\n *                                        + parse.mouse.ts + clock.ts + paste.ts\n *\n * This module provides:\n * - startInput() / stopInput() to manage raw mode and stdin parsing\n * - onKeypress / onMouse / onPaste callbacks for the screen to wire up\n */\nexport type { KeyEventType, ParsedKey } from \"./parse-keypress.ts\";\nexport type {\n\tMouseEventType,\n\tRawMouseEvent,\n\tScrollInfo,\n} from \"./parse-mouse.ts\";\nexport type { PasteMetadata } from \"./paste.ts\";\nexport { decodePasteBytes } from \"./paste.ts\";\nexport {\n\ttype StdinEvent,\n\tStdinParser,\n\ttype StdinParserOptions,\n} from \"./stdin-parser.ts\";\n\nimport type { ParsedKey } from \"./parse-keypress.ts\";\nimport type { RawMouseEvent } from \"./parse-mouse.ts\";\nimport { StdinParser, type StdinParserOptions } from \"./stdin-parser.ts\";\n\nexport interface InputCallbacks {\n\tonKey?: (key: ParsedKey) => void;\n\tonMouse?: (event: RawMouseEvent) => void;\n\tonPaste?: (bytes: Uint8Array) => void;\n\tonResponse?: (protocol: string, sequence: string) => void;\n}\n\nexport interface InputHandle {\n\t/** The underlying parser — for protocol context updates. */\n\tparser: StdinParser;\n\t/** Stop listening and restore terminal. */\n\tstop(): void;\n}\n\n/**\n * Start reading raw stdin and dispatching parsed events.\n * Enables raw mode, bracketed paste, and optionally SGR mouse.\n */\nexport function startInput(\n\tcallbacks: InputCallbacks,\n\toptions: {\n\t\tmouse?: boolean;\n\t\tkittyKeyboard?: boolean;\n\t\tbracketedPaste?: boolean;\n\t} = {},\n): InputHandle {\n\tconst mouse = options.mouse ?? false;\n\tconst kittyKeyboard = options.kittyKeyboard ?? false;\n\tconst bracketedPaste = options.bracketedPaste ?? true;\n\n\tconst parserOpts: StdinParserOptions = {\n\t\tarmTimeouts: true,\n\t\tuseKittyKeyboard: kittyKeyboard,\n\t\tonTimeoutFlush: () => drain(),\n\t};\n\n\tconst parser = new StdinParser(parserOpts);\n\n\tfunction drain() {\n\t\t// A callback may tear the screen down mid-drain (e.g. an input handler\n\t\t// that calls screen.unmount() to return to a menu), which destroys the\n\t\t// parser. Stop quietly rather than reading from a destroyed parser.\n\t\ttry {\n\t\t\tlet event = parser.read();\n\t\t\twhile (event !== null) {\n\t\t\t\tswitch (event.type) {\n\t\t\t\t\tcase \"key\":\n\t\t\t\t\t\tcallbacks.onKey?.(event.key);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"mouse\":\n\t\t\t\t\t\tcallbacks.onMouse?.(event.event);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"paste\":\n\t\t\t\t\t\tcallbacks.onPaste?.(event.bytes);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"response\":\n\t\t\t\t\t\tcallbacks.onResponse?.(event.protocol, event.sequence);\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tevent = parser.read();\n\t\t\t}\n\t\t} catch {\n\t\t\t// Parser destroyed by a callback — nothing left to drain.\n\t\t}\n\t}\n\n\tfunction onData(chunk: Buffer | string) {\n\t\tconst data = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk as string);\n\t\tparser.push(data);\n\t\tdrain();\n\t}\n\n\t// Enable raw mode\n\tif (process.stdin.isTTY) {\n\t\tprocess.stdin.setRawMode(true);\n\t}\n\tprocess.stdin.resume();\n\tprocess.stdin.on(\"data\", onData);\n\n\t// Enable terminal protocols\n\tif (bracketedPaste) {\n\t\tprocess.stdout.write(\"\\x1b[?2004h\"); // Enable bracketed paste\n\t}\n\tif (mouse) {\n\t\tprocess.stdout.write(\"\\x1b[?1006h\"); // Enable SGR mouse\n\t\tprocess.stdout.write(\"\\x1b[?1003h\"); // Enable all mouse tracking\n\t}\n\tif (kittyKeyboard) {\n\t\tprocess.stdout.write(\"\\x1b[>1u\"); // Enable kitty keyboard (disambiguate)\n\t}\n\n\treturn {\n\t\tparser,\n\t\tstop() {\n\t\t\tprocess.stdin.off(\"data\", onData);\n\t\t\tprocess.stdin.pause();\n\t\t\tif (process.stdin.isTTY) {\n\t\t\t\tprocess.stdin.setRawMode(false);\n\t\t\t}\n\n\t\t\t// Disable terminal protocols\n\t\t\tif (kittyKeyboard) {\n\t\t\t\tprocess.stdout.write(\"\\x1b[<u\"); // Pop kitty keyboard\n\t\t\t}\n\t\t\tif (mouse) {\n\t\t\t\tprocess.stdout.write(\"\\x1b[?1003l\"); // Disable mouse tracking\n\t\t\t\tprocess.stdout.write(\"\\x1b[?1006l\"); // Disable SGR mouse\n\t\t\t}\n\t\t\tif (bracketedPaste) {\n\t\t\t\tprocess.stdout.write(\"\\x1b[?2004l\"); // Disable bracketed paste\n\t\t\t}\n\n\t\t\tparser.destroy();\n\t\t},\n\t};\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAQA,SAASA,gBAAgB,QAAQ,YAAY;AAC7C,SAECC,WAAW,QAEL,mBAAmB;AAI1B,SAASA,WAAW,QAAiC,mBAAmB;AAgBxE;AACA;AACA;AACA;AACA,OAAO,SAASC,UAAUA,CACzBC,SAAyB,EACzBC,OAIC,GAAG,CAAC,CAAC,EACQ;EACd,MAAMC,KAAK,GAAGD,OAAO,CAACC,KAAK,IAAI,KAAK;EACpC,MAAMC,aAAa,GAAGF,OAAO,CAACE,aAAa,IAAI,KAAK;EACpD,MAAMC,cAAc,GAAGH,OAAO,CAACG,cAAc,IAAI,I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