mepcli 1.3.2 → 2.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (291) hide show
  1. package/README.md +11 -2
  2. package/dist/{ansi.js → src/ansi.js} +17 -9
  3. package/dist/src/ansi.js.map +1 -0
  4. package/dist/{base.js → src/base.js} +82 -70
  5. package/dist/src/base.js.map +1 -0
  6. package/dist/{core.js → src/core.js} +266 -320
  7. package/dist/src/core.js.map +1 -0
  8. package/dist/src/data/countries.js +569 -0
  9. package/dist/src/data/countries.js.map +1 -0
  10. package/dist/src/data/licenses.js +480 -0
  11. package/dist/src/data/licenses.js.map +1 -0
  12. package/dist/{highlight.js → src/highlight.js} +77 -69
  13. package/dist/src/highlight.js.map +1 -0
  14. package/dist/src/index.js +66 -0
  15. package/dist/src/index.js.map +1 -0
  16. package/dist/{input.js → src/input.js} +47 -41
  17. package/dist/src/input.js.map +1 -0
  18. package/dist/src/pipeline.js +273 -0
  19. package/dist/src/pipeline.js.map +1 -0
  20. package/dist/{prompts → src/prompts}/autocomplete.js +58 -57
  21. package/dist/src/prompts/autocomplete.js.map +1 -0
  22. package/dist/{prompts → src/prompts}/box.js +86 -53
  23. package/dist/src/prompts/box.js.map +1 -0
  24. package/dist/{prompts → src/prompts}/breadcrumb-search.js +110 -98
  25. package/dist/src/prompts/breadcrumb-search.js.map +1 -0
  26. package/dist/{prompts → src/prompts}/breadcrumb.js +126 -121
  27. package/dist/src/prompts/breadcrumb.js.map +1 -0
  28. package/dist/{prompts → src/prompts}/byte.js +69 -52
  29. package/dist/src/prompts/byte.js.map +1 -0
  30. package/dist/{prompts → src/prompts}/calculator.js +79 -56
  31. package/dist/src/prompts/calculator.js.map +1 -0
  32. package/dist/{prompts → src/prompts}/calendar.js +167 -127
  33. package/dist/src/prompts/calendar.js.map +1 -0
  34. package/dist/{prompts → src/prompts}/checkbox.js +53 -49
  35. package/dist/src/prompts/checkbox.js.map +1 -0
  36. package/dist/{prompts → src/prompts}/code.js +88 -76
  37. package/dist/src/prompts/code.js.map +1 -0
  38. package/dist/{prompts → src/prompts}/color.js +68 -50
  39. package/dist/src/prompts/color.js.map +1 -0
  40. package/dist/{prompts → src/prompts}/confirm.js +22 -15
  41. package/dist/src/prompts/confirm.js.map +1 -0
  42. package/dist/{prompts → src/prompts}/connection-string.js +59 -36
  43. package/dist/src/prompts/connection-string.js.map +1 -0
  44. package/dist/{prompts → src/prompts}/cron.js +90 -59
  45. package/dist/src/prompts/cron.js.map +1 -0
  46. package/dist/src/prompts/curl-utils.js +71 -0
  47. package/dist/src/prompts/curl-utils.js.map +1 -0
  48. package/dist/{prompts → src/prompts}/curl.js +153 -132
  49. package/dist/src/prompts/curl.js.map +1 -0
  50. package/dist/{prompts → src/prompts}/data-inspector.js +96 -91
  51. package/dist/src/prompts/data-inspector.js.map +1 -0
  52. package/dist/{prompts → src/prompts}/date.js +64 -57
  53. package/dist/src/prompts/date.js.map +1 -0
  54. package/dist/{prompts → src/prompts}/dependency.js +84 -80
  55. package/dist/src/prompts/dependency.js.map +1 -0
  56. package/dist/{prompts → src/prompts}/dial.js +49 -35
  57. package/dist/src/prompts/dial.js.map +1 -0
  58. package/dist/src/prompts/diff.js +118 -0
  59. package/dist/src/prompts/diff.js.map +1 -0
  60. package/dist/{prompts → src/prompts}/draw.js +83 -80
  61. package/dist/src/prompts/draw.js.map +1 -0
  62. package/dist/src/prompts/editor.js +234 -0
  63. package/dist/src/prompts/editor.js.map +1 -0
  64. package/dist/{prompts → src/prompts}/emoji.js +80 -82
  65. package/dist/src/prompts/emoji.js.map +1 -0
  66. package/dist/{prompts → src/prompts}/exec.js +60 -46
  67. package/dist/src/prompts/exec.js.map +1 -0
  68. package/dist/src/prompts/file.js +217 -0
  69. package/dist/src/prompts/file.js.map +1 -0
  70. package/dist/{prompts → src/prompts}/form.js +63 -54
  71. package/dist/src/prompts/form.js.map +1 -0
  72. package/dist/{prompts → src/prompts}/fuzzy-multi-column.js +65 -53
  73. package/dist/src/prompts/fuzzy-multi-column.js.map +1 -0
  74. package/dist/{prompts → src/prompts}/fuzzy.js +66 -55
  75. package/dist/src/prompts/fuzzy.js.map +1 -0
  76. package/dist/src/prompts/gauge.js +137 -0
  77. package/dist/src/prompts/gauge.js.map +1 -0
  78. package/dist/{prompts → src/prompts}/grid.js +70 -57
  79. package/dist/src/prompts/grid.js.map +1 -0
  80. package/dist/{prompts → src/prompts}/heatmap.js +70 -64
  81. package/dist/src/prompts/heatmap.js.map +1 -0
  82. package/dist/{prompts → src/prompts}/ip.js +56 -36
  83. package/dist/src/prompts/ip.js.map +1 -0
  84. package/dist/{prompts → src/prompts}/kanban.js +63 -58
  85. package/dist/src/prompts/kanban.js.map +1 -0
  86. package/dist/src/prompts/keypress.js +54 -0
  87. package/dist/src/prompts/keypress.js.map +1 -0
  88. package/dist/src/prompts/license.js +144 -0
  89. package/dist/src/prompts/license.js.map +1 -0
  90. package/dist/{prompts → src/prompts}/list.js +46 -31
  91. package/dist/src/prompts/list.js.map +1 -0
  92. package/dist/{prompts → src/prompts}/map.js +93 -77
  93. package/dist/src/prompts/map.js.map +1 -0
  94. package/dist/{prompts → src/prompts}/match.js +91 -95
  95. package/dist/src/prompts/match.js.map +1 -0
  96. package/dist/{prompts → src/prompts}/miller.js +74 -67
  97. package/dist/src/prompts/miller.js.map +1 -0
  98. package/dist/{prompts → src/prompts}/multi-column-select.js +54 -44
  99. package/dist/src/prompts/multi-column-select.js.map +1 -0
  100. package/dist/{prompts → src/prompts}/multi-range.js +70 -52
  101. package/dist/src/prompts/multi-range.js.map +1 -0
  102. package/dist/{prompts → src/prompts}/multi-select.js +67 -58
  103. package/dist/src/prompts/multi-select.js.map +1 -0
  104. package/dist/{prompts → src/prompts}/number.js +51 -39
  105. package/dist/src/prompts/number.js.map +1 -0
  106. package/dist/{prompts → src/prompts}/otp.js +43 -27
  107. package/dist/src/prompts/otp.js.map +1 -0
  108. package/dist/{prompts → src/prompts}/pattern.js +74 -71
  109. package/dist/src/prompts/pattern.js.map +1 -0
  110. package/dist/{prompts → src/prompts}/phone.js +107 -118
  111. package/dist/src/prompts/phone.js.map +1 -0
  112. package/dist/src/prompts/quiz-select.js +114 -0
  113. package/dist/src/prompts/quiz-select.js.map +1 -0
  114. package/dist/src/prompts/quiz-text.js +98 -0
  115. package/dist/src/prompts/quiz-text.js.map +1 -0
  116. package/dist/{prompts → src/prompts}/range.js +85 -61
  117. package/dist/src/prompts/range.js.map +1 -0
  118. package/dist/{prompts → src/prompts}/rating.js +29 -24
  119. package/dist/src/prompts/rating.js.map +1 -0
  120. package/dist/{prompts → src/prompts}/regex.js +50 -36
  121. package/dist/src/prompts/regex.js.map +1 -0
  122. package/dist/{prompts → src/prompts}/region.js +62 -56
  123. package/dist/src/prompts/region.js.map +1 -0
  124. package/dist/{prompts → src/prompts}/schedule.js +82 -75
  125. package/dist/src/prompts/schedule.js.map +1 -0
  126. package/dist/{prompts → src/prompts}/scroll.js +61 -58
  127. package/dist/src/prompts/scroll.js.map +1 -0
  128. package/dist/src/prompts/seat.js +164 -0
  129. package/dist/src/prompts/seat.js.map +1 -0
  130. package/dist/{prompts → src/prompts}/select-range.js +58 -46
  131. package/dist/src/prompts/select-range.js.map +1 -0
  132. package/dist/{prompts → src/prompts}/select.js +65 -66
  133. package/dist/src/prompts/select.js.map +1 -0
  134. package/dist/{prompts → src/prompts}/semver.js +24 -13
  135. package/dist/src/prompts/semver.js.map +1 -0
  136. package/dist/src/prompts/shortcut.js +133 -0
  137. package/dist/src/prompts/shortcut.js.map +1 -0
  138. package/dist/{prompts → src/prompts}/slider.js +28 -23
  139. package/dist/src/prompts/slider.js.map +1 -0
  140. package/dist/src/prompts/slot.js +117 -0
  141. package/dist/src/prompts/slot.js.map +1 -0
  142. package/dist/{prompts → src/prompts}/snippet.js +82 -61
  143. package/dist/src/prompts/snippet.js.map +1 -0
  144. package/dist/{prompts → src/prompts}/sort-grid.js +64 -59
  145. package/dist/src/prompts/sort-grid.js.map +1 -0
  146. package/dist/{prompts → src/prompts}/sort.js +59 -49
  147. package/dist/src/prompts/sort.js.map +1 -0
  148. package/dist/src/prompts/spam.js +80 -0
  149. package/dist/src/prompts/spam.js.map +1 -0
  150. package/dist/{prompts → src/prompts}/spreadsheet.js +71 -70
  151. package/dist/src/prompts/spreadsheet.js.map +1 -0
  152. package/dist/{prompts → src/prompts}/table.js +52 -38
  153. package/dist/src/prompts/table.js.map +1 -0
  154. package/dist/{prompts → src/prompts}/text.js +74 -70
  155. package/dist/src/prompts/text.js.map +1 -0
  156. package/dist/{prompts → src/prompts}/time.js +105 -96
  157. package/dist/src/prompts/time.js.map +1 -0
  158. package/dist/src/prompts/toggle.js +53 -0
  159. package/dist/src/prompts/toggle.js.map +1 -0
  160. package/dist/{prompts → src/prompts}/transfer.js +71 -67
  161. package/dist/src/prompts/transfer.js.map +1 -0
  162. package/dist/{prompts → src/prompts}/tree-select.js +83 -86
  163. package/dist/src/prompts/tree-select.js.map +1 -0
  164. package/dist/{prompts → src/prompts}/tree.js +69 -67
  165. package/dist/src/prompts/tree.js.map +1 -0
  166. package/dist/src/prompts/wait.js +79 -0
  167. package/dist/src/prompts/wait.js.map +1 -0
  168. package/dist/src/spinner.js +105 -0
  169. package/dist/src/spinner.js.map +1 -0
  170. package/dist/{symbols.js → src/symbols.js} +32 -7
  171. package/dist/src/symbols.js.map +1 -0
  172. package/dist/{tasks.js → src/tasks.js} +104 -79
  173. package/dist/src/tasks.js.map +1 -0
  174. package/dist/src/theme.js +29 -0
  175. package/dist/src/theme.js.map +1 -0
  176. package/dist/src/types.js +8 -0
  177. package/dist/src/types.js.map +1 -0
  178. package/dist/{utils.js → src/utils.js} +196 -152
  179. package/dist/src/utils.js.map +1 -0
  180. package/package.json +16 -13
  181. package/dist/ansi.d.ts +0 -36
  182. package/dist/base.d.ts +0 -60
  183. package/dist/core.d.ts +0 -1072
  184. package/dist/data/countries.d.ts +0 -2
  185. package/dist/data/countries.js +0 -105
  186. package/dist/data/licenses.d.ts +0 -2
  187. package/dist/data/licenses.js +0 -109
  188. package/dist/highlight.d.ts +0 -7
  189. package/dist/index.d.ts +0 -48
  190. package/dist/index.js +0 -64
  191. package/dist/input.d.ts +0 -14
  192. package/dist/pipeline.d.ts +0 -39
  193. package/dist/pipeline.js +0 -54
  194. package/dist/prompts/autocomplete.d.ts +0 -22
  195. package/dist/prompts/box.d.ts +0 -21
  196. package/dist/prompts/breadcrumb-search.d.ts +0 -14
  197. package/dist/prompts/breadcrumb.d.ts +0 -32
  198. package/dist/prompts/byte.d.ts +0 -13
  199. package/dist/prompts/calculator.d.ts +0 -17
  200. package/dist/prompts/calendar.d.ts +0 -33
  201. package/dist/prompts/checkbox.d.ts +0 -13
  202. package/dist/prompts/code.d.ts +0 -19
  203. package/dist/prompts/color.d.ts +0 -14
  204. package/dist/prompts/confirm.d.ts +0 -8
  205. package/dist/prompts/connection-string.d.ts +0 -18
  206. package/dist/prompts/cron.d.ts +0 -13
  207. package/dist/prompts/curl-utils.d.ts +0 -25
  208. package/dist/prompts/curl-utils.js +0 -41
  209. package/dist/prompts/curl.d.ts +0 -41
  210. package/dist/prompts/data-inspector.d.ts +0 -22
  211. package/dist/prompts/date.d.ts +0 -12
  212. package/dist/prompts/dependency.d.ts +0 -16
  213. package/dist/prompts/dial.d.ts +0 -10
  214. package/dist/prompts/diff.d.ts +0 -10
  215. package/dist/prompts/diff.js +0 -101
  216. package/dist/prompts/draw.d.ts +0 -20
  217. package/dist/prompts/editor.d.ts +0 -14
  218. package/dist/prompts/editor.js +0 -203
  219. package/dist/prompts/emoji.d.ts +0 -18
  220. package/dist/prompts/exec.d.ts +0 -17
  221. package/dist/prompts/file.d.ts +0 -21
  222. package/dist/prompts/file.js +0 -210
  223. package/dist/prompts/form.d.ts +0 -18
  224. package/dist/prompts/fuzzy-multi-column.d.ts +0 -12
  225. package/dist/prompts/fuzzy.d.ts +0 -12
  226. package/dist/prompts/gauge.d.ts +0 -21
  227. package/dist/prompts/gauge.js +0 -130
  228. package/dist/prompts/grid.d.ts +0 -14
  229. package/dist/prompts/heatmap.d.ts +0 -13
  230. package/dist/prompts/ip.d.ts +0 -11
  231. package/dist/prompts/kanban.d.ts +0 -17
  232. package/dist/prompts/keypress.d.ts +0 -7
  233. package/dist/prompts/keypress.js +0 -55
  234. package/dist/prompts/license.d.ts +0 -9
  235. package/dist/prompts/license.js +0 -105
  236. package/dist/prompts/list.d.ts +0 -9
  237. package/dist/prompts/map.d.ts +0 -17
  238. package/dist/prompts/match.d.ts +0 -19
  239. package/dist/prompts/miller.d.ts +0 -15
  240. package/dist/prompts/multi-column-select.d.ts +0 -10
  241. package/dist/prompts/multi-range.d.ts +0 -9
  242. package/dist/prompts/multi-select.d.ts +0 -15
  243. package/dist/prompts/number.d.ts +0 -11
  244. package/dist/prompts/otp.d.ts +0 -10
  245. package/dist/prompts/pattern.d.ts +0 -22
  246. package/dist/prompts/phone.d.ts +0 -41
  247. package/dist/prompts/quiz-select.d.ts +0 -10
  248. package/dist/prompts/quiz-select.js +0 -104
  249. package/dist/prompts/quiz-text.d.ts +0 -11
  250. package/dist/prompts/quiz-text.js +0 -82
  251. package/dist/prompts/range.d.ts +0 -9
  252. package/dist/prompts/rating.d.ts +0 -8
  253. package/dist/prompts/regex.d.ts +0 -13
  254. package/dist/prompts/region.d.ts +0 -11
  255. package/dist/prompts/schedule.d.ts +0 -20
  256. package/dist/prompts/scroll.d.ts +0 -13
  257. package/dist/prompts/seat.d.ts +0 -17
  258. package/dist/prompts/seat.js +0 -165
  259. package/dist/prompts/select-range.d.ts +0 -8
  260. package/dist/prompts/select.d.ts +0 -15
  261. package/dist/prompts/semver.d.ts +0 -6
  262. package/dist/prompts/shortcut.d.ts +0 -9
  263. package/dist/prompts/shortcut.js +0 -135
  264. package/dist/prompts/slider.d.ts +0 -8
  265. package/dist/prompts/slot.d.ts +0 -16
  266. package/dist/prompts/slot.js +0 -107
  267. package/dist/prompts/snippet.d.ts +0 -19
  268. package/dist/prompts/sort-grid.d.ts +0 -16
  269. package/dist/prompts/sort.d.ts +0 -14
  270. package/dist/prompts/spam.d.ts +0 -17
  271. package/dist/prompts/spam.js +0 -62
  272. package/dist/prompts/spreadsheet.d.ts +0 -21
  273. package/dist/prompts/table.d.ts +0 -14
  274. package/dist/prompts/text.d.ts +0 -17
  275. package/dist/prompts/time.d.ts +0 -12
  276. package/dist/prompts/toggle.d.ts +0 -8
  277. package/dist/prompts/toggle.js +0 -47
  278. package/dist/prompts/transfer.d.ts +0 -18
  279. package/dist/prompts/tree-select.d.ts +0 -31
  280. package/dist/prompts/tree.d.ts +0 -20
  281. package/dist/prompts/wait.d.ts +0 -18
  282. package/dist/prompts/wait.js +0 -62
  283. package/dist/spinner.d.ts +0 -33
  284. package/dist/spinner.js +0 -89
  285. package/dist/symbols.d.ts +0 -33
  286. package/dist/tasks.d.ts +0 -57
  287. package/dist/theme.d.ts +0 -2
  288. package/dist/theme.js +0 -20
  289. package/dist/types.d.ts +0 -503
  290. package/dist/types.js +0 -5
  291. package/dist/utils.d.ts +0 -81
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/prompts/diff.ts"],"sourcesContent":["import { Prompt } from '../base';\nimport { DiffOptions } from '../types';\nimport { theme } from '../theme';\nimport { ANSI } from '../ansi';\nimport { EditorPrompt } from './editor';\n\nexport class DiffPrompt extends Prompt<string, DiffOptions> {\n private activeAction: number = 0; // 0: Original, 1: Modified, 2: Edit\n private actions = ['Use Original', 'Use Modified', 'Edit'];\n\n constructor(options: DiffOptions) {\n super(options);\n }\n\n protected render(_firstRender: boolean) {\n let output = `${theme.title}${this.options.message}${ANSI.RESET}\\n`;\n\n // Render Diff\n const originalLines = this.options.original ? this.options.original.split('\\n') : [];\n const modifiedLines = this.options.modified ? this.options.modified.split('\\n') : [];\n\n const width = Math.max(40, (this.stdout.columns || 80) - 4);\n const borderTop = `${ANSI.FG_GRAY}┌${'─'.repeat(width)}┐${ANSI.RESET}`;\n const borderMid = `${ANSI.FG_GRAY}├${'─'.repeat(width)}┤${ANSI.RESET}`;\n const borderBot = `${ANSI.FG_GRAY}└${'─'.repeat(width)}┘${ANSI.RESET}`;\n\n output += borderTop + '\\n';\n\n // Original (Red)\n if (originalLines.length === 0) {\n output += `${ANSI.FG_GRAY}│ ${ANSI.DIM}(empty)${ANSI.RESET}\\n`;\n } else {\n originalLines.forEach(line => {\n const truncated = this.truncate(line, width - 4);\n output += `${ANSI.FG_GRAY}│ ${ANSI.FG_RED}- ${truncated}${ANSI.RESET}\\n`;\n });\n }\n\n output += borderMid + '\\n';\n\n // Modified (Green)\n if (modifiedLines.length === 0) {\n output += `${ANSI.FG_GRAY}│ ${ANSI.DIM}(empty)${ANSI.RESET}\\n`;\n } else {\n modifiedLines.forEach(line => {\n const truncated = this.truncate(line, width - 4);\n output += `${ANSI.FG_GRAY}│ ${ANSI.FG_GREEN}+ ${truncated}${ANSI.RESET}\\n`;\n });\n }\n\n output += borderBot + '\\n';\n\n // Render Actions\n output += '\\n';\n this.actions.forEach((action, index) => {\n if (index === this.activeAction) {\n output += `${ANSI.REVERSE} ${action} ${ANSI.RESET} `;\n } else {\n output += `[ ${action} ] `;\n }\n });\n\n this.renderFrame(output);\n }\n\n protected handleInput(char: string, _key: Buffer) {\n if (this.isLeft(char)) {\n this.activeAction = (this.activeAction - 1 + this.actions.length) % this.actions.length;\n this.render(false);\n } else if (this.isRight(char)) {\n this.activeAction = (this.activeAction + 1) % this.actions.length;\n this.render(false);\n } else if (char === '\\r' || char === '\\n') {\n this.handleSubmit();\n }\n }\n\n private handleSubmit() {\n if (this.activeAction === 0) {\n this.submit(this.options.original);\n } else if (this.activeAction === 1) {\n this.submit(this.options.modified);\n } else {\n // Edit\n this.cleanup(); // Stop listening to input for this prompt\n\n // Prepare initial content for editor\n const initial = `<<<<<<< ORIGINAL\n${this.options.original}\n=======\n${this.options.modified}\n>>>>>>> MODIFIED`;\n\n // We delegate to EditorPrompt\n new EditorPrompt({\n message: 'Resolve conflict (Edit)',\n initial: initial,\n extension: '.txt',\n waitUserInput: false // Launch immediately\n }).run().then(result => {\n this.submit(result);\n }).catch(_err => {\n this.submit(initial);\n });\n }\n }\n}\n"],"names":["DiffPrompt","Prompt","render","_firstRender","output","theme","title","options","message","ANSI","RESET","originalLines","original","split","modifiedLines","modified","width","Math","max","stdout","columns","borderTop","FG_GRAY","repeat","borderMid","borderBot","length","DIM","forEach","line","truncated","truncate","FG_RED","FG_GREEN","actions","action","index","activeAction","REVERSE","renderFrame","handleInput","char","_key","isLeft","isRight","handleSubmit","submit","cleanup","initial","EditorPrompt","extension","waitUserInput","run","then","result","catch","_err"],"mappings":";;;;+BAMaA;;;eAAAA;;;sBANU;uBAED;sBACD;wBACQ;;;;;;;;;;;;;;AAEtB,IAAA,AAAMA,aAAN,MAAMA,mBAAmBC,YAAM;IAQxBC,OAAOC,YAAqB,EAAE;QACpC,IAAIC,SAAS,GAAGC,YAAK,CAACC,KAAK,GAAG,IAAI,CAACC,OAAO,CAACC,OAAO,GAAGC,UAAI,CAACC,KAAK,CAAC,EAAE,CAAC;QAEnE,cAAc;QACd,MAAMC,gBAAgB,IAAI,CAACJ,OAAO,CAACK,QAAQ,GAAG,IAAI,CAACL,OAAO,CAACK,QAAQ,CAACC,KAAK,CAAC,QAAQ,EAAE;QACpF,MAAMC,gBAAgB,IAAI,CAACP,OAAO,CAACQ,QAAQ,GAAG,IAAI,CAACR,OAAO,CAACQ,QAAQ,CAACF,KAAK,CAAC,QAAQ,EAAE;QAEpF,MAAMG,QAAQC,KAAKC,GAAG,CAAC,IAAI,AAAC,CAAA,IAAI,CAACC,MAAM,CAACC,OAAO,IAAI,EAAC,IAAK;QACzD,MAAMC,YAAY,GAAGZ,UAAI,CAACa,OAAO,CAAC,CAAC,EAAE,IAAIC,MAAM,CAACP,OAAO,CAAC,EAAEP,UAAI,CAACC,KAAK,EAAE;QACtE,MAAMc,YAAY,GAAGf,UAAI,CAACa,OAAO,CAAC,CAAC,EAAE,IAAIC,MAAM,CAACP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,QAAQ,CAAC;gBACR,CAAC;YAEL,8BAA8B;YAC9B,IAAIkC,oBAAY,CAAC;gBACbzC,SAAS;gBACTwC,SAASA;gBACTE,WAAW;gBACXC,eAAe,MAAM,qBAAqB;YAC9C,GAAGC,GAAG,GAAGC,IAAI,CAACC,CAAAA;gBACV,IAAI,CAACR,MAAM,CAACQ;YAChB,GAAGC,KAAK,CAACC,CAAAA;gBACL,IAAI,CAACV,MAAM,CAACE;YAChB;QACJ;IACJ;IA/FA,YAAYzC,OAAoB,CAAE;QAC9B,KAAK,CAACA,UAJV,uBAAQ8B,gBAAuB,GAAG,oCAAoC;UACtE,uBAAQH,WAAU;YAAC;YAAgB;YAAgB;SAAO;IAI1D;AA8FJ"}
@@ -1,51 +1,44 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DrawPrompt = void 0;
4
- const base_1 = require("../base");
5
- const theme_1 = require("../theme");
6
- const ansi_1 = require("../ansi");
7
- class DrawPrompt extends base_1.Prompt {
8
- constructor(options) {
9
- super(options);
10
- this.cursorX = 0;
11
- this.cursorY = 0;
12
- this.lastMouse = null;
13
- this.gridWidth = options.width * 2;
14
- this.gridHeight = options.height * 4;
15
- if (options.initial) {
16
- // Deep copy to avoid mutating original if passed
17
- this.grid = options.initial.map(row => [...row]);
18
- }
19
- else {
20
- this.grid = [];
21
- for (let y = 0; y < this.gridHeight; y++) {
22
- const row = new Array(this.gridWidth).fill(false);
23
- this.grid.push(row);
24
- }
25
- }
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "DrawPrompt", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return DrawPrompt;
9
+ }
10
+ });
11
+ const _base = require("../base");
12
+ const _theme = require("../theme");
13
+ const _ansi = require("../ansi");
14
+ function _define_property(obj, key, value) {
15
+ if (key in obj) {
16
+ Object.defineProperty(obj, key, {
17
+ value: value,
18
+ enumerable: true,
19
+ configurable: true,
20
+ writable: true
21
+ });
22
+ } else {
23
+ obj[key] = value;
26
24
  }
25
+ return obj;
26
+ }
27
+ let DrawPrompt = class DrawPrompt extends _base.Prompt {
27
28
  getBrailleChar(x, y) {
28
29
  const baseX = x * 2;
29
30
  const baseY = y * 4;
30
31
  let code = 0x2800; // Base Braille
31
32
  // Column 0
32
- if (this.getPixel(baseX, baseY))
33
- code |= 0x1; // Dot 1
34
- if (this.getPixel(baseX, baseY + 1))
35
- code |= 0x2; // Dot 2
36
- if (this.getPixel(baseX, baseY + 2))
37
- code |= 0x4; // Dot 3
38
- if (this.getPixel(baseX, baseY + 3))
39
- code |= 0x40; // Dot 7 (Bottom-left)
33
+ if (this.getPixel(baseX, baseY)) code |= 0x1; // Dot 1
34
+ if (this.getPixel(baseX, baseY + 1)) code |= 0x2; // Dot 2
35
+ if (this.getPixel(baseX, baseY + 2)) code |= 0x4; // Dot 3
36
+ if (this.getPixel(baseX, baseY + 3)) code |= 0x40; // Dot 7 (Bottom-left)
40
37
  // Column 1
41
- if (this.getPixel(baseX + 1, baseY))
42
- code |= 0x8; // Dot 4
43
- if (this.getPixel(baseX + 1, baseY + 1))
44
- code |= 0x10; // Dot 5
45
- if (this.getPixel(baseX + 1, baseY + 2))
46
- code |= 0x20; // Dot 6
47
- if (this.getPixel(baseX + 1, baseY + 3))
48
- code |= 0x80; // Dot 8 (Bottom-right)
38
+ if (this.getPixel(baseX + 1, baseY)) code |= 0x8; // Dot 4
39
+ if (this.getPixel(baseX + 1, baseY + 1)) code |= 0x10; // Dot 5
40
+ if (this.getPixel(baseX + 1, baseY + 2)) code |= 0x20; // Dot 6
41
+ if (this.getPixel(baseX + 1, baseY + 3)) code |= 0x80; // Dot 8 (Bottom-right)
49
42
  return String.fromCharCode(code);
50
43
  }
51
44
  getPixel(x, y) {
@@ -60,60 +53,51 @@ class DrawPrompt extends base_1.Prompt {
60
53
  }
61
54
  }
62
55
  render(_firstRender) {
63
- let output = `${theme_1.theme.title}${this.options.message}${ansi_1.ANSI.RESET}\n`;
64
- output += `${ansi_1.ANSI.FG_GRAY}┌${'─'.repeat(this.options.width + 2)}┐${ansi_1.ANSI.RESET}\n`;
65
- for (let y = 0; y < this.options.height; y++) {
56
+ let output = `${_theme.theme.title}${this.options.message}${_ansi.ANSI.RESET}\n`;
57
+ output += `${_ansi.ANSI.FG_GRAY}┌${'─'.repeat(this.options.width + 2)}┐${_ansi.ANSI.RESET}\n`;
58
+ for(let y = 0; y < this.options.height; y++){
66
59
  let line = '';
67
- for (let x = 0; x < this.options.width; x++) {
60
+ for(let x = 0; x < this.options.width; x++){
68
61
  const char = this.getBrailleChar(x, y);
69
62
  // Highlight cursor position (pixel level approximation)
70
63
  // If cursor is within this character block
71
- const containsCursor = Math.floor(this.cursorX / 2) === x &&
72
- Math.floor(this.cursorY / 4) === y;
64
+ const containsCursor = Math.floor(this.cursorX / 2) === x && Math.floor(this.cursorY / 4) === y;
73
65
  if (containsCursor) {
74
- line += ansi_1.ANSI.REVERSE + char + ansi_1.ANSI.RESET;
75
- }
76
- else {
66
+ line += _ansi.ANSI.REVERSE + char + _ansi.ANSI.RESET;
67
+ } else {
77
68
  line += char;
78
69
  }
79
70
  }
80
- output += `${ansi_1.ANSI.FG_GRAY}│ ${ansi_1.ANSI.RESET}${line} ${ansi_1.ANSI.FG_GRAY}│${ansi_1.ANSI.RESET}\n`;
71
+ output += `${_ansi.ANSI.FG_GRAY}│ ${_ansi.ANSI.RESET}${line} ${_ansi.ANSI.FG_GRAY}│${_ansi.ANSI.RESET}\n`;
81
72
  }
82
- output += `${ansi_1.ANSI.FG_GRAY}└${'─'.repeat(this.options.width + 2)}┘${ansi_1.ANSI.RESET}\n`;
83
- output += `\n${ansi_1.ANSI.FG_GRAY}(Arrows: move, Space: toggle, Mouse: drag, 'c': clear, 'i': invert, Enter: done)${ansi_1.ANSI.RESET}`;
73
+ output += `${_ansi.ANSI.FG_GRAY}└${'─'.repeat(this.options.width + 2)}┘${_ansi.ANSI.RESET}\n`;
74
+ output += `\n${_ansi.ANSI.FG_GRAY}(Arrows: move, Space: toggle, Mouse: drag, 'c': clear, 'i': invert, Enter: done)${_ansi.ANSI.RESET}`;
84
75
  this.renderFrame(output);
85
76
  }
86
77
  handleInput(char, _key) {
87
78
  if (this.isLeft(char)) {
88
79
  this.cursorX = Math.max(0, this.cursorX - 1);
89
80
  this.render(false);
90
- }
91
- else if (this.isRight(char)) {
81
+ } else if (this.isRight(char)) {
92
82
  this.cursorX = Math.min(this.gridWidth - 1, this.cursorX + 1);
93
83
  this.render(false);
94
- }
95
- else if (this.isUp(char)) {
84
+ } else if (this.isUp(char)) {
96
85
  this.cursorY = Math.max(0, this.cursorY - 1);
97
86
  this.render(false);
98
- }
99
- else if (this.isDown(char)) {
87
+ } else if (this.isDown(char)) {
100
88
  this.cursorY = Math.min(this.gridHeight - 1, this.cursorY + 1);
101
89
  this.render(false);
102
- }
103
- else if (char === ' ') {
90
+ } else if (char === ' ') {
104
91
  const current = this.getPixel(this.cursorX, this.cursorY);
105
92
  this.setPixel(this.cursorX, this.cursorY, !current);
106
93
  this.render(false);
107
- }
108
- else if (char === 'c') {
94
+ } else if (char === 'c') {
109
95
  this.clearGrid();
110
96
  this.render(false);
111
- }
112
- else if (char === 'i') {
97
+ } else if (char === 'i') {
113
98
  this.invertGrid();
114
99
  this.render(false);
115
- }
116
- else if (char === '\r' || char === '\n') {
100
+ } else if (char === '\r' || char === '\n') {
117
101
  this.handleSubmit();
118
102
  }
119
103
  }
@@ -135,7 +119,7 @@ class DrawPrompt extends base_1.Prompt {
135
119
  this.cursorX = Math.max(0, Math.min(this.gridWidth - 1, this.cursorX));
136
120
  this.cursorY = Math.max(0, Math.min(this.gridHeight - 1, this.cursorY));
137
121
  // Draw if pressing (Left Button = 0)
138
- if (event.action === 'press' || (event.action === 'move' && event.button === 0)) {
122
+ if (event.action === 'press' || event.action === 'move' && event.button === 0) {
139
123
  this.setPixel(this.cursorX, this.cursorY, true);
140
124
  }
141
125
  // Eraser (Right Button = 2)
@@ -144,25 +128,27 @@ class DrawPrompt extends base_1.Prompt {
144
128
  }
145
129
  this.render(false);
146
130
  }
147
- }
148
- else {
131
+ } else {
149
132
  if (event.action === 'press' && event.button === 0) {
150
133
  this.setPixel(this.cursorX, this.cursorY, true);
151
134
  this.render(false);
152
135
  }
153
136
  }
154
- this.lastMouse = { x: event.x, y: event.y };
137
+ this.lastMouse = {
138
+ x: event.x,
139
+ y: event.y
140
+ };
155
141
  }
156
142
  clearGrid() {
157
- for (let y = 0; y < this.gridHeight; y++) {
158
- for (let x = 0; x < this.gridWidth; x++) {
143
+ for(let y = 0; y < this.gridHeight; y++){
144
+ for(let x = 0; x < this.gridWidth; x++){
159
145
  this.grid[y][x] = false;
160
146
  }
161
147
  }
162
148
  }
163
149
  invertGrid() {
164
- for (let y = 0; y < this.gridHeight; y++) {
165
- for (let x = 0; x < this.gridWidth; x++) {
150
+ for(let y = 0; y < this.gridHeight; y++){
151
+ for(let x = 0; x < this.gridWidth; x++){
166
152
  this.grid[y][x] = !this.grid[y][x];
167
153
  }
168
154
  }
@@ -171,18 +157,35 @@ class DrawPrompt extends base_1.Prompt {
171
157
  if (this.options.exportType === 'text') {
172
158
  // Render to string
173
159
  let result = '';
174
- for (let y = 0; y < this.options.height; y++) {
175
- for (let x = 0; x < this.options.width; x++) {
160
+ for(let y = 0; y < this.options.height; y++){
161
+ for(let x = 0; x < this.options.width; x++){
176
162
  result += this.getBrailleChar(x, y);
177
163
  }
178
164
  result += '\n';
179
165
  }
180
166
  this.submit(result.trim());
181
- }
182
- else {
167
+ } else {
183
168
  // Default: return matrix
184
169
  this.submit(this.grid);
185
170
  }
186
171
  }
187
- }
188
- exports.DrawPrompt = DrawPrompt;
172
+ constructor(options){
173
+ super(options), _define_property(this, "grid", void 0), _define_property(this, "cursorX", 0), _define_property(this, "cursorY", 0), _define_property(this, "gridWidth", void 0), _define_property(this, "gridHeight", void 0), _define_property(this, "lastMouse", null);
174
+ this.gridWidth = options.width * 2;
175
+ this.gridHeight = options.height * 4;
176
+ if (options.initial) {
177
+ // Deep copy to avoid mutating original if passed
178
+ this.grid = options.initial.map((row)=>[
179
+ ...row
180
+ ]);
181
+ } else {
182
+ this.grid = [];
183
+ for(let y = 0; y < this.gridHeight; y++){
184
+ const row = new Array(this.gridWidth).fill(false);
185
+ this.grid.push(row);
186
+ }
187
+ }
188
+ }
189
+ };
190
+
191
+ //# sourceMappingURL=draw.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/prompts/draw.ts"],"sourcesContent":["import { Prompt } from '../base';\nimport { DrawOptions, MouseEvent } from '../types';\nimport { theme } from '../theme';\nimport { ANSI } from '../ansi';\n\nexport class DrawPrompt extends Prompt<string | boolean[][], DrawOptions> {\n private grid: boolean[][];\n private cursorX: number = 0;\n private cursorY: number = 0;\n private gridWidth: number;\n private gridHeight: number;\n private lastMouse: { x: number, y: number } | null = null;\n\n constructor(options: DrawOptions) {\n super(options);\n this.gridWidth = options.width * 2;\n this.gridHeight = options.height * 4;\n\n if (options.initial) {\n // Deep copy to avoid mutating original if passed\n this.grid = options.initial.map(row => [...row]);\n } else {\n this.grid = [];\n for (let y = 0; y < this.gridHeight; y++) {\n const row = new Array(this.gridWidth).fill(false);\n this.grid.push(row);\n }\n }\n }\n\n private getBrailleChar(x: number, y: number): string {\n const baseX = x * 2;\n const baseY = y * 4;\n let code = 0x2800; // Base Braille\n\n // Column 0\n if (this.getPixel(baseX, baseY)) code |= 0x1; // Dot 1\n if (this.getPixel(baseX, baseY + 1)) code |= 0x2; // Dot 2\n if (this.getPixel(baseX, baseY + 2)) code |= 0x4; // Dot 3\n if (this.getPixel(baseX, baseY + 3)) code |= 0x40; // Dot 7 (Bottom-left)\n\n // Column 1\n if (this.getPixel(baseX + 1, baseY)) code |= 0x8; // Dot 4\n if (this.getPixel(baseX + 1, baseY + 1)) code |= 0x10; // Dot 5\n if (this.getPixel(baseX + 1, baseY + 2)) code |= 0x20; // Dot 6\n if (this.getPixel(baseX + 1, baseY + 3)) code |= 0x80; // Dot 8 (Bottom-right)\n\n return String.fromCharCode(code);\n }\n\n private getPixel(x: number, y: number): boolean {\n if (y >= 0 && y < this.gridHeight && x >= 0 && x < this.gridWidth) {\n return this.grid[y][x];\n }\n return false;\n }\n\n private setPixel(x: number, y: number, val: boolean) {\n if (y >= 0 && y < this.gridHeight && x >= 0 && x < this.gridWidth) {\n this.grid[y][x] = val;\n }\n }\n\n protected render(_firstRender: boolean) {\n let output = `${theme.title}${this.options.message}${ANSI.RESET}\\n`;\n\n output += `${ANSI.FG_GRAY}┌${'─'.repeat(this.options.width + 2)}┐${ANSI.RESET}\\n`;\n\n for (let y = 0; y < this.options.height; y++) {\n let line = '';\n for (let x = 0; x < this.options.width; x++) {\n const char = this.getBrailleChar(x, y);\n\n // Highlight cursor position (pixel level approximation)\n // If cursor is within this character block\n const containsCursor =\n Math.floor(this.cursorX / 2) === x &&\n Math.floor(this.cursorY / 4) === y;\n\n if (containsCursor) {\n line += ANSI.REVERSE + char + ANSI.RESET;\n } else {\n line += char;\n }\n }\n output += `${ANSI.FG_GRAY}│ ${ANSI.RESET}${line} ${ANSI.FG_GRAY}│${ANSI.RESET}\\n`;\n }\n\n output += `${ANSI.FG_GRAY}└${'─'.repeat(this.options.width + 2)}┘${ANSI.RESET}\\n`;\n\n output += `\\n${ANSI.FG_GRAY}(Arrows: move, Space: toggle, Mouse: drag, 'c': clear, 'i': invert, Enter: done)${ANSI.RESET}`;\n this.renderFrame(output);\n }\n\n protected handleInput(char: string, _key: Buffer) {\n if (this.isLeft(char)) {\n this.cursorX = Math.max(0, this.cursorX - 1);\n this.render(false);\n } else if (this.isRight(char)) {\n this.cursorX = Math.min(this.gridWidth - 1, this.cursorX + 1);\n this.render(false);\n } else if (this.isUp(char)) {\n this.cursorY = Math.max(0, this.cursorY - 1);\n this.render(false);\n } else if (this.isDown(char)) {\n this.cursorY = Math.min(this.gridHeight - 1, this.cursorY + 1);\n this.render(false);\n } else if (char === ' ') {\n const current = this.getPixel(this.cursorX, this.cursorY);\n this.setPixel(this.cursorX, this.cursorY, !current);\n this.render(false);\n } else if (char === 'c') {\n this.clearGrid();\n this.render(false);\n } else if (char === 'i') {\n this.invertGrid();\n this.render(false);\n } else if (char === '\\r' || char === '\\n') {\n this.handleSubmit();\n }\n }\n\n protected handleMouse(event: MouseEvent) {\n if (event.action === 'release') {\n this.lastMouse = null;\n return;\n }\n\n if (this.lastMouse) {\n const dx = event.x - this.lastMouse.x;\n const dy = event.y - this.lastMouse.y;\n\n // Relative movement: scale to grid density\n // X: 1 char = 2 pixels\n // Y: 1 char = 4 pixels\n if (dx !== 0 || dy !== 0) {\n this.cursorX += dx * 2;\n this.cursorY += dy * 4;\n\n // Clamp\n this.cursorX = Math.max(0, Math.min(this.gridWidth - 1, this.cursorX));\n this.cursorY = Math.max(0, Math.min(this.gridHeight - 1, this.cursorY));\n\n // Draw if pressing (Left Button = 0)\n if (event.action === 'press' || (event.action === 'move' && event.button === 0)) {\n this.setPixel(this.cursorX, this.cursorY, true);\n }\n // Eraser (Right Button = 2)\n if ((event.action === 'press' || event.action === 'move') && event.button === 2) {\n this.setPixel(this.cursorX, this.cursorY, false);\n }\n\n this.render(false);\n }\n } else {\n if (event.action === 'press' && event.button === 0) {\n this.setPixel(this.cursorX, this.cursorY, true);\n this.render(false);\n }\n }\n\n this.lastMouse = { x: event.x, y: event.y };\n }\n\n private clearGrid() {\n for (let y = 0; y < this.gridHeight; y++) {\n for (let x = 0; x < this.gridWidth; x++) {\n this.grid[y][x] = false;\n }\n }\n }\n\n private invertGrid() {\n for (let y = 0; y < this.gridHeight; y++) {\n for (let x = 0; x < this.gridWidth; x++) {\n this.grid[y][x] = !this.grid[y][x];\n }\n }\n }\n\n private handleSubmit() {\n if (this.options.exportType === 'text') {\n // Render to string\n let result = '';\n for (let y = 0; y < this.options.height; y++) {\n for (let x = 0; x < this.options.width; x++) {\n result += this.getBrailleChar(x, y);\n }\n result += '\\n';\n }\n this.submit(result.trim());\n } else {\n // Default: return matrix\n this.submit(this.grid);\n }\n }\n}\n"],"names":["DrawPrompt","Prompt","getBrailleChar","x","y","baseX","baseY","code","getPixel","String","fromCharCode","gridHeight","gridWidth","grid","setPixel","val","render","_firstRender","output","theme","title","options","message","ANSI","RESET","FG_GRAY","repeat","width","height","line","char","containsCursor","Math","floor","cursorX","cursorY","REVERSE","renderFrame","handleInput","_key","isLeft","max","isRight","min","isUp","isDown","current","clearGrid","invertGrid","handleSubmit","handleMouse","event","action","lastMouse","dx","dy","button","exportType","result","submit","trim","initial","map","row","Array","fill","push"],"mappings":";;;;+BAKaA;;;eAAAA;;;sBALU;uBAED;sBACD;;;;;;;;;;;;;;AAEd,IAAA,AAAMA,aAAN,MAAMA,mBAAmBC,YAAM;IAyB1BC,eAAeC,CAAS,EAAEC,CAAS,EAAU;QACjD,MAAMC,QAAQF,IAAI;QAClB,MAAMG,QAAQF,IAAI;QAClB,IAAIG,OAAO,QAAQ,eAAe;QAElC,WAAW;QACX,IAAI,IAAI,CAACC,QAAQ,CAACH,OAAOC,QAAQC,QAAQ,KAAW,QAAQ;QAC5D,IAAI,IAAI,CAACC,QAAQ,CAACH,OAAOC,QAAQ,IAAIC,QAAQ,KAAO,QAAQ;QAC5D,IAAI,IAAI,CAACC,QAAQ,CAACH,OAAOC,QAAQ,IAAIC,QAAQ,KAAO,QAAQ;QAC5D,IAAI,IAAI,CAACC,QAAQ,CAACH,OAAOC,QAAQ,IAAIC,QAAQ,MAAO,sBAAsB;QAE1E,WAAW;QACX,IAAI,IAAI,CAACC,QAAQ,CAACH,QAAQ,GAAGC,QAAQC,QAAQ,KAAW,QAAQ;QAChE,IAAI,IAAI,CAACC,QAAQ,CAACH,QAAQ,GAAGC,QAAQ,IAAIC,QAAQ,MAAO,QAAQ;QAChE,IAAI,IAAI,CAACC,QAAQ,CAACH,QAAQ,GAAGC,QAAQ,IAAIC,QAAQ,MAAO,QAAQ;QAChE,IAAI,IAAI,CAACC,QAAQ,CAACH,QAAQ,G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EAAEP,IAAK;gBACtC,MAAM2D,MAAM,IAAIC,MAAM,IAAI,CAACpD,SAAS,EAAEqD,IAAI,CAAC;gBAC3C,IAAI,CAACpD,IAAI,CAACqD,IAAI,CAACH;YACnB;QACJ;IACJ;AAwKJ"}
@@ -0,0 +1,234 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "EditorPrompt", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return EditorPrompt;
9
+ }
10
+ });
11
+ const _fs = /*#__PURE__*/ _interop_require_wildcard(require("fs"));
12
+ const _os = /*#__PURE__*/ _interop_require_wildcard(require("os"));
13
+ const _path = /*#__PURE__*/ _interop_require_wildcard(require("path"));
14
+ const _child_process = require("child_process");
15
+ const _base = require("../base");
16
+ const _theme = require("../theme");
17
+ const _symbols = require("../symbols");
18
+ const _ansi = require("../ansi");
19
+ function _define_property(obj, key, value) {
20
+ if (key in obj) {
21
+ Object.defineProperty(obj, key, {
22
+ value: value,
23
+ enumerable: true,
24
+ configurable: true,
25
+ writable: true
26
+ });
27
+ } else {
28
+ obj[key] = value;
29
+ }
30
+ return obj;
31
+ }
32
+ function _getRequireWildcardCache(nodeInterop) {
33
+ if (typeof WeakMap !== "function") return null;
34
+ var cacheBabelInterop = new WeakMap();
35
+ var cacheNodeInterop = new WeakMap();
36
+ return (_getRequireWildcardCache = function(nodeInterop) {
37
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
38
+ })(nodeInterop);
39
+ }
40
+ function _interop_require_wildcard(obj, nodeInterop) {
41
+ if (!nodeInterop && obj && obj.__esModule) {
42
+ return obj;
43
+ }
44
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
45
+ return {
46
+ default: obj
47
+ };
48
+ }
49
+ var cache = _getRequireWildcardCache(nodeInterop);
50
+ if (cache && cache.has(obj)) {
51
+ return cache.get(obj);
52
+ }
53
+ var newObj = {
54
+ __proto__: null
55
+ };
56
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
57
+ for(var key in obj){
58
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
59
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
60
+ if (desc && (desc.get || desc.set)) {
61
+ Object.defineProperty(newObj, key, desc);
62
+ } else {
63
+ newObj[key] = obj[key];
64
+ }
65
+ }
66
+ }
67
+ newObj.default = obj;
68
+ if (cache) {
69
+ cache.set(obj, newObj);
70
+ }
71
+ return newObj;
72
+ }
73
+ let EditorPrompt = class EditorPrompt extends _base.Prompt {
74
+ cleanup() {
75
+ if (this.tempFilePath) {
76
+ try {
77
+ if (_fs.existsSync(this.tempFilePath)) {
78
+ _fs.unlinkSync(this.tempFilePath);
79
+ }
80
+ } catch (_error) {
81
+ // Ignore cleanup errors
82
+ }
83
+ }
84
+ super.cleanup();
85
+ }
86
+ render(firstRender) {
87
+ if (this.status === 'editing') {
88
+ return; // Don't render while editor is open (stdio inherited)
89
+ }
90
+ const icon = this.status === 'done' ? _theme.theme.success + _symbols.symbols.tick : _theme.theme.main + '?';
91
+ const message = `${_theme.theme.title}${this.options.message}${_ansi.ANSI.RESET}`;
92
+ const hint = this.options.waitUserInput ? ` ${_theme.theme.muted}[Press <Enter> to launch editor]${_ansi.ANSI.RESET}` : ` ${_theme.theme.muted}[Launching editor...]${_ansi.ANSI.RESET}`;
93
+ let output = `${icon} ${_ansi.ANSI.BOLD}${message}${_ansi.ANSI.RESET}${hint}`;
94
+ if (this.errorMsg) {
95
+ output += `\n${_theme.theme.error}>> ${this.errorMsg}${_ansi.ANSI.RESET}`;
96
+ }
97
+ this.renderFrame(output);
98
+ // Auto-launch handling
99
+ if (firstRender && this.options.waitUserInput === false) {
100
+ // We need to delay slightly to ensure the render frame is flushed
101
+ // and raw mode setup is complete from .run()
102
+ setTimeout(()=>{
103
+ this.spawnEditor();
104
+ }, 50);
105
+ }
106
+ }
107
+ handleInput(char) {
108
+ if (this.status !== 'pending') return;
109
+ // Enter
110
+ if (char === '\r' || char === '\n') {
111
+ this.spawnEditor();
112
+ }
113
+ }
114
+ resolveEditor() {
115
+ // 1. Env vars
116
+ const envEditor = process.env.VISUAL || process.env.EDITOR;
117
+ if (envEditor) {
118
+ const parts = envEditor.split(' ');
119
+ return {
120
+ cmd: parts[0],
121
+ args: parts.slice(1)
122
+ };
123
+ }
124
+ // 2. OS specific
125
+ if (process.platform === 'win32') {
126
+ // Priority: notepad -> code -> wordpad
127
+ return {
128
+ cmd: 'notepad',
129
+ args: []
130
+ };
131
+ } else {
132
+ // Unix/Linux/Mac
133
+ // Priority: vim -> nano -> vi
134
+ // We'll stick to 'vim' as the default safe bet if we can't detect.
135
+ // A more robust solution would check paths, but for now we assume 'vim'.
136
+ return {
137
+ cmd: 'vim',
138
+ args: []
139
+ };
140
+ }
141
+ }
142
+ spawnEditor() {
143
+ this.status = 'editing';
144
+ // 1. Prepare Temp File
145
+ const ext = this.options.extension || '.txt';
146
+ // Ensure extension has dot
147
+ const safeExt = ext.startsWith('.') ? ext : '.' + ext;
148
+ const filename = `mep-editor-${Date.now()}-${Math.floor(Math.random() * 1000)}${safeExt}`;
149
+ this.tempFilePath = _path.join(_os.tmpdir(), filename);
150
+ const initialContent = this.options.initial || '';
151
+ try {
152
+ _fs.writeFileSync(this.tempFilePath, initialContent, 'utf8');
153
+ } catch (e) {
154
+ this.errorMsg = `Failed to create temp file: ${e.message}`;
155
+ this.status = 'pending';
156
+ this.render(false);
157
+ return;
158
+ }
159
+ // 2. Resolve Editor
160
+ const { cmd, args } = this.resolveEditor();
161
+ const editorArgs = [
162
+ ...args,
163
+ this.tempFilePath
164
+ ];
165
+ // 3. Pause Mep
166
+ // Temporarily disable mouse tracking if it was enabled
167
+ const shouldEnableMouse = this.options.mouse !== false && this.capabilities.hasMouse;
168
+ if (shouldEnableMouse) {
169
+ this.print(_ansi.ANSI.DISABLE_MOUSE);
170
+ }
171
+ // Pause stdin and raw mode to allow child process to take over TTY
172
+ this.stdin.setRawMode(false);
173
+ this.stdin.pause();
174
+ // 4. Spawn
175
+ const child = (0, _child_process.spawn)(cmd, editorArgs, {
176
+ stdio: 'inherit',
177
+ shell: true
178
+ });
179
+ child.on('error', (err)=>{
180
+ this.restoreMep();
181
+ this.status = 'pending';
182
+ this.errorMsg = `Could not launch editor '${cmd}': ${err.message}`;
183
+ this.render(false);
184
+ });
185
+ child.on('exit', (code)=>{
186
+ // 5. Read Result
187
+ let content = initialContent;
188
+ try {
189
+ if (this.tempFilePath && _fs.existsSync(this.tempFilePath)) {
190
+ content = _fs.readFileSync(this.tempFilePath, 'utf8');
191
+ _fs.unlinkSync(this.tempFilePath); // Cleanup
192
+ this.tempFilePath = null; // Mark as cleaned
193
+ }
194
+ } catch (_e) {
195
+ // Ignore read/delete errors
196
+ }
197
+ this.restoreMep();
198
+ if (code !== 0) {
199
+ this.status = 'pending';
200
+ this.errorMsg = `Editor exited with code ${code}`;
201
+ this.render(false);
202
+ return;
203
+ }
204
+ // Success
205
+ this.status = 'done';
206
+ if (content.endsWith('\n')) {
207
+ content = content.slice(0, -1);
208
+ }
209
+ if (content.endsWith('\r')) {
210
+ content = content.slice(0, -1);
211
+ }
212
+ this.submit(content);
213
+ });
214
+ }
215
+ restoreMep() {
216
+ this.stdin.resume();
217
+ this.stdin.setRawMode(true);
218
+ // Re-enable mouse if it was enabled
219
+ const shouldEnableMouse = this.options.mouse !== false && this.capabilities.hasMouse;
220
+ if (shouldEnableMouse) {
221
+ this.print(_ansi.ANSI.SET_ANY_EVENT_MOUSE + _ansi.ANSI.SET_SGR_EXT_MODE_MOUSE);
222
+ }
223
+ this.print(_ansi.ANSI.HIDE_CURSOR); // Ensure cursor is hidden again for Mep
224
+ }
225
+ constructor(options){
226
+ super(options), _define_property(this, "errorMsg", ''), _define_property(this, "status", 'pending'), _define_property(this, "tempFilePath", null);
227
+ // Default waitUserInput to true if not specified
228
+ if (this.options.waitUserInput === undefined) {
229
+ this.options.waitUserInput = true;
230
+ }
231
+ }
232
+ };
233
+
234
+ //# sourceMappingURL=editor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/prompts/editor.ts"],"sourcesContent":["import * as fs from 'fs';\nimport * as os from 'os';\nimport * as path from 'path';\nimport { spawn } from 'child_process';\nimport { Prompt } from '../base';\nimport { EditorOptions } from '../types';\nimport { theme } from '../theme';\nimport { symbols } from '../symbols';\nimport { ANSI } from '../ansi';\n\nexport class EditorPrompt extends Prompt<string, EditorOptions> {\n private errorMsg: string = '';\n private status: 'pending' | 'editing' | 'done' = 'pending';\n private tempFilePath: string | null = null;\n\n constructor(options: EditorOptions) {\n super(options);\n // Default waitUserInput to true if not specified\n if (this.options.waitUserInput === undefined) {\n this.options.waitUserInput = true;\n }\n }\n\n protected cleanup() {\n if (this.tempFilePath) {\n try {\n if (fs.existsSync(this.tempFilePath)) {\n fs.unlinkSync(this.tempFilePath);\n }\n } catch (_error) {\n // Ignore cleanup errors\n }\n }\n super.cleanup();\n }\n\n protected render(firstRender: boolean) {\n if (this.status === 'editing') {\n return; // Don't render while editor is open (stdio inherited)\n }\n\n const icon = this.status === 'done' ? theme.success + symbols.tick : theme.main + '?';\n const message = `${theme.title}${this.options.message}${ANSI.RESET}`;\n const hint = this.options.waitUserInput\n ? ` ${theme.muted}[Press <Enter> to launch editor]${ANSI.RESET}`\n : ` ${theme.muted}[Launching editor...]${ANSI.RESET}`;\n\n let output = `${icon} ${ANSI.BOLD}${message}${ANSI.RESET}${hint}`;\n\n if (this.errorMsg) {\n output += `\\n${theme.error}>> ${this.errorMsg}${ANSI.RESET}`;\n }\n\n this.renderFrame(output);\n\n // Auto-launch handling\n if (firstRender && this.options.waitUserInput === false) {\n // We need to delay slightly to ensure the render frame is flushed\n // and raw mode setup is complete from .run()\n setTimeout(() => {\n this.spawnEditor();\n }, 50);\n }\n }\n\n protected handleInput(char: string) {\n if (this.status !== 'pending') return;\n\n // Enter\n if (char === '\\r' || char === '\\n') {\n this.spawnEditor();\n }\n }\n\n private resolveEditor(): { cmd: string, args: string[] } {\n // 1. Env vars\n const envEditor = process.env.VISUAL || process.env.EDITOR;\n if (envEditor) {\n const parts = envEditor.split(' ');\n return { cmd: parts[0], args: parts.slice(1) };\n }\n\n // 2. OS specific\n if (process.platform === 'win32') {\n // Priority: notepad -> code -> wordpad\n return { cmd: 'notepad', args: [] };\n } else {\n // Unix/Linux/Mac\n // Priority: vim -> nano -> vi\n // We'll stick to 'vim' as the default safe bet if we can't detect.\n // A more robust solution would check paths, but for now we assume 'vim'.\n return { cmd: 'vim', args: [] };\n }\n }\n\n private spawnEditor() {\n this.status = 'editing';\n\n // 1. Prepare Temp File\n const ext = this.options.extension || '.txt';\n // Ensure extension has dot\n const safeExt = ext.startsWith('.') ? ext : '.' + ext;\n const filename = `mep-editor-${Date.now()}-${Math.floor(Math.random() * 1000)}${safeExt}`;\n this.tempFilePath = path.join(os.tmpdir(), filename);\n const initialContent = this.options.initial || '';\n\n try {\n fs.writeFileSync(this.tempFilePath, initialContent, 'utf8');\n } catch (e) {\n this.errorMsg = `Failed to create temp file: ${(e as Error).message}`;\n this.status = 'pending';\n this.render(false);\n return;\n }\n\n // 2. Resolve Editor\n const { cmd, args } = this.resolveEditor();\n const editorArgs = [...args, this.tempFilePath];\n\n // 3. Pause Mep\n // Temporarily disable mouse tracking if it was enabled\n const shouldEnableMouse = (this.options as any).mouse !== false && this.capabilities.hasMouse;\n if (shouldEnableMouse) {\n this.print(ANSI.DISABLE_MOUSE);\n }\n\n // Pause stdin and raw mode to allow child process to take over TTY\n this.stdin.setRawMode(false);\n this.stdin.pause();\n\n // 4. Spawn\n const child = spawn(cmd, editorArgs, {\n stdio: 'inherit',\n shell: true\n });\n\n child.on('error', (err) => {\n this.restoreMep();\n this.status = 'pending';\n this.errorMsg = `Could not launch editor '${cmd}': ${err.message}`;\n this.render(false);\n });\n\n child.on('exit', (code) => {\n // 5. Read Result\n let content = initialContent;\n try {\n if (this.tempFilePath && fs.existsSync(this.tempFilePath)) {\n content = fs.readFileSync(this.tempFilePath, 'utf8');\n fs.unlinkSync(this.tempFilePath); // Cleanup\n this.tempFilePath = null; // Mark as cleaned\n }\n } catch (_e) {\n // Ignore read/delete errors\n }\n\n this.restoreMep();\n\n if (code !== 0) {\n this.status = 'pending';\n this.errorMsg = `Editor exited with code ${code}`;\n this.render(false);\n return;\n }\n\n // Success\n this.status = 'done';\n\n if (content.endsWith('\\n')) {\n content = content.slice(0, -1);\n }\n if (content.endsWith('\\r')) {\n content = content.slice(0, -1);\n }\n\n this.submit(content);\n });\n }\n\n private restoreMep() {\n this.stdin.resume();\n this.stdin.setRawMode(true);\n\n // Re-enable mouse if it was enabled\n const shouldEnableMouse = (this.options as any).mouse !== false && this.capabilities.hasMouse;\n if (shouldEnableMouse) {\n this.print(ANSI.SET_ANY_EVENT_MOUSE + ANSI.SET_SGR_EXT_MODE_MOUSE);\n }\n this.print(ANSI.HIDE_CURSOR); // Ensure cursor is hidden again for Mep\n }\n}\n"],"names":["EditorPrompt","Prompt","cleanup","tempFilePath","fs","existsSync","unlinkSync","_error","render","firstRender","status","icon","theme","success","symbols","tick","main","message","title","options","ANSI","RESET","hint","waitUserInput","muted","output","BOLD","errorMsg","error","renderFrame","setTimeout","spawnEditor","handleInput","char","resolveEditor","envEditor","process","env","VISUAL","EDITOR","parts","split","cmd","args","slice","platform","ext","extension","safeExt","startsWith","filename","Date","now","Math","floor","random","path","join","os","tmpdir","initialContent","initial","writeFileSync","e","editorArgs","shouldEnableMouse","mouse","capabilities","hasMouse","print","DISABLE_MOUSE","stdin","setRawMode","pause","child","spawn","stdio","shell","on","err","restoreMep","code","content","readFileSync","_e","endsWith","submit","resume","SET_ANY_EVENT_MOUSE","SET_SGR_EXT_MODE_MOUSE","HIDE_CURSOR","undefined"],"mappings":";;;;+BAUaA;;;eAAAA;;;4DAVO;4DACA;8DACE;+BACA;sBACC;uBAED;yBACE;sBACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;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