mepcli 2.0.0-beta.1 → 2.0.0-beta.3
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.
- package/README.md +32 -10
- package/dist/ansi.d.ts +36 -0
- package/dist/ansi.js +1 -0
- package/dist/base.d.ts +60 -0
- package/dist/base.js +1 -0
- package/dist/{src/core.js → core.d.ts} +175 -347
- package/dist/core.js +1 -0
- package/dist/data/countries.d.ts +2 -0
- package/dist/data/countries.js +1 -0
- package/dist/data/licenses.d.ts +2 -0
- package/dist/data/licenses.js +1 -0
- package/dist/highlight.d.ts +7 -0
- package/dist/highlight.js +1 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.js +1 -0
- package/dist/input.d.ts +14 -0
- package/dist/input.js +1 -0
- package/dist/pipeline.d.ts +90 -0
- package/dist/pipeline.js +1 -0
- package/dist/prompts/autocomplete.d.ts +22 -0
- package/dist/prompts/autocomplete.js +1 -0
- package/dist/prompts/box.d.ts +21 -0
- package/dist/prompts/box.js +4 -0
- package/dist/prompts/breadcrumb-search.d.ts +14 -0
- package/dist/prompts/breadcrumb-search.js +2 -0
- package/dist/prompts/breadcrumb.d.ts +32 -0
- package/dist/prompts/breadcrumb.js +3 -0
- package/dist/prompts/byte.d.ts +13 -0
- package/dist/prompts/byte.js +5 -0
- package/dist/prompts/calculator.d.ts +17 -0
- package/dist/prompts/calculator.js +3 -0
- package/dist/prompts/calendar.d.ts +33 -0
- package/dist/prompts/calendar.js +3 -0
- package/dist/prompts/checkbox.d.ts +13 -0
- package/dist/prompts/checkbox.js +2 -0
- package/dist/prompts/code.d.ts +19 -0
- package/dist/prompts/code.js +4 -0
- package/dist/prompts/color.d.ts +14 -0
- package/dist/prompts/color.js +10 -0
- package/dist/prompts/confirm.d.ts +8 -0
- package/dist/prompts/confirm.js +1 -0
- package/dist/prompts/connection-string.d.ts +18 -0
- package/dist/prompts/connection-string.js +1 -0
- package/dist/prompts/cron.d.ts +13 -0
- package/dist/prompts/cron.js +4 -0
- package/dist/prompts/curl-utils.d.ts +25 -0
- package/dist/prompts/curl-utils.js +1 -0
- package/dist/prompts/curl.d.ts +41 -0
- package/dist/prompts/curl.js +12 -0
- package/dist/prompts/data-inspector.d.ts +22 -0
- package/dist/prompts/data-inspector.js +5 -0
- package/dist/prompts/date.d.ts +12 -0
- package/dist/prompts/date.js +2 -0
- package/dist/prompts/dependency.d.ts +16 -0
- package/dist/prompts/dependency.js +3 -0
- package/dist/prompts/dial.d.ts +10 -0
- package/dist/prompts/dial.js +3 -0
- package/dist/prompts/diff.d.ts +10 -0
- package/dist/prompts/diff.js +10 -0
- package/dist/prompts/draw.d.ts +20 -0
- package/dist/prompts/draw.js +6 -0
- package/dist/prompts/editor.d.ts +14 -0
- package/dist/prompts/editor.js +2 -0
- package/dist/prompts/emoji.d.ts +18 -0
- package/dist/prompts/emoji.js +5 -0
- package/dist/prompts/exec.d.ts +17 -0
- package/dist/prompts/exec.js +1 -0
- package/dist/prompts/file.d.ts +21 -0
- package/dist/prompts/file.js +2 -0
- package/dist/prompts/form.d.ts +18 -0
- package/dist/prompts/form.js +1 -0
- package/dist/prompts/fuzzy-multi-column.d.ts +12 -0
- package/dist/prompts/fuzzy-multi-column.js +2 -0
- package/dist/prompts/fuzzy.d.ts +12 -0
- package/dist/prompts/fuzzy.js +2 -0
- package/dist/prompts/gauge.d.ts +21 -0
- package/dist/prompts/gauge.js +4 -0
- package/dist/prompts/grid.d.ts +14 -0
- package/dist/prompts/grid.js +2 -0
- package/dist/prompts/heatmap.d.ts +13 -0
- package/dist/prompts/heatmap.js +2 -0
- package/dist/prompts/ip.d.ts +11 -0
- package/dist/prompts/ip.js +3 -0
- package/dist/prompts/kanban.d.ts +17 -0
- package/dist/prompts/kanban.js +4 -0
- package/dist/prompts/keypress.d.ts +7 -0
- package/dist/prompts/keypress.js +1 -0
- package/dist/prompts/license.d.ts +9 -0
- package/dist/prompts/license.js +13 -0
- package/dist/prompts/list.d.ts +9 -0
- package/dist/prompts/list.js +1 -0
- package/dist/prompts/map.d.ts +17 -0
- package/dist/prompts/map.js +5 -0
- package/dist/prompts/match.d.ts +19 -0
- package/dist/prompts/match.js +7 -0
- package/dist/prompts/miller.d.ts +15 -0
- package/dist/prompts/miller.js +2 -0
- package/dist/prompts/multi-column-select.d.ts +10 -0
- package/dist/prompts/multi-column-select.js +2 -0
- package/dist/prompts/multi-range.d.ts +9 -0
- package/dist/prompts/multi-range.js +3 -0
- package/dist/prompts/multi-select.d.ts +15 -0
- package/dist/prompts/multi-select.js +4 -0
- package/dist/prompts/number.d.ts +11 -0
- package/dist/prompts/number.js +2 -0
- package/dist/prompts/otp.d.ts +10 -0
- package/dist/prompts/otp.js +2 -0
- package/dist/prompts/pattern.d.ts +22 -0
- package/dist/prompts/pattern.js +4 -0
- package/dist/prompts/phone.d.ts +41 -0
- package/dist/prompts/phone.js +3 -0
- package/dist/prompts/quiz-select.d.ts +10 -0
- package/dist/prompts/quiz-select.js +7 -0
- package/dist/prompts/quiz-text.d.ts +11 -0
- package/dist/prompts/quiz-text.js +8 -0
- package/dist/prompts/range.d.ts +9 -0
- package/dist/prompts/range.js +1 -0
- package/dist/prompts/rating.d.ts +8 -0
- package/dist/prompts/rating.js +1 -0
- package/dist/prompts/regex.d.ts +13 -0
- package/dist/prompts/regex.js +5 -0
- package/dist/prompts/region.d.ts +11 -0
- package/dist/prompts/region.js +5 -0
- package/dist/prompts/schedule.d.ts +20 -0
- package/dist/prompts/schedule.js +5 -0
- package/dist/prompts/scroll.d.ts +13 -0
- package/dist/prompts/scroll.js +1 -0
- package/dist/prompts/seat.d.ts +17 -0
- package/dist/prompts/seat.js +5 -0
- package/dist/prompts/select-range.d.ts +8 -0
- package/dist/prompts/select-range.js +3 -0
- package/dist/prompts/select.d.ts +15 -0
- package/dist/prompts/select.js +2 -0
- package/dist/prompts/semver.d.ts +6 -0
- package/dist/prompts/semver.js +1 -0
- package/dist/prompts/shortcut.d.ts +9 -0
- package/dist/prompts/shortcut.js +1 -0
- package/dist/prompts/slider.d.ts +8 -0
- package/dist/prompts/slider.js +1 -0
- package/dist/prompts/slot.d.ts +16 -0
- package/dist/prompts/slot.js +8 -0
- package/dist/prompts/snippet.d.ts +19 -0
- package/dist/prompts/snippet.js +4 -0
- package/dist/prompts/sort-grid.d.ts +16 -0
- package/dist/prompts/sort-grid.js +2 -0
- package/dist/prompts/sort.d.ts +14 -0
- package/dist/prompts/sort.js +2 -0
- package/dist/prompts/spam.d.ts +17 -0
- package/dist/prompts/spam.js +2 -0
- package/dist/prompts/spreadsheet.d.ts +21 -0
- package/dist/prompts/spreadsheet.js +7 -0
- package/dist/prompts/table.d.ts +14 -0
- package/dist/prompts/table.js +3 -0
- package/dist/prompts/text.d.ts +17 -0
- package/dist/prompts/text.js +2 -0
- package/dist/prompts/time.d.ts +12 -0
- package/dist/prompts/time.js +2 -0
- package/dist/prompts/toggle.d.ts +8 -0
- package/dist/prompts/toggle.js +1 -0
- package/dist/prompts/transfer.d.ts +18 -0
- package/dist/prompts/transfer.js +5 -0
- package/dist/prompts/tree-select.d.ts +31 -0
- package/dist/prompts/tree-select.js +3 -0
- package/dist/prompts/tree.d.ts +20 -0
- package/dist/prompts/tree.js +3 -0
- package/dist/prompts/wait.d.ts +18 -0
- package/dist/prompts/wait.js +1 -0
- package/dist/spinner.d.ts +33 -0
- package/dist/spinner.js +3 -0
- package/dist/symbols.d.ts +33 -0
- package/dist/symbols.js +1 -0
- package/dist/tasks.d.ts +57 -0
- package/dist/tasks.js +1 -0
- package/dist/theme.d.ts +2 -0
- package/dist/theme.js +1 -0
- package/dist/types.d.ts +503 -0
- package/dist/types.js +1 -0
- package/dist/utils.d.ts +81 -0
- package/dist/utils.js +1 -0
- package/package.json +12 -17
- package/dist/src/ansi.js +0 -50
- package/dist/src/ansi.js.map +0 -1
- package/dist/src/base.js +0 -258
- package/dist/src/base.js.map +0 -1
- package/dist/src/core.js.map +0 -1
- package/dist/src/data/countries.js +0 -569
- package/dist/src/data/countries.js.map +0 -1
- package/dist/src/data/licenses.js +0 -480
- package/dist/src/data/licenses.js.map +0 -1
- package/dist/src/highlight.js +0 -185
- package/dist/src/highlight.js.map +0 -1
- package/dist/src/index.js +0 -66
- package/dist/src/index.js.map +0 -1
- package/dist/src/input.js +0 -158
- package/dist/src/input.js.map +0 -1
- package/dist/src/pipeline.js +0 -273
- package/dist/src/pipeline.js.map +0 -1
- package/dist/src/prompts/autocomplete.js +0 -171
- package/dist/src/prompts/autocomplete.js.map +0 -1
- package/dist/src/prompts/box.js +0 -225
- package/dist/src/prompts/box.js.map +0 -1
- package/dist/src/prompts/breadcrumb-search.js +0 -260
- package/dist/src/prompts/breadcrumb-search.js.map +0 -1
- package/dist/src/prompts/breadcrumb.js +0 -307
- package/dist/src/prompts/breadcrumb.js.map +0 -1
- package/dist/src/prompts/byte.js +0 -176
- package/dist/src/prompts/byte.js.map +0 -1
- package/dist/src/prompts/calculator.js +0 -243
- package/dist/src/prompts/calculator.js.map +0 -1
- package/dist/src/prompts/calendar.js +0 -430
- package/dist/src/prompts/calendar.js.map +0 -1
- package/dist/src/prompts/checkbox.js +0 -159
- package/dist/src/prompts/checkbox.js.map +0 -1
- package/dist/src/prompts/code.js +0 -271
- package/dist/src/prompts/code.js.map +0 -1
- package/dist/src/prompts/color.js +0 -165
- package/dist/src/prompts/color.js.map +0 -1
- package/dist/src/prompts/confirm.js +0 -55
- package/dist/src/prompts/confirm.js.map +0 -1
- package/dist/src/prompts/connection-string.js +0 -120
- package/dist/src/prompts/connection-string.js.map +0 -1
- package/dist/src/prompts/cron.js +0 -207
- package/dist/src/prompts/cron.js.map +0 -1
- package/dist/src/prompts/curl-utils.js +0 -71
- package/dist/src/prompts/curl-utils.js.map +0 -1
- package/dist/src/prompts/curl.js +0 -431
- package/dist/src/prompts/curl.js.map +0 -1
- package/dist/src/prompts/data-inspector.js +0 -261
- package/dist/src/prompts/data-inspector.js.map +0 -1
- package/dist/src/prompts/date.js +0 -185
- package/dist/src/prompts/date.js.map +0 -1
- package/dist/src/prompts/dependency.js +0 -283
- package/dist/src/prompts/dependency.js.map +0 -1
- package/dist/src/prompts/dial.js +0 -124
- package/dist/src/prompts/dial.js.map +0 -1
- package/dist/src/prompts/diff.js +0 -118
- package/dist/src/prompts/diff.js.map +0 -1
- package/dist/src/prompts/draw.js +0 -191
- package/dist/src/prompts/draw.js.map +0 -1
- package/dist/src/prompts/editor.js +0 -234
- package/dist/src/prompts/editor.js.map +0 -1
- package/dist/src/prompts/emoji.js +0 -226
- package/dist/src/prompts/emoji.js.map +0 -1
- package/dist/src/prompts/exec.js +0 -151
- package/dist/src/prompts/exec.js.map +0 -1
- package/dist/src/prompts/file.js +0 -217
- package/dist/src/prompts/file.js.map +0 -1
- package/dist/src/prompts/form.js +0 -241
- package/dist/src/prompts/form.js.map +0 -1
- package/dist/src/prompts/fuzzy-multi-column.js +0 -161
- package/dist/src/prompts/fuzzy-multi-column.js.map +0 -1
- package/dist/src/prompts/fuzzy.js +0 -147
- package/dist/src/prompts/fuzzy.js.map +0 -1
- package/dist/src/prompts/gauge.js +0 -137
- package/dist/src/prompts/gauge.js.map +0 -1
- package/dist/src/prompts/grid.js +0 -191
- package/dist/src/prompts/grid.js.map +0 -1
- package/dist/src/prompts/heatmap.js +0 -147
- package/dist/src/prompts/heatmap.js.map +0 -1
- package/dist/src/prompts/ip.js +0 -138
- package/dist/src/prompts/ip.js.map +0 -1
- package/dist/src/prompts/kanban.js +0 -233
- package/dist/src/prompts/kanban.js.map +0 -1
- package/dist/src/prompts/keypress.js +0 -54
- package/dist/src/prompts/keypress.js.map +0 -1
- package/dist/src/prompts/license.js +0 -144
- package/dist/src/prompts/license.js.map +0 -1
- package/dist/src/prompts/list.js +0 -124
- package/dist/src/prompts/list.js.map +0 -1
- package/dist/src/prompts/map.js +0 -262
- package/dist/src/prompts/map.js.map +0 -1
- package/dist/src/prompts/match.js +0 -271
- package/dist/src/prompts/match.js.map +0 -1
- package/dist/src/prompts/miller.js +0 -228
- package/dist/src/prompts/miller.js.map +0 -1
- package/dist/src/prompts/multi-column-select.js +0 -176
- package/dist/src/prompts/multi-column-select.js.map +0 -1
- package/dist/src/prompts/multi-range.js +0 -189
- package/dist/src/prompts/multi-range.js.map +0 -1
- package/dist/src/prompts/multi-select.js +0 -183
- package/dist/src/prompts/multi-select.js.map +0 -1
- package/dist/src/prompts/number.js +0 -166
- package/dist/src/prompts/number.js.map +0 -1
- package/dist/src/prompts/otp.js +0 -107
- package/dist/src/prompts/otp.js.map +0 -1
- package/dist/src/prompts/pattern.js +0 -252
- package/dist/src/prompts/pattern.js.map +0 -1
- package/dist/src/prompts/phone.js +0 -398
- package/dist/src/prompts/phone.js.map +0 -1
- package/dist/src/prompts/quiz-select.js +0 -114
- package/dist/src/prompts/quiz-select.js.map +0 -1
- package/dist/src/prompts/quiz-text.js +0 -98
- package/dist/src/prompts/quiz-text.js.map +0 -1
- package/dist/src/prompts/range.js +0 -164
- package/dist/src/prompts/range.js.map +0 -1
- package/dist/src/prompts/rating.js +0 -83
- package/dist/src/prompts/rating.js.map +0 -1
- package/dist/src/prompts/regex.js +0 -145
- package/dist/src/prompts/regex.js.map +0 -1
- package/dist/src/prompts/region.js +0 -170
- package/dist/src/prompts/region.js.map +0 -1
- package/dist/src/prompts/schedule.js +0 -270
- package/dist/src/prompts/schedule.js.map +0 -1
- package/dist/src/prompts/scroll.js +0 -155
- package/dist/src/prompts/scroll.js.map +0 -1
- package/dist/src/prompts/seat.js +0 -164
- package/dist/src/prompts/seat.js.map +0 -1
- package/dist/src/prompts/select-range.js +0 -148
- package/dist/src/prompts/select-range.js.map +0 -1
- package/dist/src/prompts/select.js +0 -163
- package/dist/src/prompts/select.js.map +0 -1
- package/dist/src/prompts/semver.js +0 -43
- package/dist/src/prompts/semver.js.map +0 -1
- package/dist/src/prompts/shortcut.js +0 -133
- package/dist/src/prompts/shortcut.js.map +0 -1
- package/dist/src/prompts/slider.js +0 -69
- package/dist/src/prompts/slider.js.map +0 -1
- package/dist/src/prompts/slot.js +0 -117
- package/dist/src/prompts/slot.js.map +0 -1
- package/dist/src/prompts/snippet.js +0 -228
- package/dist/src/prompts/snippet.js.map +0 -1
- package/dist/src/prompts/sort-grid.js +0 -151
- package/dist/src/prompts/sort-grid.js.map +0 -1
- package/dist/src/prompts/sort.js +0 -166
- package/dist/src/prompts/sort.js.map +0 -1
- package/dist/src/prompts/spam.js +0 -80
- package/dist/src/prompts/spam.js.map +0 -1
- package/dist/src/prompts/spreadsheet.js +0 -240
- package/dist/src/prompts/spreadsheet.js.map +0 -1
- package/dist/src/prompts/table.js +0 -120
- package/dist/src/prompts/table.js.map +0 -1
- package/dist/src/prompts/text.js +0 -317
- package/dist/src/prompts/text.js.map +0 -1
- package/dist/src/prompts/time.js +0 -211
- package/dist/src/prompts/time.js.map +0 -1
- package/dist/src/prompts/toggle.js +0 -53
- package/dist/src/prompts/toggle.js.map +0 -1
- package/dist/src/prompts/transfer.js +0 -207
- package/dist/src/prompts/transfer.js.map +0 -1
- package/dist/src/prompts/tree-select.js +0 -270
- package/dist/src/prompts/tree-select.js.map +0 -1
- package/dist/src/prompts/tree.js +0 -233
- package/dist/src/prompts/tree.js.map +0 -1
- package/dist/src/prompts/wait.js +0 -79
- package/dist/src/prompts/wait.js.map +0 -1
- package/dist/src/spinner.js +0 -105
- package/dist/src/spinner.js.map +0 -1
- package/dist/src/symbols.js +0 -66
- package/dist/src/symbols.js.map +0 -1
- package/dist/src/tasks.js +0 -231
- package/dist/src/tasks.js.map +0 -1
- package/dist/src/theme.js +0 -29
- package/dist/src/theme.js.map +0 -1
- package/dist/src/types.js +0 -8
- package/dist/src/types.js.map +0 -1
- package/dist/src/utils.js +0 -480
- package/dist/src/utils.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"FormPrompt",{enumerable:true,get:function(){return FormPrompt}});const _ansi=require("../ansi");const _base=require("../base");const _theme=require("../theme");const _symbols=require("../symbols");const _utils=require("../utils");function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}let FormPrompt=class FormPrompt extends _base.Prompt{render(firstRender){if(!firstRender&&this.lastLinesUp>0){this.print(`\x1b[${this.lastLinesUp}B`)}this.lastLinesUp=0;const outputLines=[];outputLines.push(`${_theme.theme.success}? ${_ansi.ANSI.BOLD}${_theme.theme.title}${this.options.message}${_ansi.ANSI.RESET}`);if(this.globalError){outputLines.push(`${_theme.theme.error}>> ${this.globalError}${_ansi.ANSI.RESET}`)}let cursorLineIndex=-1;let cursorColIndex=0;this.options.fields.forEach((field,index)=>{const isActive=index===this.activeIndex;const value=this.values[field.name];const error=this.fieldErrors[field.name];let icon="";if(isActive){icon=`${_theme.theme.main}${_symbols.symbols.pointer}`}else{icon=" "}const labelStyle=isActive?`${_theme.theme.main}${_ansi.ANSI.BOLD}`:_theme.theme.muted;const label=`${labelStyle}${field.message}:${_ansi.ANSI.RESET}`;const displayValue=isActive?value:`${_theme.theme.muted}${value}${_ansi.ANSI.RESET}`;const line=`${icon} ${label} ${displayValue}`;outputLines.push(line);if(isActive){const prefix=`${icon} ${label} `;const valuePrefix=value.substring(0,this.cursor);cursorLineIndex=outputLines.length-1;cursorColIndex=(0,_utils.stringWidth)(this.stripAnsi(prefix))+(0,_utils.stringWidth)(this.stripAnsi(valuePrefix))}if(error){outputLines.push(` ${_theme.theme.error}>> ${error}${_ansi.ANSI.RESET}`)}});outputLines.push("");outputLines.push(`${_ansi.ANSI.RESET}${_theme.theme.muted}(Use Up/Down/Tab to navigate, Enter to submit)${_ansi.ANSI.RESET}`);const output=outputLines.join("\n");this.renderFrame(output);this.print(_ansi.ANSI.SHOW_CURSOR);if(cursorLineIndex!==-1){const totalLines=outputLines.length;const linesUp=totalLines-1-cursorLineIndex;if(linesUp>0){this.print(`\x1b[${linesUp}A`);this.lastLinesUp=linesUp}this.print(_ansi.ANSI.CURSOR_LEFT);if(cursorColIndex>0){this.print(`\x1b[${cursorColIndex}C`)}}}handleInput(char,key){if(this.isUp(char)||char===" "&&key||char==="\x1b[Z"){this.validateCurrentField();this.moveFocus(-1);return}if(this.isDown(char)||char===" "){this.validateCurrentField();this.moveFocus(1);return}if(char==="\r"||char==="\n"){this.validateCurrentField().then(isValid=>{if(isValid){if(this.activeIndex<this.options.fields.length-1){this.moveFocus(1)}else{this.submitForm()}}});return}const activeField=this.options.fields[this.activeIndex];const val=this.values[activeField.name];if(char==="\b"||char===""){if(this.cursor>0){const pre=val.slice(0,this.cursor-1);const post=val.slice(this.cursor);this.values[activeField.name]=pre+post;this.cursor--;this.render(false)}return}if(this.isLeft(char)){if(this.cursor>0)this.cursor--;this.render(false);return}if(this.isRight(char)){if(this.cursor<val.length)this.cursor++;this.render(false);return}if(!/^[\x00-\x1F]/.test(char)&&!char.startsWith("\x1b")){const pre=val.slice(0,this.cursor);const post=val.slice(this.cursor);this.values[activeField.name]=pre+char+post;this.cursor+=char.length;this.fieldErrors[activeField.name]="";this.render(false)}}handleMouse(event){if(event.action==="scroll"){if(event.scroll==="up"){this.validateCurrentField();this.moveFocus(-1)}else if(event.scroll==="down"){this.validateCurrentField();this.moveFocus(1)}}}moveFocus(direction){const nextIndex=this.activeIndex+direction;if(nextIndex>=0&&nextIndex<this.options.fields.length){this.activeIndex=nextIndex;this.cursor=this.values[this.options.fields[this.activeIndex].name].length;this.render(false)}}async validateCurrentField(){const field=this.options.fields[this.activeIndex];const val=this.values[field.name];if(field.validate){try{const res=await field.validate(val);if(res!==true){this.fieldErrors[field.name]=typeof res==="string"?res:"Invalid value";this.render(false);return false}}catch(err){this.fieldErrors[field.name]=err.message||"Validation failed";this.render(false);return false}}delete this.fieldErrors[field.name];this.render(false);return true}cleanup(){if(this.lastLinesUp>0){this.print(`\x1b[${this.lastLinesUp}B`);this.lastLinesUp=0}super.cleanup()}async submitForm(){this.globalError="";let allValid=true;for(const field of this.options.fields){const val=this.values[field.name];if(field.validate){const res=await field.validate(val);if(res!==true){this.fieldErrors[field.name]=typeof res==="string"?res:"Invalid value";allValid=false}else{delete this.fieldErrors[field.name]}}}if(allValid){this.submit(this.values)}else{this.globalError="Please fix errors before submitting.";this.render(false)}}constructor(options){super(options),_define_property(this,"values",{}),_define_property(this,"activeIndex",0),_define_property(this,"fieldErrors",{}),_define_property(this,"globalError",""),_define_property(this,"cursor",0),_define_property(this,"lastLinesUp",0);this.options.fields.forEach(field=>{this.values[field.name]=field.initial||""});this.cursor=this.values[this.options.fields[0].name].length}};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { MultiColumnSelectPrompt } from './multi-column-select';
|
|
2
|
+
import { MultiColumnSelectOptions } from '../types';
|
|
3
|
+
export declare class FuzzyMultiColumnPrompt<V> extends MultiColumnSelectPrompt<V> {
|
|
4
|
+
private filteredResults;
|
|
5
|
+
private debounceTimer;
|
|
6
|
+
constructor(options: MultiColumnSelectOptions<V>);
|
|
7
|
+
protected getFilteredChoices(): any[];
|
|
8
|
+
protected handleInput(char: string): void;
|
|
9
|
+
private performSearch;
|
|
10
|
+
private highlight;
|
|
11
|
+
protected render(_firstRender: boolean): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"FuzzyMultiColumnPrompt",{enumerable:true,get:function(){return FuzzyMultiColumnPrompt}});const _multicolumnselect=require("./multi-column-select");const _theme=require("../theme");const _ansi=require("../ansi");const _utils=require("../utils");const _symbols=require("../symbols");function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}let FuzzyMultiColumnPrompt=class FuzzyMultiColumnPrompt extends _multicolumnselect.MultiColumnSelectPrompt{getFilteredChoices(){return this.filteredResults||this.options.choices}handleInput(char){if(char==="\b"||char===""){if(this.searchBuffer.length>0){this.searchBuffer=this.searchBuffer.slice(0,-1);this.performSearch()}return}if(char.length===1&&!/^[\x00-\x1F]/.test(char)&&!char.startsWith("\x1b")){this.searchBuffer+=char;if(this.options.choices.length>1e3){if(this.debounceTimer)clearTimeout(this.debounceTimer);this.debounceTimer=setTimeout(()=>{this.performSearch()},150)}else{this.performSearch()}return}super.handleInput(char)}performSearch(){if(!this.searchBuffer){this.filteredResults=this.options.choices}else{const results=this.options.choices.map(c=>{if(this.isSeparator(c))return null;const match=(0,_utils.fuzzyMatch)(this.searchBuffer,c.title);return{choice:c,match}}).filter(item=>item&&item.match!==null).sort((a,b)=>b.match.score-a.match.score);this.filteredResults=results.map(r=>{r.choice._match=r.match;return r.choice})}this.selectedIndex=0;this.render(false)}highlight(text,indices,isSelected){let output="";const indexSet=new Set(indices);for(let i=0;i<text.length;i++){if(indexSet.has(i)){if(isSelected){output+=`${_ansi.ANSI.BOLD}${_ansi.ANSI.FG_WHITE}${text[i]}${_theme.theme.main}`}else{output+=`${_ansi.ANSI.BOLD}${_ansi.ANSI.FG_CYAN}${text[i]}${_ansi.ANSI.RESET}`}}else{output+=text[i]}}return output}render(_firstRender){let output="";const choices=this.getFilteredChoices();const searchStr=this.searchBuffer?` ${_theme.theme.muted}(Fuzzy: ${this.searchBuffer})${_ansi.ANSI.RESET}`:"";output+=`${_theme.theme.success}?${_ansi.ANSI.RESET} ${_ansi.ANSI.BOLD}${_theme.theme.title}${this.options.message}${_ansi.ANSI.RESET}${searchStr}
|
|
2
|
+
`;if(choices.length===0){output+=` ${_theme.theme.muted}No results found${_ansi.ANSI.RESET}`;this.renderFrame(output);return}const totalRows=Math.ceil(choices.length/this.cols);const currentRow=Math.floor(this.selectedIndex/this.cols);if(currentRow<this.scrollTop){this.scrollTop=currentRow}else if(currentRow>=this.scrollTop+this.pageSize){this.scrollTop=currentRow-this.pageSize+1}if(this.scrollTop>totalRows-1){this.scrollTop=Math.max(0,totalRows-this.pageSize)}const startRow=this.scrollTop;const endRow=Math.min(totalRows,startRow+this.pageSize);for(let r=startRow;r<endRow;r++){let rowStr="";for(let c=0;c<this.cols;c++){const idx=r*this.cols+c;if(idx>=choices.length)break;const choice=choices[idx];let title=choice.title||"";if((0,_utils.stringWidth)(title)>this.colWidth-3){title=title.slice(0,this.colWidth-4)+"…"}const match=choice._match;const isSelected=idx===this.selectedIndex;if(match&&this.searchBuffer){title=this.highlight(title,match.indices,isSelected)}let cellContent="";if(isSelected){cellContent=`${_theme.theme.main}${_symbols.symbols.pointer} ${title}${_ansi.ANSI.RESET}`}else{cellContent=` ${title}`}const currentWidth=(0,_utils.stringWidth)(this.stripAnsi(cellContent));const padding=Math.max(0,this.colWidth-currentWidth);rowStr+=cellContent+" ".repeat(padding)}output+=rowStr+"\n"}if(output.endsWith("\n"))output=output.slice(0,-1);this.renderFrame(output)}constructor(options){super(options),_define_property(this,"filteredResults",[]),_define_property(this,"debounceTimer",void 0);this.filteredResults=this.options.choices}};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { SelectPrompt } from './select';
|
|
2
|
+
import { FuzzySelectOptions } from '../types';
|
|
3
|
+
export declare class FuzzySelectPrompt<V> extends SelectPrompt<V, FuzzySelectOptions<V>> {
|
|
4
|
+
private filteredResults;
|
|
5
|
+
private debounceTimer;
|
|
6
|
+
constructor(options: FuzzySelectOptions<V>);
|
|
7
|
+
protected getFilteredChoices(): any[];
|
|
8
|
+
protected handleInput(char: string): void;
|
|
9
|
+
private performSearch;
|
|
10
|
+
private highlight;
|
|
11
|
+
protected render(_firstRender: boolean): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"FuzzySelectPrompt",{enumerable:true,get:function(){return FuzzySelectPrompt}});const _select=require("./select");const _theme=require("../theme");const _ansi=require("../ansi");const _utils=require("../utils");const _symbols=require("../symbols");function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}let FuzzySelectPrompt=class FuzzySelectPrompt extends _select.SelectPrompt{getFilteredChoices(){return this.filteredResults||this.options.choices}handleInput(char){if(char==="\b"||char===""){if(this.searchBuffer.length>0){this.searchBuffer=this.searchBuffer.slice(0,-1);this.performSearch()}return}if(char.length===1&&!/^[\x00-\x1F]/.test(char)&&!char.startsWith("\x1b")){this.searchBuffer+=char;if(this.options.choices.length>1e3){if(this.debounceTimer)clearTimeout(this.debounceTimer);this.debounceTimer=setTimeout(()=>{this.performSearch()},150)}else{this.performSearch()}return}super.handleInput(char)}performSearch(){if(!this.searchBuffer){this.filteredResults=this.options.choices}else{const results=this.options.choices.map(c=>{if(this.isSeparator(c))return null;const match=(0,_utils.fuzzyMatch)(this.searchBuffer,c.title);return{choice:c,match}}).filter(item=>item&&item.match!==null).sort((a,b)=>b.match.score-a.match.score);this.filteredResults=results.map(r=>{r.choice._match=r.match;return r.choice})}this.selectedIndex=0;this.render(false)}highlight(text,indices,isSelected){let output="";const indexSet=new Set(indices);for(let i=0;i<text.length;i++){if(indexSet.has(i)){if(isSelected){output+=`${_ansi.ANSI.BOLD}${_ansi.ANSI.FG_WHITE}${text[i]}${_theme.theme.main}`}else{output+=`${_ansi.ANSI.BOLD}${_ansi.ANSI.FG_CYAN}${text[i]}${_ansi.ANSI.RESET}`}}else{output+=text[i]}}return output}render(_firstRender){let output="";const choices=this.getFilteredChoices();if(this.selectedIndex<this.scrollTop){this.scrollTop=this.selectedIndex}else if(this.selectedIndex>=this.scrollTop+this.pageSize){this.scrollTop=this.selectedIndex-this.pageSize+1}if(this.scrollTop>choices.length-1){this.scrollTop=Math.max(0,choices.length-this.pageSize)}const searchStr=this.searchBuffer?` ${_theme.theme.muted}(Fuzzy: ${this.searchBuffer})${_ansi.ANSI.RESET}`:"";output+=`${_theme.theme.success}?${_ansi.ANSI.RESET} ${_ansi.ANSI.BOLD}${_theme.theme.title}${this.options.message}${_ansi.ANSI.RESET}${searchStr}
|
|
2
|
+
`;if(choices.length===0){output+=` ${_theme.theme.muted}No results found${_ansi.ANSI.RESET}`}else{const visibleChoices=choices.slice(this.scrollTop,this.scrollTop+this.pageSize);visibleChoices.forEach((choice,index)=>{const actualIndex=this.scrollTop+index;if(index>0)output+="\n";if(this.isSeparator(choice)){output+=` ${_ansi.ANSI.DIM}${choice.text||_symbols.symbols.line.repeat(8)}${_ansi.ANSI.RESET}`}else{let title=choice.title;const match=choice._match;const isSelected=actualIndex===this.selectedIndex;if(match&&this.searchBuffer){title=this.highlight(title,match.indices,isSelected)}if(isSelected){output+=`${_theme.theme.main}${_symbols.symbols.pointer} ${title}${_ansi.ANSI.RESET}`;if(match&&this.searchBuffer){}}else{output+=` ${title}`}}})}this.renderFrame(output)}constructor(options){super(options),_define_property(this,"filteredResults",[]),_define_property(this,"debounceTimer",void 0);this.filteredResults=this.options.choices}};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Prompt } from '../base';
|
|
2
|
+
import { GaugeOptions } from '../types';
|
|
3
|
+
export declare class GaugePrompt extends Prompt<string, GaugeOptions> {
|
|
4
|
+
private cursor;
|
|
5
|
+
private direction;
|
|
6
|
+
private running;
|
|
7
|
+
private timer?;
|
|
8
|
+
private readonly width;
|
|
9
|
+
private readonly safeZoneHalf;
|
|
10
|
+
private readonly warnZoneHalf;
|
|
11
|
+
private result;
|
|
12
|
+
private resultColor;
|
|
13
|
+
constructor(options: GaugeOptions);
|
|
14
|
+
run(): Promise<string>;
|
|
15
|
+
private startLoop;
|
|
16
|
+
private tick;
|
|
17
|
+
private stop;
|
|
18
|
+
protected handleInput(char: string, _key: Buffer): void;
|
|
19
|
+
protected render(_firstRender: boolean): void;
|
|
20
|
+
protected cleanup(): void;
|
|
21
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"GaugePrompt",{enumerable:true,get:function(){return GaugePrompt}});const _ansi=require("../ansi");const _base=require("../base");const _theme=require("../theme");function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}let GaugePrompt=class GaugePrompt extends _base.Prompt{run(){const p=super.run();this.startLoop();return p}startLoop(){if(!this.running)return;this.timer=setTimeout(()=>{this.tick();this.startLoop()},30)}tick(){this.cursor+=this.direction*2;if(this.cursor>=100){this.cursor=100;this.direction=-1}else if(this.cursor<=0){this.cursor=0;this.direction=1}this.render(false)}stop(){this.running=false;if(this.timer)clearTimeout(this.timer);const center=50;const distance=Math.abs(this.cursor-center);if(distance<=this.safeZoneHalf){this.result="PERFECT!";this.resultColor=_theme.theme.success}else if(distance<=this.warnZoneHalf){this.result="GOOD";this.resultColor=_ansi.ANSI.FG_YELLOW}else{this.result="MISS";this.resultColor=_theme.theme.error}this.render(false);setTimeout(()=>{this.submit(this.result)},800)}handleInput(char,_key){if(!this.running)return;if(char===" "){this.stop()}}render(_firstRender){let output="";output+=`${_theme.theme.success}?${_ansi.ANSI.RESET} ${_ansi.ANSI.BOLD}${_theme.theme.title}${this.options.message}${_ansi.ANSI.RESET}
|
|
2
|
+
`;let barStr="";const center=50;for(let i=0;i<this.width;i++){const pct=i/this.width*100;const dist=Math.abs(pct-center);let charColor=_theme.theme.error;if(dist<=this.safeZoneHalf){charColor=_theme.theme.success}else if(dist<=this.warnZoneHalf){charColor=_ansi.ANSI.FG_YELLOW}barStr+=`${charColor}━${_ansi.ANSI.RESET}`}output+=` ${barStr}
|
|
3
|
+
`;const pos=Math.floor(this.cursor/100*(this.width-1));const padding=" ".repeat(pos);output+=` ${padding}${_theme.theme.main}▲${_ansi.ANSI.RESET}
|
|
4
|
+
`;if(this.running){output+=`${_theme.theme.muted}(Press Space to Stop)${_ansi.ANSI.RESET}`}else{output+=`${_ansi.ANSI.BOLD}${this.resultColor}${this.result}${_ansi.ANSI.RESET}`}this.renderFrame(output)}cleanup(){if(this.timer)clearTimeout(this.timer);super.cleanup()}constructor(options){super(options),_define_property(this,"cursor",0),_define_property(this,"direction",1),_define_property(this,"running",true),_define_property(this,"timer",void 0),_define_property(this,"width",void 0),_define_property(this,"safeZoneHalf",void 0),_define_property(this,"warnZoneHalf",void 0),_define_property(this,"result",null),_define_property(this,"resultColor","");this.width=options.width||40;const safeParam=options.safeZone??.2;let safeWidthPct;if(safeParam<=1){safeWidthPct=safeParam*100}else{safeWidthPct=safeParam/this.width*100}this.safeZoneHalf=safeWidthPct/2;this.warnZoneHalf=Math.max(this.safeZoneHalf*3,30)}};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Prompt } from '../base';
|
|
2
|
+
import { GridOptions, MouseEvent } from '../types';
|
|
3
|
+
export declare class GridPrompt extends Prompt<boolean[][], GridOptions> {
|
|
4
|
+
private cursorRow;
|
|
5
|
+
private cursorCol;
|
|
6
|
+
private selected;
|
|
7
|
+
private columnWidths;
|
|
8
|
+
private rowLabelWidth;
|
|
9
|
+
constructor(options: GridOptions);
|
|
10
|
+
private calculateLayout;
|
|
11
|
+
protected render(_firstRender: boolean): void;
|
|
12
|
+
protected handleInput(char: string, _key: Buffer): void;
|
|
13
|
+
protected handleMouse(event: MouseEvent): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"GridPrompt",{enumerable:true,get:function(){return GridPrompt}});const _ansi=require("../ansi");const _base=require("../base");const _theme=require("../theme");const _utils=require("../utils");function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}let GridPrompt=class GridPrompt extends _base.Prompt{calculateLayout(){this.rowLabelWidth=0;for(const row of this.options.rows){this.rowLabelWidth=Math.max(this.rowLabelWidth,(0,_utils.stringWidth)(row))}this.columnWidths=this.options.columns.map(col=>{return Math.max((0,_utils.stringWidth)(col),3)})}render(_firstRender){const{rows,columns}=this.options;let output=`${_theme.theme.title}${this.options.message}${_ansi.ANSI.RESET}
|
|
2
|
+
`;output+=" ".repeat(this.rowLabelWidth+2);output+=columns.map((col,i)=>{const width=this.columnWidths[i];const padding=width-(0,_utils.stringWidth)(col);const leftPad=Math.floor(padding/2);const rightPad=padding-leftPad;return`${_theme.theme.muted}${" ".repeat(leftPad)}${col}${" ".repeat(rightPad)}${_ansi.ANSI.RESET}`}).join(" ")+"\n";for(let r=0;r<rows.length;r++){const rowLabel=rows[r];const labelPadding=this.rowLabelWidth-(0,_utils.stringWidth)(rowLabel);output+=`${_theme.theme.muted}${rowLabel}${" ".repeat(labelPadding)}${_ansi.ANSI.RESET} `;const cells=this.selected[r].map((isChecked,c)=>{const isFocused=r===this.cursorRow&&c===this.cursorCol;const width=this.columnWidths[c];const content=isChecked?`[${_theme.theme.success}x${_ansi.ANSI.RESET}]`:"[ ]";const padding=width-3;const leftPad=Math.floor(padding/2);const rightPad=padding-leftPad;let cellStr=`${" ".repeat(leftPad)}${content}${" ".repeat(rightPad)}`;if(isFocused){cellStr=`${_ansi.ANSI.REVERSE}${cellStr}${_ansi.ANSI.RESET}`}return cellStr});output+=cells.join(" ")+"\n"}output+=`${_theme.theme.muted}Arrows to move, Space to toggle, Enter to submit${_ansi.ANSI.RESET}`;this.renderFrame(output)}handleInput(char,_key){const isUp=this.isUp(char);const isDown=this.isDown(char);const isLeft=this.isLeft(char);const isRight=this.isRight(char);if(isUp||isDown||isLeft||isRight){if(isUp)this.cursorRow=Math.max(0,this.cursorRow-1);if(isDown)this.cursorRow=Math.min(this.options.rows.length-1,this.cursorRow+1);if(isLeft)this.cursorCol=Math.max(0,this.cursorCol-1);if(isRight)this.cursorCol=Math.min(this.options.columns.length-1,this.cursorCol+1);this.render(false);return}if(char===" "){this.selected[this.cursorRow][this.cursorCol]=!this.selected[this.cursorRow][this.cursorCol];this.render(false);return}if(char==="\r"||char==="\n"){this.submit(this.selected);return}if(char==="\x1b[5~"){this.cursorRow=0;this.render(false);return}if(char==="\x1b[6~"){this.cursorRow=this.options.rows.length-1;this.render(false);return}if(char==="\x1b[H"||char==="\x1b[1~"){this.cursorCol=0;this.render(false);return}if(char==="\x1b[F"||char==="\x1b[4~"){this.cursorCol=this.options.columns.length-1;this.render(false);return}if(char==="r"){const row=this.selected[this.cursorRow];const allSelected=row.every(c=>c);this.selected[this.cursorRow]=row.map(()=>!allSelected);this.render(false);return}if(char==="c"){const colIdx=this.cursorCol;const colValues=this.selected.map(row=>row[colIdx]);const allSelected=colValues.every(c=>c);this.selected.forEach(row=>row[colIdx]=!allSelected);this.render(false);return}if(char==="a"){this.selected=this.selected.map(row=>row.map(()=>true));this.render(false);return}if(char==="x"){this.selected=this.selected.map(row=>row.map(()=>false));this.render(false);return}if(char==="i"){this.selected=this.selected.map(row=>row.map(v=>!v));this.render(false);return}}handleMouse(event){if(event.action==="scroll"){const direction=event.scroll==="up"?-1:1;if(event.shift){this.cursorCol=Math.max(0,Math.min(this.options.columns.length-1,this.cursorCol+direction))}else{this.cursorRow=Math.max(0,Math.min(this.options.rows.length-1,this.cursorRow+direction))}this.render(false)}}constructor(options){super(options),_define_property(this,"cursorRow",0),_define_property(this,"cursorCol",0),_define_property(this,"selected",void 0),_define_property(this,"columnWidths",[]),_define_property(this,"rowLabelWidth",0);if(options.initial){this.selected=options.initial.map(row=>[...row])}else{this.selected=options.rows.map(()=>new Array(options.columns.length).fill(false))}this.calculateLayout()}};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Prompt } from '../base';
|
|
2
|
+
import { HeatmapOptions, MouseEvent } from '../types';
|
|
3
|
+
export declare class HeatmapPrompt extends Prompt<number[][], HeatmapOptions> {
|
|
4
|
+
private grid;
|
|
5
|
+
private cursorRow;
|
|
6
|
+
private cursorCol;
|
|
7
|
+
private validValues;
|
|
8
|
+
constructor(options: HeatmapOptions);
|
|
9
|
+
protected render(_firstRender: boolean): void;
|
|
10
|
+
private getLegend;
|
|
11
|
+
protected handleMouse(event: MouseEvent): void;
|
|
12
|
+
protected handleInput(char: string, _key: Buffer): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"HeatmapPrompt",{enumerable:true,get:function(){return HeatmapPrompt}});const _base=require("../base");const _ansi=require("../ansi");function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}let HeatmapPrompt=class HeatmapPrompt extends _base.Prompt{render(_firstRender){let output=`${_ansi.ANSI.FG_CYAN}? ${this.options.message}${_ansi.ANSI.RESET}
|
|
2
|
+
`;output+=" ";this.options.columns.forEach(col=>{const label=col.substring(0,2).padEnd(2);output+=` ${label} `});output+="\n";for(let r=0;r<this.options.rows.length;r++){const rowLabel=this.options.rows[r].substring(0,4).padStart(4);output+=`${_ansi.ANSI.FG_GRAY}${rowLabel} ${_ansi.ANSI.RESET}`;for(let c=0;c<this.options.columns.length;c++){const val=this.grid[r][c];const legend=this.getLegend(val);const char=legend?.char||"?";const color=legend?.color||(s=>s);const isCursor=r===this.cursorRow&&c===this.cursorCol;const cellContent=color(char);if(isCursor){output+=`[${cellContent}]`}else{output+=` ${cellContent} `}}output+="\n"}output+="\nLegend: ";this.options.legend.forEach(l=>{output+=`${l.value}:${l.color(l.char)} `});output+="\n"+_ansi.ANSI.FG_GRAY+"(Arrows to move, Space to cycle, 0-9 to set)"+_ansi.ANSI.RESET;this.renderFrame(output)}getLegend(val){return this.options.legend.find(l=>l.value===val)}handleMouse(event){if(event.action==="scroll"){if(event.scroll==="up"){if(this.cursorRow>0)this.cursorRow--}else if(event.scroll==="down"){if(this.cursorRow<this.options.rows.length-1)this.cursorRow++}this.render(false)}}handleInput(char,_key){if(char==="\r"||char==="\n"){this.submit(this.grid);return}if(this.isUp(char)){if(this.cursorRow>0)this.cursorRow--}else if(this.isDown(char)){if(this.cursorRow<this.options.rows.length-1)this.cursorRow++}else if(this.isLeft(char)){if(this.cursorCol>0)this.cursorCol--}else if(this.isRight(char)){if(this.cursorCol<this.options.columns.length-1)this.cursorCol++}else if(char===" "){this.cursorCol++;if(this.cursorCol>=this.options.columns.length){this.cursorCol=0;this.cursorRow++;if(this.cursorRow>=this.options.rows.length){this.cursorRow=0}}}else if(char==="\x1b[Z"){this.cursorCol--;if(this.cursorCol<0){this.cursorCol=this.options.columns.length-1;this.cursorRow--;if(this.cursorRow<0){this.cursorRow=this.options.rows.length-1}}}else if(char===" "){const val=this.grid[this.cursorRow][this.cursorCol];const idx=this.validValues.indexOf(val);let nextVal;if(idx===-1){nextVal=this.validValues[0]}else{nextVal=this.validValues[(idx+1)%this.validValues.length]}this.grid[this.cursorRow][this.cursorCol]=nextVal}else if(/[0-9]/.test(char)){const num=parseInt(char,10);if(this.validValues.includes(num)){this.grid[this.cursorRow][this.cursorCol]=num}}this.render(false)}constructor(options){super(options),_define_property(this,"grid",void 0),_define_property(this,"cursorRow",0),_define_property(this,"cursorCol",0),_define_property(this,"validValues",void 0);const rows=options.rows.length;const cols=options.columns.length;if(options.initial){this.grid=options.initial.map(row=>[...row])}else{this.grid=Array.from({length:rows},()=>Array(cols).fill(0))}this.validValues=options.legend.map(l=>l.value).sort((a,b)=>a-b)}};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Prompt } from '../base';
|
|
2
|
+
import { IPOptions, MouseEvent } from '../types';
|
|
3
|
+
export declare class IPPrompt extends Prompt<string, IPOptions> {
|
|
4
|
+
private octets;
|
|
5
|
+
private activeOctet;
|
|
6
|
+
private errorMsg;
|
|
7
|
+
constructor(options: IPOptions);
|
|
8
|
+
protected render(_firstRender: boolean): void;
|
|
9
|
+
protected handleInput(char: string): void;
|
|
10
|
+
protected handleMouse(event: MouseEvent): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"IPPrompt",{enumerable:true,get:function(){return IPPrompt}});const _ansi=require("../ansi");const _base=require("../base");const _theme=require("../theme");const _symbols=require("../symbols");function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}let IPPrompt=class IPPrompt extends _base.Prompt{render(_firstRender){let output="";const icon=this.errorMsg?`${_theme.theme.error}${_symbols.symbols.cross}`:`${_theme.theme.success}?`;output+=`${icon} ${_ansi.ANSI.BOLD}${_theme.theme.title}${this.options.message}${_ansi.ANSI.RESET}
|
|
2
|
+
`;const partsDisplay=this.octets.map((octet,index)=>{const isEmpty=octet.length===0;let displayVal=isEmpty?"_":octet;if(index===this.activeOctet){displayVal=`${_theme.theme.main}${_ansi.ANSI.UNDERLINE}${displayVal}${_ansi.ANSI.RESET}`}return displayVal});output+=` ${partsDisplay.join(".")}`;if(this.errorMsg){output+=`
|
|
3
|
+
${_theme.theme.error}>> ${this.errorMsg}${_ansi.ANSI.RESET}`}this.renderFrame(output)}handleInput(char){this.errorMsg="";if(char==="\r"||char==="\n"){if(this.octets.every(o=>o.length>0)){this.submit(this.octets.join("."))}else{this.errorMsg="Invalid IP address";this.render(false)}return}if(char==="\b"||char===""){const current=this.octets[this.activeOctet];if(current.length>0){this.octets[this.activeOctet]=current.slice(0,-1)}else if(this.activeOctet>0){this.activeOctet--}this.render(false);return}if(this.isLeft(char)&&this.activeOctet>0){this.activeOctet--;this.render(false);return}if(this.isRight(char)&&this.activeOctet<3){this.activeOctet++;this.render(false);return}if(char==="."){if(this.activeOctet<3){this.activeOctet++;this.render(false)}return}if(/^\d$/.test(char)){const current=this.octets[this.activeOctet];const newValue=current+char;if(parseInt(newValue,10)<=255){this.octets[this.activeOctet]=newValue;if(newValue.length===3&&this.activeOctet<3){this.activeOctet++}this.render(false)}}}handleMouse(event){if(event.action==="scroll"){if(event.scroll==="up"){if(this.activeOctet>0){this.activeOctet--;this.render(false)}}else if(event.scroll==="down"){if(this.activeOctet<3){this.activeOctet++;this.render(false)}}}}constructor(options){super(options),_define_property(this,"octets",["","","",""]),_define_property(this,"activeOctet",0),_define_property(this,"errorMsg","");if(options.initial){const parts=options.initial.split(".");if(parts.length===4){this.octets=parts.map(p=>{const num=parseInt(p,10);return!isNaN(num)&&num>=0&&num<=255?p:""})}}}};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Prompt } from '../base';
|
|
2
|
+
import { KanbanOptions, KanbanItem, MouseEvent } from '../types';
|
|
3
|
+
export declare class KanbanPrompt<V extends KanbanItem> extends Prompt<Record<string, V[]>, KanbanOptions<V>> {
|
|
4
|
+
private columns;
|
|
5
|
+
private activeCol;
|
|
6
|
+
private activeRow;
|
|
7
|
+
private grabbed;
|
|
8
|
+
private scrollStates;
|
|
9
|
+
constructor(options: KanbanOptions<V>);
|
|
10
|
+
protected render(_firstRender: boolean): void;
|
|
11
|
+
private padCenter;
|
|
12
|
+
protected handleMouse(event: MouseEvent): void;
|
|
13
|
+
protected handleInput(char: string, _key: Buffer): void;
|
|
14
|
+
private moveItemHorizontal;
|
|
15
|
+
private clampRow;
|
|
16
|
+
private ensureVisible;
|
|
17
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"KanbanPrompt",{enumerable:true,get:function(){return KanbanPrompt}});const _base=require("../base");const _ansi=require("../ansi");const _utils=require("../utils");function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}let KanbanPrompt=class KanbanPrompt extends _base.Prompt{render(_firstRender){const{columns}=this.stdout;const colCount=this.columns.length;const colWidth=Math.floor(columns/colCount);let output="";output+=`${_ansi.ANSI.FG_CYAN}${_ansi.ANSI.BOLD}? ${this.options.message}${_ansi.ANSI.RESET}
|
|
2
|
+
`;if(this.grabbed){output+=`${_ansi.ANSI.FG_YELLOW}(Grabbed) Move with arrows, Space to Drop${_ansi.ANSI.RESET}
|
|
3
|
+
`}else{output+=`${_ansi.ANSI.FG_GRAY}(Normal) Space to Grab, Arrows to Navigate, Enter to Submit${_ansi.ANSI.RESET}
|
|
4
|
+
`}const headers=this.columns.map((col,i)=>{const isSelected=i===this.activeCol;const title=this.truncate(col.title,colWidth-4);const style=isSelected?`${_ansi.ANSI.FG_BLUE}${_ansi.ANSI.BOLD}`:_ansi.ANSI.BOLD;return this.padCenter(title,colWidth,style)});output+=headers.join("")+"\n";output+=_ansi.ANSI.FG_GRAY+"─".repeat(columns)+_ansi.ANSI.RESET+"\n";const viewportHeight=10;for(let r=0;r<viewportHeight;r++){const rowLine=this.columns.map((col,cIndex)=>{const scrollTop=this.scrollStates[cIndex];const itemIndex=r+scrollTop;const item=col.items[itemIndex];let content="";if(item){const isCursor=cIndex===this.activeCol&&itemIndex===this.activeRow;let prefix=" ";const suffix=" ";let style="";if(isCursor){if(this.grabbed){style=_ansi.ANSI.BG_YELLOW+_ansi.ANSI.FG_BLACK;prefix=">"}else{style=_ansi.ANSI.FG_CYAN+_ansi.ANSI.BOLD;prefix=">"}}const title=this.truncate(item.title,colWidth-4);content=`${prefix} ${title}${suffix}`;content=content.padEnd(colWidth);const plain=`${prefix} ${title}${suffix}`.padEnd(colWidth);if(style){content=style+plain+_ansi.ANSI.RESET}else{content=plain}}else{content=" ".repeat(colWidth)}return content}).join("");output+=rowLine+"\n"}this.renderFrame(output)}padCenter(str,width,style=""){const visibleLen=(0,_utils.stringWidth)(str);if(visibleLen>=width)return style+str+_ansi.ANSI.RESET;const left=Math.floor((width-visibleLen)/2);const right=width-visibleLen-left;return" ".repeat(left)+style+str+_ansi.ANSI.RESET+" ".repeat(right)}handleMouse(event){if(event.action==="scroll"){if(this.grabbed){if(event.scroll==="up"){if(this.activeCol>0){this.moveItemHorizontal(-1);this.activeCol--;this.clampRow();this.ensureVisible()}}else if(event.scroll==="down"){if(this.activeCol<this.columns.length-1){this.moveItemHorizontal(1);this.activeCol++;this.clampRow();this.ensureVisible()}}}else{if(event.scroll==="up"){if(this.activeRow>0){this.activeRow--;this.ensureVisible()}}else if(event.scroll==="down"){const colLen=this.columns[this.activeCol].items.length;if(this.activeRow<colLen-1){this.activeRow++;this.ensureVisible()}}}this.render(false)}}handleInput(char,_key){if(char==="\r"||char==="\n"){const result={};this.columns.forEach(c=>{result[c.id]=c.items});this.submit(result);return}if(char===" "){this.grabbed=!this.grabbed;this.render(false);return}if(this.isLeft(char)){if(this.activeCol>0){if(this.grabbed){this.moveItemHorizontal(-1)}this.activeCol--;this.clampRow();this.ensureVisible()}}else if(this.isRight(char)){if(this.activeCol<this.columns.length-1){if(this.grabbed){this.moveItemHorizontal(1)}this.activeCol++;this.clampRow();this.ensureVisible()}}else if(this.isUp(char)){if(this.activeRow>0){if(this.grabbed){const col=this.columns[this.activeCol];const temp=col.items[this.activeRow];col.items[this.activeRow]=col.items[this.activeRow-1];col.items[this.activeRow-1]=temp}this.activeRow--;this.ensureVisible()}}else if(this.isDown(char)){const colLen=this.columns[this.activeCol].items.length;if(this.activeRow<colLen-1){if(this.grabbed){const col=this.columns[this.activeCol];const temp=col.items[this.activeRow];col.items[this.activeRow]=col.items[this.activeRow+1];col.items[this.activeRow+1]=temp}this.activeRow++;this.ensureVisible()}}this.render(false)}moveItemHorizontal(direction){const sourceCol=this.columns[this.activeCol];const targetCol=this.columns[this.activeCol+direction];const item=sourceCol.items.splice(this.activeRow,1)[0];let targetIndex=this.activeRow;if(targetIndex>targetCol.items.length){targetIndex=targetCol.items.length}targetCol.items.splice(targetIndex,0,item);this.activeRow=targetIndex}clampRow(){const len=this.columns[this.activeCol].items.length;if(len===0){this.activeRow=0}else if(this.activeRow>=len){this.activeRow=len-1}}ensureVisible(){const scrollTop=this.scrollStates[this.activeCol];const viewportHeight=10;if(this.activeRow<scrollTop){this.scrollStates[this.activeCol]=this.activeRow}else if(this.activeRow>=scrollTop+viewportHeight){this.scrollStates[this.activeCol]=this.activeRow-viewportHeight+1}}constructor(options){super(options),_define_property(this,"columns",void 0),_define_property(this,"activeCol",0),_define_property(this,"activeRow",0),_define_property(this,"grabbed",false),_define_property(this,"scrollStates",void 0);this.columns=JSON.parse(JSON.stringify(options.columns));this.scrollStates=new Array(this.columns.length).fill(0)}};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Prompt } from '../base';
|
|
2
|
+
import { KeypressOptions } from '../types';
|
|
3
|
+
export declare class KeypressPrompt extends Prompt<string, KeypressOptions> {
|
|
4
|
+
constructor(options: KeypressOptions);
|
|
5
|
+
protected render(_firstRender: boolean): void;
|
|
6
|
+
protected handleInput(char: string, _key: Buffer): void;
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"KeypressPrompt",{enumerable:true,get:function(){return KeypressPrompt}});const _ansi=require("../ansi");const _base=require("../base");const _theme=require("../theme");let KeypressPrompt=class KeypressPrompt extends _base.Prompt{render(_firstRender){let output=`${_theme.theme.title}${this.options.message}${_ansi.ANSI.RESET}`;if(this.options.keys){const hint=this.options.keys.map(k=>{if(k==="\r"||k==="\n"||k==="enter")return"enter";if(k===" "||k==="space")return"space";return k}).join("/");output+=` ${_theme.theme.muted}(${hint})${_ansi.ANSI.RESET}`}else{output+=` ${_theme.theme.muted}(Press any key)${_ansi.ANSI.RESET}`}this.renderFrame(output)}handleInput(char,_key){let keyName=char;if(char==="\r"||char==="\n")keyName="enter";else if(char===" ")keyName="space";else if(char==="\x1b")keyName="escape";else if(char===" ")keyName="tab";else if(char===""||char==="\b")keyName="backspace";if(this.options.keys){const allowed=this.options.keys.map(k=>k.toLowerCase());if(!allowed.includes(keyName)&&!allowed.includes(char)){return}}if(this.options.showInvisible){this.print(` ${_theme.theme.success}${keyName}${_ansi.ANSI.RESET}`)}this.submit(keyName)}constructor(options){super(options)}};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SelectPrompt } from './select';
|
|
2
|
+
import { LicenseOptions } from '../types';
|
|
3
|
+
export declare class LicensePrompt extends SelectPrompt<string> {
|
|
4
|
+
private licenses;
|
|
5
|
+
constructor(options: LicenseOptions);
|
|
6
|
+
protected render(_firstRender: boolean): void;
|
|
7
|
+
private renderList;
|
|
8
|
+
private renderDetails;
|
|
9
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"LicensePrompt",{enumerable:true,get:function(){return LicensePrompt}});const _ansi=require("../ansi");const _select=require("./select");const _theme=require("../theme");const _symbols=require("../symbols");const _utils=require("../utils");const _licenses=require("../data/licenses");function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}let LicensePrompt=class LicensePrompt extends _select.SelectPrompt{render(_firstRender){const choices=this.getFilteredChoices();if(this.selectedIndex<this.scrollTop){this.scrollTop=this.selectedIndex}else if(this.selectedIndex>=this.scrollTop+this.pageSize){this.scrollTop=this.selectedIndex-this.pageSize+1}if(this.scrollTop>choices.length-1){this.scrollTop=Math.max(0,choices.length-this.pageSize)}const width=this.stdout.columns||80;const gap=2;const ratio=.3;const leftWidth=Math.floor((width-gap)*ratio);const rightWidth=width-leftWidth-gap;const leftContent=this.renderList();const rightContent=this.renderDetails(rightWidth);const content=_utils.Layout.split(leftContent,rightContent,width,{ratio,gap});const searchStr=this.searchBuffer?` ${_theme.theme.muted}(Filter: ${this.searchBuffer})${_ansi.ANSI.RESET}`:"";const header=`${_theme.theme.success}? ${_ansi.ANSI.BOLD}${_theme.theme.title}${this.options.message}${_ansi.ANSI.RESET}${searchStr} ${_theme.theme.muted}(Use arrows to navigate, Enter to select)${_ansi.ANSI.RESET}`;this.renderFrame(`${header}
|
|
2
|
+
${content}`)}renderList(){const choices=this.getFilteredChoices();let output="";if(choices.length===0){output+=` ${_theme.theme.muted}No results found${_ansi.ANSI.RESET}`;return output+"\n".repeat(this.pageSize-1)}const visibleChoices=choices.slice(this.scrollTop,this.scrollTop+this.pageSize);visibleChoices.forEach((choice,index)=>{const actualIndex=this.scrollTop+index;const isSelected=actualIndex===this.selectedIndex;const cursor=isSelected?`${_theme.theme.main}${_symbols.symbols.pointer}`:" ";if("separator"in choice){output+=`${_theme.theme.muted}${choice.text||"---"}${_ansi.ANSI.RESET}
|
|
3
|
+
`;return}const title=isSelected?`${_theme.theme.main}${choice.title}${_ansi.ANSI.RESET}`:choice.title;output+=`${cursor} ${title}
|
|
4
|
+
`});const filledLines=visibleChoices.length;if(filledLines<this.pageSize){output+="\n".repeat(this.pageSize-filledLines)}return output}renderDetails(maxWidth){const choices=this.getFilteredChoices();if(choices.length===0)return"";const selectedChoice=choices[this.selectedIndex];if(!selectedChoice||"separator"in selectedChoice)return"";const license=this.licenses.find(l=>l.id===selectedChoice.value);if(!license)return"";let output="";output+=`${_ansi.ANSI.BOLD}${license.name}${_ansi.ANSI.RESET}
|
|
5
|
+
`;const wrappedDesc=_utils.Layout.wrap(license.description,maxWidth);const coloredDesc=wrappedDesc.split("\n").map(line=>`${_theme.theme.muted}${line}${_ansi.ANSI.RESET}`).join("\n");output+=`${coloredDesc}
|
|
6
|
+
|
|
7
|
+
`;if(license.permissions.length>0){output+=`${_ansi.ANSI.FG_GREEN}Permissions:${_ansi.ANSI.RESET}
|
|
8
|
+
`;license.permissions.forEach(p=>output+=` ${_theme.theme.success}${_symbols.symbols.checked} ${p}${_ansi.ANSI.RESET}
|
|
9
|
+
`);output+="\n"}if(license.conditions.length>0){output+=`${_ansi.ANSI.FG_BLUE}Conditions:${_ansi.ANSI.RESET}
|
|
10
|
+
`;license.conditions.forEach(c=>output+=` ${_ansi.ANSI.FG_BLUE}ℹ ${c}${_ansi.ANSI.RESET}
|
|
11
|
+
`);output+="\n"}if(license.limitations.length>0){output+=`${_ansi.ANSI.FG_RED}Limitations:${_ansi.ANSI.RESET}
|
|
12
|
+
`;license.limitations.forEach(l=>output+=` ${_theme.theme.error}${_symbols.symbols.cross} ${l}${_ansi.ANSI.RESET}
|
|
13
|
+
`)}return output}constructor(options){const choices=_licenses.POPULAR_LICENSES.map(l=>({title:l.id,value:l.id,description:l.name}));super({...options,choices}),_define_property(this,"licenses",void 0);this.licenses=_licenses.POPULAR_LICENSES;if(options.defaultLicense){const idx=this.licenses.findIndex(l=>l.id===options.defaultLicense);if(idx!==-1){this.selectedIndex=idx}}}};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Prompt } from '../base';
|
|
2
|
+
import { ListOptions } from '../types';
|
|
3
|
+
export declare class ListPrompt extends Prompt<string[], ListOptions> {
|
|
4
|
+
private currentInput;
|
|
5
|
+
private errorMsg;
|
|
6
|
+
constructor(options: ListOptions);
|
|
7
|
+
protected render(_firstRender: boolean): void;
|
|
8
|
+
protected handleInput(char: string): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"ListPrompt",{enumerable:true,get:function(){return ListPrompt}});const _ansi=require("../ansi");const _base=require("../base");const _theme=require("../theme");const _symbols=require("../symbols");function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}let ListPrompt=class ListPrompt extends _base.Prompt{render(_firstRender){const cols=process.stdout.columns||80;const icon=this.errorMsg?`${_theme.theme.error}${_symbols.symbols.cross}`:`${_theme.theme.success}?`;const prefix=`${icon} ${_ansi.ANSI.BOLD}${_theme.theme.title}${this.options.message}${_ansi.ANSI.RESET} `;const lines=[];let currentLine=prefix;const addText=text=>{const visualLen=this.stripAnsi(currentLine).length+this.stripAnsi(text).length;if(visualLen>cols){lines.push(currentLine);currentLine=text.trimStart()}else{currentLine+=text}};if(this.value.length>0){this.value.forEach(tag=>{const tagStr=`${_theme.theme.main}[${tag}]${_ansi.ANSI.RESET} `;addText(tagStr)})}addText(this.currentInput);lines.push(currentLine);const inputLineIndex=lines.length-1;const inputVisualCol=this.stripAnsi(currentLine).length;if(this.errorMsg){lines.push(`${_theme.theme.error}>> ${this.errorMsg}${_ansi.ANSI.RESET}`)}const output=lines.join("\n");this.renderFrame(output);this.print(_ansi.ANSI.SHOW_CURSOR);const totalRows=lines.length;const linesUp=totalRows-1-inputLineIndex;if(linesUp>0){this.print(`\x1b[${linesUp}A`)}this.print(_ansi.ANSI.CURSOR_LEFT);if(inputVisualCol>0){this.print(`\x1b[${inputVisualCol}C`)}}handleInput(char){if(char==="\r"||char==="\n"){if(this.currentInput.trim()){this.value.push(this.currentInput.trim());this.currentInput="";this.errorMsg="";this.render(false)}else{if(this.options.validate){const result=this.options.validate(this.value);if(result!==true){this.errorMsg=typeof result==="string"?result:"Invalid input";this.render(false);return}}this.submit(this.value)}return}if(char==="\b"||char===""){if(this.currentInput.length>0){this.currentInput=this.currentInput.slice(0,-1);this.render(false)}else if(this.value.length>0){const last=this.value.pop();this.currentInput=last||"";this.render(false)}return}if(!/^[\x00-\x1F]/.test(char)&&!char.startsWith("\x1b")){this.currentInput+=char;this.render(false)}}constructor(options){super(options),_define_property(this,"currentInput",""),_define_property(this,"errorMsg","");this.value=options.initial||[]}};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Prompt } from '../base';
|
|
2
|
+
import { MapOptions, MouseEvent } from '../types';
|
|
3
|
+
export declare class MapPrompt extends Prompt<Record<string, string>, MapOptions> {
|
|
4
|
+
private items;
|
|
5
|
+
private rowIndex;
|
|
6
|
+
private colIndex;
|
|
7
|
+
private scrollTop;
|
|
8
|
+
private readonly pageSize;
|
|
9
|
+
private errorMsg;
|
|
10
|
+
private ghost;
|
|
11
|
+
constructor(options: MapOptions);
|
|
12
|
+
protected render(_firstRender: boolean): void;
|
|
13
|
+
private pad;
|
|
14
|
+
private updateGhost;
|
|
15
|
+
protected handleInput(char: string): void;
|
|
16
|
+
protected handleMouse(event: MouseEvent): void;
|
|
17
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"MapPrompt",{enumerable:true,get:function(){return MapPrompt}});const _ansi=require("../ansi");const _base=require("../base");const _theme=require("../theme");const _symbols=require("../symbols");const _utils=require("../utils");function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}let MapPrompt=class MapPrompt extends _base.Prompt{render(_firstRender){let output="";const icon=this.errorMsg?`${_theme.theme.error}${_symbols.symbols.cross}`:`${_theme.theme.success}?`;output+=`${icon} ${_ansi.ANSI.BOLD}${_theme.theme.title}${this.options.message}${_ansi.ANSI.RESET}
|
|
2
|
+
`;const maxKeyWidth=Math.max(5,...this.items.map((item,idx)=>{const ghostLen=idx===this.rowIndex&&this.colIndex===0?(0,_utils.stringWidth)(this.ghost):0;return(0,_utils.stringWidth)(item.key)+ghostLen}))+2;if(this.rowIndex<this.scrollTop){this.scrollTop=this.rowIndex}else if(this.rowIndex>=this.scrollTop+this.pageSize){this.scrollTop=this.rowIndex-this.pageSize+1}const maxScroll=Math.max(0,this.items.length-this.pageSize);this.scrollTop=Math.min(this.scrollTop,maxScroll);const keyHeader=this.pad("Key",maxKeyWidth);output+=` ${_ansi.ANSI.BOLD}${keyHeader}Value${_ansi.ANSI.RESET}
|
|
3
|
+
`;const visibleItems=this.items.slice(this.scrollTop,this.scrollTop+this.pageSize);visibleItems.forEach((item,index)=>{const actualIndex=this.scrollTop+index;if(index>0)output+="\n";const isRowActive=actualIndex===this.rowIndex;const pointer=isRowActive?`${_theme.theme.main}${_symbols.symbols.pointer}${_ansi.ANSI.RESET} `:" ";let keyStr=item.key;let ghostStr="";if(isRowActive&&this.colIndex===0){if(this.ghost){ghostStr=`${_theme.theme.muted}${this.ghost}${_ansi.ANSI.RESET}`}keyStr=`${_theme.theme.main}${_ansi.ANSI.UNDERLINE}${keyStr}${_ansi.ANSI.RESET}${ghostStr}`}const keyVisualWidth=(0,_utils.stringWidth)(item.key)+(isRowActive&&this.colIndex===0?(0,_utils.stringWidth)(this.ghost):0);const padding=" ".repeat(Math.max(0,maxKeyWidth-keyVisualWidth));let valStr=item.value;if(isRowActive&&this.colIndex===1){valStr=`${_theme.theme.main}${_ansi.ANSI.UNDERLINE}${valStr||" "}${_ansi.ANSI.RESET}`}output+=`${pointer}${keyStr}${padding}${valStr}`});output+=`
|
|
4
|
+
${_ansi.ANSI.DIM}(Ctrl+N: Add, Ctrl+D: Del)${_ansi.ANSI.RESET}`;if(this.errorMsg){output+=`
|
|
5
|
+
${_theme.theme.error}>> ${this.errorMsg}${_ansi.ANSI.RESET}`}this.renderFrame(output)}pad(str,width){const len=(0,_utils.stringWidth)(str);if(len>=width)return str;return str+" ".repeat(width-len)}updateGhost(){this.ghost="";if(this.colIndex!==0||!this.options.suggestions)return;const currentKey=this.items[this.rowIndex].key;if(!currentKey)return;const lowerKey=currentKey.toLowerCase();const match=this.options.suggestions.find(s=>s.toLowerCase().startsWith(lowerKey)&&s.length>currentKey.length);if(match){this.ghost=match.slice(currentKey.length)}}handleInput(char){this.errorMsg="";if(char===" "){if(this.colIndex===0&&this.ghost){this.items[this.rowIndex].key+=this.ghost;this.ghost="";this.render(false);return}this.colIndex=this.colIndex===0?1:0;this.ghost="";this.render(false);return}if(this.isUp(char)){if(this.rowIndex>0)this.rowIndex--;this.ghost="";this.render(false);return}if(this.isDown(char)){if(this.rowIndex<this.items.length-1){this.rowIndex++}else{this.items.push({key:"",value:""});this.rowIndex++;this.colIndex=0}this.ghost="";this.render(false);return}if(this.isRight(char)||this.isLeft(char)){this.colIndex=this.colIndex===0?1:0;this.ghost="";this.render(false);return}if(char==="\x0e"){this.items.push({key:"",value:""});this.rowIndex=this.items.length-1;this.colIndex=0;this.ghost="";this.render(false);return}if(char==="\x04"){if(this.items.length>1){this.items.splice(this.rowIndex,1);if(this.rowIndex>=this.items.length){this.rowIndex=this.items.length-1}}else{this.items[0]={key:"",value:""}}this.ghost="";this.render(false);return}if(char==="\r"||char==="\n"){const keys=this.items.map(i=>i.key);const duplicates=keys.filter((item,index)=>keys.indexOf(item)!==index&&item!=="");if(duplicates.length>0){this.errorMsg=`Duplicate keys found: ${duplicates.join(", ")}`;this.render(false);return}if(keys.some(k=>k==="")){this.errorMsg="Keys cannot be empty";this.render(false);return}const result={};this.items.forEach(item=>{result[item.key]=item.value});this.submit(result);return}if(char==="\b"||char===""){const item=this.items[this.rowIndex];if(this.colIndex===0){if(item.key.length>0){item.key=item.key.slice(0,-1);this.updateGhost()}else{this.ghost=""}}else{if(item.value.length>0)item.value=item.value.slice(0,-1)}this.render(false);return}if(!/^[\x00-\x1F]/.test(char)){const item=this.items[this.rowIndex];if(this.colIndex===0){item.key+=char;this.updateGhost()}else{item.value+=char}this.render(false)}}handleMouse(event){if(event.action==="scroll"){if(event.scroll==="up"){if(this.rowIndex>0){this.rowIndex--;this.ghost="";this.render(false)}}else if(event.scroll==="down"){if(this.rowIndex<this.items.length-1){this.rowIndex++;this.ghost="";this.render(false)}}}}constructor(options){super(options),_define_property(this,"items",[]),_define_property(this,"rowIndex",0),_define_property(this,"colIndex",0),_define_property(this,"scrollTop",0),_define_property(this,"pageSize",7),_define_property(this,"errorMsg",""),_define_property(this,"ghost","");if(options.initial){this.items=Object.entries(options.initial).map(([key,value])=>({key,value}))}if(this.items.length===0){this.items.push({key:"",value:""})}}};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Prompt } from '../base';
|
|
2
|
+
import { MatchOptions, MouseEvent } from '../types';
|
|
3
|
+
export declare class MatchPrompt extends Prompt<Record<string, any[]>, MatchOptions> {
|
|
4
|
+
private source;
|
|
5
|
+
private target;
|
|
6
|
+
private links;
|
|
7
|
+
private cursorSource;
|
|
8
|
+
private cursorTarget;
|
|
9
|
+
private scrollTopSource;
|
|
10
|
+
private scrollTopTarget;
|
|
11
|
+
private activeSide;
|
|
12
|
+
private pickedSourceIndex;
|
|
13
|
+
private readonly pageSize;
|
|
14
|
+
constructor(options: MatchOptions);
|
|
15
|
+
private normalize;
|
|
16
|
+
protected render(_firstRender: boolean): void;
|
|
17
|
+
protected handleInput(char: string): void;
|
|
18
|
+
protected handleMouse(event: MouseEvent): void;
|
|
19
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"MatchPrompt",{enumerable:true,get:function(){return MatchPrompt}});const _ansi=require("../ansi");const _base=require("../base");const _theme=require("../theme");const _symbols=require("../symbols");const _utils=require("../utils");function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}let MatchPrompt=class MatchPrompt extends _base.Prompt{normalize(items){return items.map(item=>{if(typeof item==="string"){return{id:item,label:item,value:item}}return item})}render(_firstRender){const termWidth=process.stdout.columns||80;const colWidth=Math.floor((termWidth-8)/2);if(this.activeSide==="source"){if(this.cursorSource<this.scrollTopSource)this.scrollTopSource=this.cursorSource;if(this.cursorSource>=this.scrollTopSource+this.pageSize)this.scrollTopSource=this.cursorSource-this.pageSize+1}else{if(this.cursorTarget<this.scrollTopTarget)this.scrollTopTarget=this.cursorTarget;if(this.cursorTarget>=this.scrollTopTarget+this.pageSize)this.scrollTopTarget=this.cursorTarget-this.pageSize+1}let output=`${_theme.theme.success}?${_ansi.ANSI.RESET} ${_ansi.ANSI.BOLD}${_theme.theme.title}${this.options.message}${_ansi.ANSI.RESET}
|
|
2
|
+
`;const sourceTitle=this.activeSide==="source"?`${_theme.theme.main}Source${_ansi.ANSI.RESET}`:"Source";const targetTitle=this.activeSide==="target"?`${_theme.theme.main}Target${_ansi.ANSI.RESET}`:"Target";output+=` ${sourceTitle}`.padEnd(colWidth+2)+" "+` ${targetTitle}
|
|
3
|
+
`;output+=` ${_ansi.ANSI.DIM}${_symbols.symbols.line.repeat(colWidth)}${_ansi.ANSI.RESET} ${_ansi.ANSI.DIM}${_symbols.symbols.line.repeat(colWidth)}${_ansi.ANSI.RESET}
|
|
4
|
+
`;for(let i=0;i<this.pageSize;i++){const idxSource=this.scrollTopSource+i;const idxTarget=this.scrollTopTarget+i;const itemSource=this.source[idxSource];const itemTarget=this.target[idxTarget];let sourceStr="";if(itemSource){const isSelected=this.activeSide==="source"&&idxSource===this.cursorSource;const isPicked=this.pickedSourceIndex===idxSource;const hasLinks=this.links.has(itemSource.id)&&this.links.get(itemSource.id).size>0;let prefix=" ";if(isSelected)prefix=`${_theme.theme.main}${_symbols.symbols.pointer} `;if(isPicked)prefix=`${_theme.theme.success}${_symbols.symbols.pointer} `;let title=this.truncate(itemSource.label,colWidth-4);if(isPicked){title=`${_theme.theme.success}${title}${_ansi.ANSI.RESET}`}else if(hasLinks){title=`${_theme.theme.success}${title}${_ansi.ANSI.RESET}`}else if(isSelected){title=`${_ansi.ANSI.FG_CYAN}${title}${_ansi.ANSI.RESET}`}const linkIndicator=hasLinks?`${_theme.theme.success}*${_ansi.ANSI.RESET}`:" ";sourceStr=`${prefix}${title} ${linkIndicator}`;if(isSelected||isPicked){}}else{sourceStr=""}let targetStr="";if(itemTarget){const isSelected=this.activeSide==="target"&&idxTarget===this.cursorTarget;const relevantSourceIdx=this.pickedSourceIndex!==null?this.pickedSourceIndex:this.cursorSource;const relevantSource=this.source[relevantSourceIdx];let isLinkedToRelevant=false;let isLinkedToAny=false;for(const[sId,tIds]of Array.from(this.links.entries())){if(tIds.has(itemTarget.id)){isLinkedToAny=true;if(relevantSource&&sId===relevantSource.id){isLinkedToRelevant=true}}}let prefix=" ";if(isSelected)prefix=`${_theme.theme.main}${_symbols.symbols.pointer} `;let title=this.truncate(itemTarget.label,colWidth-4);if(isLinkedToRelevant){title=`${_theme.theme.success}${title}${_ansi.ANSI.RESET}`}else if(isLinkedToAny){title=`${_ansi.ANSI.DIM}${title}${_ansi.ANSI.RESET}`}else if(isSelected){title=`${_ansi.ANSI.FG_CYAN}${title}${_ansi.ANSI.RESET}`}const linkIndicator=isLinkedToRelevant?`${_theme.theme.success}<=${_ansi.ANSI.RESET}`:isLinkedToAny?`${_ansi.ANSI.DIM}<=${_ansi.ANSI.RESET}`:" ";targetStr=`${linkIndicator} ${prefix}${title}`}const sourceVisualLen=itemSource?(0,_utils.stringWidth)(this.stripAnsi(sourceStr)):0;const padding=" ".repeat(Math.max(0,colWidth-sourceVisualLen+2));output+=sourceStr+padding+" "+targetStr+"\n"}if(this.pickedSourceIndex!==null){output+=`
|
|
5
|
+
${_theme.theme.success}Linking: ${this.source[this.pickedSourceIndex].label}${_ansi.ANSI.RESET}`;output+=`
|
|
6
|
+
${_ansi.ANSI.DIM}Select Target to Link/Unlink. Esc to Cancel.${_ansi.ANSI.RESET}`}else{output+=`
|
|
7
|
+
${_ansi.ANSI.DIM}Space to Pick Source, Enter to Submit.${_ansi.ANSI.RESET}`}this.renderFrame(output)}handleInput(char){if(this.isUp(char)){if(this.activeSide==="source"){this.cursorSource=Math.max(0,this.cursorSource-1)}else{this.cursorTarget=Math.max(0,this.cursorTarget-1)}this.render(false);return}if(this.isDown(char)){if(this.activeSide==="source"){this.cursorSource=Math.min(this.source.length-1,this.cursorSource+1)}else{this.cursorTarget=Math.min(this.target.length-1,this.cursorTarget+1)}this.render(false);return}if(char===" "){if(this.activeSide==="source"){this.pickedSourceIndex=this.cursorSource;this.activeSide="target"}else{if(this.pickedSourceIndex!==null){const sId=this.source[this.pickedSourceIndex].id;const tId=this.target[this.cursorTarget].id;if(!this.links.has(sId)){this.links.set(sId,new Set)}const sourceLinks=this.links.get(sId);if(sourceLinks.has(tId)){sourceLinks.delete(tId)}else{if(this.options.constraints?.oneToMany===false){for(const[otherSId,tIds]of Array.from(this.links.entries())){if(otherSId!==sId&&tIds.has(tId)){tIds.delete(tId)}}}sourceLinks.add(tId)}}}this.render(false);return}if(char==="\r"||char==="\n"){if(this.options.constraints?.required){const allLinked=this.source.every(s=>{return this.links.has(s.id)&&this.links.get(s.id).size>0});if(!allLinked){return}}const result={};for(const[sId,tIds]of Array.from(this.links.entries())){if(tIds.size>0){const values=Array.from(tIds).map(tid=>{return this.target.find(t=>t.id===tid)?.value});result[sId]=values}}this.submit(result);return}if(char==="\x1b"||char==="\b"||char===""||char==="h"){if(this.activeSide==="target"){this.activeSide="source";this.pickedSourceIndex=null;this.render(false)}return}if(char===" "){this.activeSide=this.activeSide==="source"?"target":"source";if(this.activeSide==="source"){this.pickedSourceIndex=null}this.render(false);return}}handleMouse(event){if(event.action==="scroll"){if(event.scroll==="up"){if(this.activeSide==="source"){this.cursorSource=Math.max(0,this.cursorSource-1)}else{this.cursorTarget=Math.max(0,this.cursorTarget-1)}}else{if(this.activeSide==="source"){this.cursorSource=Math.min(this.source.length-1,this.cursorSource+1)}else{this.cursorTarget=Math.min(this.target.length-1,this.cursorTarget+1)}}this.render(false)}}constructor(options){super(options),_define_property(this,"source",void 0),_define_property(this,"target",void 0),_define_property(this,"links",new Map),_define_property(this,"cursorSource",0),_define_property(this,"cursorTarget",0),_define_property(this,"scrollTopSource",0),_define_property(this,"scrollTopTarget",0),_define_property(this,"activeSide","source"),_define_property(this,"pickedSourceIndex",null),_define_property(this,"pageSize",10);this.source=this.normalize(options.source);this.target=this.normalize(options.target)}};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Prompt } from '../base';
|
|
2
|
+
import { MillerOptions, MouseEvent } from '../types';
|
|
3
|
+
export declare class MillerPrompt<V> extends Prompt<V[], MillerOptions<V>> {
|
|
4
|
+
private selections;
|
|
5
|
+
private activeCol;
|
|
6
|
+
private scrollTops;
|
|
7
|
+
private colWidth;
|
|
8
|
+
private visibleCols;
|
|
9
|
+
constructor(options: MillerOptions<V>);
|
|
10
|
+
private calculateLayout;
|
|
11
|
+
private getColumnData;
|
|
12
|
+
protected render(_firstRender: boolean): void;
|
|
13
|
+
protected handleInput(char: string): void;
|
|
14
|
+
protected handleMouse(event: MouseEvent): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"MillerPrompt",{enumerable:true,get:function(){return MillerPrompt}});const _base=require("../base");const _theme=require("../theme");const _ansi=require("../ansi");const _symbols=require("../symbols");const _utils=require("../utils");function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}let MillerPrompt=class MillerPrompt extends _base.Prompt{calculateLayout(){const termWidth=process.stdout.columns||80;this.visibleCols=Math.floor(termWidth/20);if(this.visibleCols<1)this.visibleCols=1;if(this.visibleCols>4)this.visibleCols=4;this.colWidth=Math.floor((termWidth-4)/this.visibleCols)}getColumnData(depth){let current=this.options.data;for(let i=0;i<depth;i++){const sel=this.selections[i];if(current[sel]&¤t[sel].children){current=current[sel].children}else{return undefined}}return current}render(_firstRender){let output="";output+=`${_theme.theme.success}?${_ansi.ANSI.RESET} ${_ansi.ANSI.BOLD}${_theme.theme.title}${this.options.message}${_ansi.ANSI.RESET}
|
|
2
|
+
`;let startCol=0;if(this.activeCol>=this.visibleCols){startCol=this.activeCol-this.visibleCols+1}const columnsToRender=[];for(let c=startCol;c<startCol+this.visibleCols;c++){const data=this.getColumnData(c);if(!data)break;const rows=[];const selectedIdx=this.selections[c]??-1;const isFocusedCol=c===this.activeCol;const pageSize=10;if(!this.scrollTops[c])this.scrollTops[c]=0;if(selectedIdx!==-1){if(selectedIdx<this.scrollTops[c]){this.scrollTops[c]=selectedIdx}else if(selectedIdx>=this.scrollTops[c]+pageSize){this.scrollTops[c]=selectedIdx-pageSize+1}}const start=this.scrollTops[c];const end=Math.min(data.length,start+pageSize);for(let i=start;i<end;i++){const item=data[i];const isSelected=i===selectedIdx;const isFocused=isSelected&&isFocusedCol;let prefix=" ";if(isSelected){prefix=isFocused?`${_theme.theme.main}${_symbols.symbols.pointer}${_ansi.ANSI.RESET}`:`${_theme.theme.muted}${_symbols.symbols.pointer}${_ansi.ANSI.RESET}`}let title=item.title;if((0,_utils.stringWidth)(title)>this.colWidth-4){title=title.slice(0,this.colWidth-5)+"…"}let line=`${prefix} ${isSelected&&isFocused?_theme.theme.main:""}${title}${_ansi.ANSI.RESET}`;if(item.children&&item.children.length>0){const pad=this.colWidth-(0,_utils.stringWidth)((0,_utils.stripAnsi)(line))-2;line+=" ".repeat(Math.max(0,pad))+`${_theme.theme.muted}>${_ansi.ANSI.RESET}`}rows.push(line)}while(rows.length<pageSize){rows.push("")}columnsToRender.push(rows)}const rowCount=10;for(let r=0;r<rowCount;r++){let line="";for(let c=0;c<columnsToRender.length;c++){let cell=columnsToRender[c][r]||"";const len=(0,_utils.stringWidth)((0,_utils.stripAnsi)(cell));const pad=this.colWidth-len;cell+=" ".repeat(Math.max(0,pad));line+=cell;if(c<columnsToRender.length-1){line+=`${_theme.theme.muted}│${_ansi.ANSI.RESET} `}}output+=line+"\n"}const pathTitles=[];for(let i=0;i<=this.activeCol;i++){const data=this.getColumnData(i);if(data&&typeof this.selections[i]==="number"){pathTitles.push(data[this.selections[i]].title)}}output+=`${_theme.theme.muted}Path: ${pathTitles.join(" / ")}${_ansi.ANSI.RESET}`;this.renderFrame(output)}handleInput(char){const currentData=this.getColumnData(this.activeCol);if(!currentData)return;if(char==="\r"||char==="\n"){const values=[];for(let i=0;i<=this.activeCol;i++){const d=this.getColumnData(i);if(d)values.push(d[this.selections[i]].value)}this.submit(values);return}if(this.isUp(char)){if(this.selections[this.activeCol]>0){this.selections[this.activeCol]--;this.selections=this.selections.slice(0,this.activeCol+1)}else{this.selections[this.activeCol]=currentData.length-1;this.selections=this.selections.slice(0,this.activeCol+1)}this.render(false);return}if(this.isDown(char)){if(this.selections[this.activeCol]<currentData.length-1){this.selections[this.activeCol]++;this.selections=this.selections.slice(0,this.activeCol+1)}else{this.selections[this.activeCol]=0;this.selections=this.selections.slice(0,this.activeCol+1)}this.render(false);return}if(this.isRight(char)||char===" "){const idx=this.selections[this.activeCol];const item=currentData[idx];if(item.children&&item.children.length>0){this.activeCol++;this.selections[this.activeCol]=0;this.render(false)}return}if(this.isLeft(char)||char==="\x1b[Z"){if(this.activeCol>0){this.activeCol--;this.render(false)}return}}handleMouse(event){if(event.action==="scroll"){const currentData=this.getColumnData(this.activeCol);if(!currentData||currentData.length===0)return;if(event.scroll==="up"){if(this.selections[this.activeCol]>0){this.selections[this.activeCol]--}else{this.selections[this.activeCol]=currentData.length-1}}else if(event.scroll==="down"){if(this.selections[this.activeCol]<currentData.length-1){this.selections[this.activeCol]++}else{this.selections[this.activeCol]=0}}this.selections=this.selections.slice(0,this.activeCol+1);this.render(false)}}constructor(options){super(options),_define_property(this,"selections",[]),_define_property(this,"activeCol",0),_define_property(this,"scrollTops",[]),_define_property(this,"colWidth",0),_define_property(this,"visibleCols",3);this.selections=[0];this.scrollTops=[0];this.calculateLayout()}};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SelectPrompt } from './select';
|
|
2
|
+
import { MultiColumnSelectOptions } from '../types';
|
|
3
|
+
export declare class MultiColumnSelectPrompt<V> extends SelectPrompt<V, MultiColumnSelectOptions<V>> {
|
|
4
|
+
protected cols: number;
|
|
5
|
+
protected colWidth: number;
|
|
6
|
+
constructor(options: MultiColumnSelectOptions<V>);
|
|
7
|
+
private calculateLayout;
|
|
8
|
+
protected render(_firstRender: boolean): void;
|
|
9
|
+
protected handleInput(char: string): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"MultiColumnSelectPrompt",{enumerable:true,get:function(){return MultiColumnSelectPrompt}});const _select=require("./select");const _theme=require("../theme");const _ansi=require("../ansi");const _utils=require("../utils");const _symbols=require("../symbols");function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}let MultiColumnSelectPrompt=class MultiColumnSelectPrompt extends _select.SelectPrompt{calculateLayout(){const termWidth=process.stdout.columns||80;const choices=this.options.choices.filter(c=>!this.isSeparator(c));if(choices.length===0){this.cols=1;this.colWidth=termWidth;return}let maxLen=0;for(const c of choices){const len=(0,_utils.stringWidth)(c.title);if(len>maxLen)maxLen=len}const itemWidth=maxLen+4;if(typeof this.options.cols==="number"){this.cols=this.options.cols}else{this.cols=Math.floor(termWidth/itemWidth);if(this.cols<1)this.cols=1}this.colWidth=Math.floor(termWidth/this.cols)}render(_firstRender){let output="";const choices=this.getFilteredChoices();const searchStr=this.searchBuffer?` ${_theme.theme.muted}(Filter: ${this.searchBuffer})${_ansi.ANSI.RESET}`:"";output+=`${_theme.theme.success}?${_ansi.ANSI.RESET} ${_ansi.ANSI.BOLD}${_theme.theme.title}${this.options.message}${_ansi.ANSI.RESET}${searchStr}
|
|
2
|
+
`;if(choices.length===0){output+=` ${_theme.theme.muted}No results found${_ansi.ANSI.RESET}`;this.renderFrame(output);return}const totalRows=Math.ceil(choices.length/this.cols);const currentRow=Math.floor(this.selectedIndex/this.cols);if(currentRow<this.scrollTop){this.scrollTop=currentRow}else if(currentRow>=this.scrollTop+this.pageSize){this.scrollTop=currentRow-this.pageSize+1}if(this.scrollTop>totalRows-1){this.scrollTop=Math.max(0,totalRows-this.pageSize)}const startRow=this.scrollTop;const endRow=Math.min(totalRows,startRow+this.pageSize);for(let r=startRow;r<endRow;r++){let rowStr="";for(let c=0;c<this.cols;c++){const idx=r*this.cols+c;if(idx>=choices.length)break;const choice=choices[idx];let title=choice.title||"";if((0,_utils.stringWidth)(title)>this.colWidth-3){title=title.slice(0,this.colWidth-4)+"…"}let cellContent="";if(idx===this.selectedIndex){cellContent=`${_theme.theme.main}${_symbols.symbols.pointer} ${title}${_ansi.ANSI.RESET}`}else{cellContent=` ${title}`}const currentWidth=(0,_utils.stringWidth)(this.stripAnsi(cellContent));const padding=Math.max(0,this.colWidth-currentWidth);rowStr+=cellContent+" ".repeat(padding)}output+=rowStr+"\n"}if(output.endsWith("\n"))output=output.slice(0,-1);this.renderFrame(output)}handleInput(char){const choices=this.getFilteredChoices();if(char==="\r"||char==="\n"){if(choices.length>0){this.submit(choices[this.selectedIndex].value)}return}if(this.isUp(char)){const newIndex=this.selectedIndex-this.cols;if(newIndex>=0){this.selectedIndex=newIndex}this.render(false);return}if(this.isDown(char)){const newIndex=this.selectedIndex+this.cols;if(newIndex<choices.length){this.selectedIndex=newIndex}this.render(false);return}if(this.isLeft(char)){if(this.selectedIndex>0){this.selectedIndex--}else{this.selectedIndex=choices.length-1}this.render(false);return}if(this.isRight(char)){if(this.selectedIndex<choices.length-1){this.selectedIndex++}else{this.selectedIndex=0}this.render(false);return}if(char==="\b"||char===""){if(this.searchBuffer.length>0){this.searchBuffer=this.searchBuffer.slice(0,-1);this.selectedIndex=0;this.calculateLayout();this.render(false)}return}if(char.length===1&&!/^[\x00-\x1F]/.test(char)&&!char.startsWith("\x1b")){this.searchBuffer+=char;this.selectedIndex=0;this.render(false)}}constructor(options){super(options),_define_property(this,"cols",1),_define_property(this,"colWidth",0);this.calculateLayout()}};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SelectRangePrompt } from './select-range';
|
|
2
|
+
import { SelectRangeOptions } from '../types';
|
|
3
|
+
export declare class MultiRangePrompt<V> extends SelectRangePrompt<V> {
|
|
4
|
+
private committedRanges;
|
|
5
|
+
constructor(options: SelectRangeOptions<V>);
|
|
6
|
+
private mergeRanges;
|
|
7
|
+
protected handleInput(char: string, key?: Buffer): void;
|
|
8
|
+
protected render(_firstRender: boolean): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"MultiRangePrompt",{enumerable:true,get:function(){return MultiRangePrompt}});const _selectrange=require("./select-range");const _theme=require("../theme");const _ansi=require("../ansi");const _symbols=require("../symbols");function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}let MultiRangePrompt=class MultiRangePrompt extends _selectrange.SelectRangePrompt{mergeRanges(){if(this.committedRanges.length===0)return;this.committedRanges.sort((a,b)=>a.start-b.start);const merged=[];let current=this.committedRanges[0];for(let i=1;i<this.committedRanges.length;i++){const next=this.committedRanges[i];if(current.end>=next.start-1){current.end=Math.max(current.end,next.end)}else{merged.push(current);current=next}}merged.push(current);this.committedRanges=merged}handleInput(char,key){if(char==="\r"||char==="\n"){const choices=this.getFilteredChoices();if(choices.length===0)return;if(this.anchorIndex!==null){const start=Math.min(this.anchorIndex,this.selectedIndex);const end=Math.max(this.anchorIndex,this.selectedIndex);this.committedRanges.push({start,end});this.mergeRanges();this.anchorIndex=null}const allIndices=new Set;for(const range of this.committedRanges){for(let i=range.start;i<=range.end;i++){allIndices.add(i)}}if(allIndices.size===0){allIndices.add(this.selectedIndex)}const selectedItems=[];const sortedIndices=Array.from(allIndices).sort((a,b)=>a-b);for(const idx of sortedIndices){if(idx<choices.length){const choice=choices[idx];if(!this.isSeparator(choice)){selectedItems.push(choice.value)}}}this.submit(selectedItems);return}if(char===" "){if(this.anchorIndex===null){this.anchorIndex=this.selectedIndex}else{const start=Math.min(this.anchorIndex,this.selectedIndex);const end=Math.max(this.anchorIndex,this.selectedIndex);this.committedRanges.push({start,end});this.mergeRanges();this.anchorIndex=null}this.render(false);return}super.handleInput(char,key)}render(_firstRender){let output="";const choices=this.getFilteredChoices();if(this.selectedIndex<this.scrollTop){this.scrollTop=this.selectedIndex}else if(this.selectedIndex>=this.scrollTop+this.pageSize){this.scrollTop=this.selectedIndex-this.pageSize+1}if(this.scrollTop>choices.length-1){this.scrollTop=Math.max(0,choices.length-this.pageSize)}const searchStr=this.searchBuffer?` ${_theme.theme.muted}(Filter: ${this.searchBuffer})${_ansi.ANSI.RESET}`:"";output+=`${_theme.theme.success}?${_ansi.ANSI.RESET} ${_ansi.ANSI.BOLD}${_theme.theme.title}${this.options.message}${_ansi.ANSI.RESET}${searchStr}
|
|
2
|
+
`;if(choices.length===0){output+=` ${_theme.theme.muted}No results found${_ansi.ANSI.RESET}`}else{const visibleChoices=choices.slice(this.scrollTop,this.scrollTop+this.pageSize);visibleChoices.forEach((choice,index)=>{const actualIndex=this.scrollTop+index;if(index>0)output+="\n";let isCommitted=false;for(const range of this.committedRanges){if(actualIndex>=range.start&&actualIndex<=range.end){isCommitted=true;break}}let isDragging=false;if(this.anchorIndex!==null){const min=Math.min(this.anchorIndex,this.selectedIndex);const max=Math.max(this.anchorIndex,this.selectedIndex);if(actualIndex>=min&&actualIndex<=max){isDragging=true}}if(this.isSeparator(choice)){output+=` ${_ansi.ANSI.DIM}${choice.text||_symbols.symbols.line.repeat(8)}${_ansi.ANSI.RESET}`}else{let prefix=" ";const title=choice.title;let content=title;if(actualIndex===this.anchorIndex){prefix=`${_theme.theme.muted}> ${_ansi.ANSI.RESET}`}if(actualIndex===this.selectedIndex){prefix=`${_theme.theme.main}${_symbols.symbols.pointer} `}if(actualIndex===this.selectedIndex&&actualIndex===this.anchorIndex){prefix=`${_theme.theme.main}${_symbols.symbols.pointer}>`}if(isCommitted||isDragging){if(actualIndex!==this.selectedIndex&&actualIndex!==this.anchorIndex){prefix=`${_theme.theme.success}* ${_ansi.ANSI.RESET}`}content=`${_theme.theme.success}${title}${_ansi.ANSI.RESET}`;if(isDragging&&!isCommitted){}}if(actualIndex===this.selectedIndex){content=`${_ansi.ANSI.UNDERLINE}${content}${_ansi.ANSI.RESET}`}output+=`${prefix}${content}`}})}output+=`
|
|
3
|
+
${_theme.theme.muted}(Space to anchor/commit, Enter to submit)${_ansi.ANSI.RESET}`;this.renderFrame(output)}constructor(options){super(options),_define_property(this,"committedRanges",[])}};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Prompt } from '../base';
|
|
2
|
+
import { MultiSelectOptions, MouseEvent } from '../types';
|
|
3
|
+
export declare class MultiSelectPrompt<V> extends Prompt<any[], MultiSelectOptions<V>> {
|
|
4
|
+
private selectedIndex;
|
|
5
|
+
private checkedState;
|
|
6
|
+
private searchBuffer;
|
|
7
|
+
private scrollTop;
|
|
8
|
+
private readonly pageSize;
|
|
9
|
+
private errorMsg;
|
|
10
|
+
constructor(options: MultiSelectOptions<V>);
|
|
11
|
+
private getFilteredChoices;
|
|
12
|
+
protected render(_firstRender: boolean): void;
|
|
13
|
+
protected handleInput(char: string): void;
|
|
14
|
+
protected handleMouse(event: MouseEvent): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"MultiSelectPrompt",{enumerable:true,get:function(){return MultiSelectPrompt}});const _ansi=require("../ansi");const _base=require("../base");const _theme=require("../theme");const _symbols=require("../symbols");function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}let MultiSelectPrompt=class MultiSelectPrompt extends _base.Prompt{getFilteredChoices(){if(!this.searchBuffer)return this.options.choices.map((c,i)=>({...c,originalIndex:i}));return this.options.choices.map((c,i)=>({...c,originalIndex:i})).filter(c=>c.title.toLowerCase().includes(this.searchBuffer.toLowerCase()))}render(_firstRender){let output="";const choices=this.getFilteredChoices();if(this.selectedIndex<this.scrollTop){this.scrollTop=this.selectedIndex}else if(this.selectedIndex>=this.scrollTop+this.pageSize){this.scrollTop=this.selectedIndex-this.pageSize+1}if(this.scrollTop>choices.length-1){this.scrollTop=Math.max(0,choices.length-this.pageSize)}const icon=this.errorMsg?`${_theme.theme.error}${_symbols.symbols.cross}`:`${_theme.theme.success}?`;const searchStr=this.searchBuffer?` ${_theme.theme.muted}(Filter: ${this.searchBuffer})${_ansi.ANSI.RESET}`:"";output+=`${icon} ${_ansi.ANSI.BOLD}${_theme.theme.title}${this.options.message}${_ansi.ANSI.RESET}${searchStr}
|
|
2
|
+
`;if(choices.length===0){output+=` ${_theme.theme.muted}No results found${_ansi.ANSI.RESET}`}else{const visible=choices.slice(this.scrollTop,this.scrollTop+this.pageSize);visible.forEach((choice,index)=>{if(index>0)output+="\n";const actualIndex=this.scrollTop+index;const cursor=actualIndex===this.selectedIndex?`${_theme.theme.main}${_symbols.symbols.pointer}${_ansi.ANSI.RESET}`:" ";const isChecked=this.checkedState[choice.originalIndex];const checkbox=isChecked?`${_theme.theme.success}${_symbols.symbols.checked}${_ansi.ANSI.RESET}`:`${_theme.theme.muted}${_symbols.symbols.unchecked}${_ansi.ANSI.RESET}`;output+=`${cursor} ${checkbox} ${choice.title}`})}if(!this.searchBuffer&&!this.errorMsg){output+=`
|
|
3
|
+
${_ansi.ANSI.DIM}(Ctrl+A: All, Ctrl+X: None)${_ansi.ANSI.RESET}`}if(this.errorMsg){output+=`
|
|
4
|
+
${_theme.theme.error}>> ${this.errorMsg}${_ansi.ANSI.RESET}`}this.renderFrame(output)}handleInput(char){const choices=this.getFilteredChoices();if(char==="\r"||char==="\n"){const selectedCount=this.checkedState.filter(Boolean).length;const{min=0,max}=this.options;if(selectedCount<min){this.errorMsg=`Select at least ${min}.`;this.render(false);return}if(max&&selectedCount>max){this.errorMsg=`Max ${max} allowed.`;this.render(false);return}const results=this.options.choices.filter((_,i)=>this.checkedState[i]).map(c=>c.value);this.submit(results);return}if(char==="\x01"){const newCheckedState=[...this.checkedState];let potentialAdd=0;choices.forEach(c=>{if(!newCheckedState[c.originalIndex])potentialAdd++});const currentSelected=newCheckedState.filter(Boolean).length;if(this.options.max&¤tSelected+potentialAdd>this.options.max){this.errorMsg=`Max limit ${this.options.max} reached`}else{choices.forEach(c=>newCheckedState[c.originalIndex]=true);this.checkedState=newCheckedState;this.errorMsg=""}this.render(false);return}if(char==="\x18"){choices.forEach(c=>this.checkedState[c.originalIndex]=false);this.errorMsg="";this.render(false);return}if(char===" "){if(choices.length>0){const choice=choices[this.selectedIndex];const originalIndex=choice.originalIndex;this.checkedState[originalIndex]=!this.checkedState[originalIndex];this.render(false)}return}if(this.isUp(char)){if(choices.length>0){this.selectedIndex=(this.selectedIndex-1+choices.length)%choices.length;this.render(false)}return}if(this.isDown(char)){if(choices.length>0){this.selectedIndex=(this.selectedIndex+1)%choices.length;this.render(false)}return}if(char==="\b"||char===""){if(this.searchBuffer.length>0){this.searchBuffer=this.searchBuffer.slice(0,-1);this.selectedIndex=0;this.render(false)}return}if(!/^[\x00-\x1F]/.test(char)&&!char.startsWith("\x1b")){this.searchBuffer+=char;this.selectedIndex=0;this.render(false)}}handleMouse(event){const choices=this.getFilteredChoices();if(choices.length===0)return;if(event.action==="scroll"){if(event.scroll==="up"){this.selectedIndex=(this.selectedIndex-1+choices.length)%choices.length;this.render(false)}else if(event.scroll==="down"){this.selectedIndex=(this.selectedIndex+1)%choices.length;this.render(false)}}}constructor(options){super(options),_define_property(this,"selectedIndex",0),_define_property(this,"checkedState",void 0),_define_property(this,"searchBuffer",""),_define_property(this,"scrollTop",0),_define_property(this,"pageSize",7),_define_property(this,"errorMsg","");this.checkedState=options.choices.map(c=>!!c.selected);this.selectedIndex=0}};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Prompt } from '../base';
|
|
2
|
+
import { NumberOptions, MouseEvent } from '../types';
|
|
3
|
+
export declare class NumberPrompt extends Prompt<number, NumberOptions> {
|
|
4
|
+
private stringValue;
|
|
5
|
+
private cursor;
|
|
6
|
+
private errorMsg;
|
|
7
|
+
constructor(options: NumberOptions);
|
|
8
|
+
protected render(_firstRender: boolean): void;
|
|
9
|
+
protected handleInput(char: string): void;
|
|
10
|
+
protected handleMouse(event: MouseEvent): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"NumberPrompt",{enumerable:true,get:function(){return NumberPrompt}});const _ansi=require("../ansi");const _base=require("../base");const _theme=require("../theme");const _symbols=require("../symbols");function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}let NumberPrompt=class NumberPrompt extends _base.Prompt{render(_firstRender){const icon=this.errorMsg?`${_theme.theme.error}${_symbols.symbols.cross}`:`${_theme.theme.success}?`;let output=`${icon} ${_ansi.ANSI.BOLD}${_theme.theme.title}${this.options.message}${_ansi.ANSI.RESET} `;output+=`${_theme.theme.main}${this.stringValue}${_ansi.ANSI.RESET}`;if(this.errorMsg){output+=`
|
|
2
|
+
${_theme.theme.error}>> ${this.errorMsg}${_ansi.ANSI.RESET}`}this.renderFrame(output);this.print(_ansi.ANSI.SHOW_CURSOR);if(this.errorMsg){this.print(_ansi.ANSI.UP)}const prefix=`${icon} ${_theme.theme.title}${this.options.message} `;const prefixLen=this.stripAnsi(prefix).length;const targetCol=prefixLen+this.cursor;this.print(_ansi.ANSI.CURSOR_LEFT);if(targetCol>0){this.print(`\x1b[${targetCol}C`)}}handleInput(char){if(char==="\r"||char==="\n"){const num=parseFloat(this.stringValue);if(this.stringValue.trim()===""||isNaN(num)){this.errorMsg="Please enter a valid number.";this.render(false);return}if(this.options.min!==undefined&&num<this.options.min){this.errorMsg=`Minimum value is ${this.options.min}`;this.render(false);return}if(this.options.max!==undefined&&num>this.options.max){this.errorMsg=`Maximum value is ${this.options.max}`;this.render(false);return}this.submit(num);return}if(this.isUp(char)){let num=parseFloat(this.stringValue)||0;num+=this.options.step??1;if(this.options.max!==undefined&&num>this.options.max)num=this.options.max;num=Math.round(num*1e4)/1e4;this.stringValue=num.toString();this.cursor=this.stringValue.length;this.errorMsg="";this.render(false);return}if(this.isDown(char)){let num=parseFloat(this.stringValue)||0;num-=this.options.step??1;if(this.options.min!==undefined&&num<this.options.min)num=this.options.min;num=Math.round(num*1e4)/1e4;this.stringValue=num.toString();this.cursor=this.stringValue.length;this.errorMsg="";this.render(false);return}if(char==="\b"||char===""){if(this.cursor>0){this.stringValue=this.stringValue.slice(0,this.cursor-1)+this.stringValue.slice(this.cursor);this.cursor--;this.errorMsg="";this.render(false)}return}if(this.isLeft(char)){if(this.cursor>0){this.cursor--;this.render(false)}return}if(this.isRight(char)){if(this.cursor<this.stringValue.length){this.cursor++;this.render(false)}return}if(/^[0-9.-]+$/.test(char)){this.stringValue=this.stringValue.slice(0,this.cursor)+char+this.stringValue.slice(this.cursor);this.cursor+=char.length;this.errorMsg="";this.render(false)}}handleMouse(event){if(event.action==="scroll"){let num=parseFloat(this.stringValue)||0;const step=this.options.step??1;if(event.scroll==="up"){num+=step;if(this.options.max!==undefined&&num>this.options.max)num=this.options.max}else if(event.scroll==="down"){num-=step;if(this.options.min!==undefined&&num<this.options.min)num=this.options.min}num=Math.round(num*1e4)/1e4;this.stringValue=num.toString();this.cursor=this.stringValue.length;this.errorMsg="";this.render(false)}}constructor(options){super(options),_define_property(this,"stringValue",""),_define_property(this,"cursor",0),_define_property(this,"errorMsg","");this.stringValue=options.initial!==undefined?options.initial.toString():"";this.cursor=this.stringValue.length}};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Prompt } from '../base';
|
|
2
|
+
import { OTPOptions } from '../types';
|
|
3
|
+
export declare class OTPPrompt extends Prompt<string, OTPOptions> {
|
|
4
|
+
private slots;
|
|
5
|
+
private cursor;
|
|
6
|
+
private readonly length;
|
|
7
|
+
constructor(options: OTPOptions);
|
|
8
|
+
protected render(_firstRender: boolean): void;
|
|
9
|
+
protected handleInput(char: string): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"OTPPrompt",{enumerable:true,get:function(){return OTPPrompt}});const _ansi=require("../ansi");const _base=require("../base");const _theme=require("../theme");function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}let OTPPrompt=class OTPPrompt extends _base.Prompt{render(_firstRender){const mask=this.options.mask||"_";let output=`${_theme.theme.success}?${_ansi.ANSI.RESET} ${_ansi.ANSI.BOLD}${_theme.theme.title}${this.options.message}${_ansi.ANSI.RESET}
|
|
2
|
+
`;output+=" ";for(let i=0;i<this.length;i++){const val=this.slots[i];let charToDisplay=mask;if(val){charToDisplay=this.options.secure?"*":val}else{if(this.options.placeholder&&i<this.options.placeholder.length){charToDisplay=this.options.placeholder[i]}}if(i===this.cursor){output+=`${_ansi.ANSI.REVERSE}${charToDisplay}${_ansi.ANSI.RESET} `}else{if(!val){output+=`${_theme.theme.muted}${charToDisplay}${_ansi.ANSI.RESET} `}else{output+=`${_theme.theme.main}${charToDisplay}${_ansi.ANSI.RESET} `}}}this.renderFrame(output)}handleInput(char){if(/^\d$/.test(char)){this.slots[this.cursor]=char;if(this.cursor===this.length-1){if(this.slots.every(s=>s!=="")){this.render(false);this.submit(this.slots.join(""));return}}this.cursor++;this.render(false);return}if(char==="\b"||char===""){if(this.slots[this.cursor]!==""){this.slots[this.cursor]=""}else if(this.cursor>0){this.cursor--;this.slots[this.cursor]=""}this.render(false);return}if(this.isLeft(char)){if(this.cursor>0){this.cursor--;this.render(false)}return}if(this.isRight(char)){if(this.cursor<this.length-1){this.cursor++;this.render(false)}return}}constructor(options){super(options),_define_property(this,"slots",void 0),_define_property(this,"cursor",0),_define_property(this,"length",void 0);this.length=options.length||6;this.slots=new Array(this.length).fill("")}};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Prompt } from '../base';
|
|
2
|
+
import { PatternOptions, MouseEvent } from '../types';
|
|
3
|
+
export declare class PatternPrompt extends Prompt<number[], PatternOptions> {
|
|
4
|
+
private path;
|
|
5
|
+
private cursor;
|
|
6
|
+
private isDragging;
|
|
7
|
+
private errorMsg;
|
|
8
|
+
private rows;
|
|
9
|
+
private cols;
|
|
10
|
+
private nodeChar;
|
|
11
|
+
private nodeSpacingX;
|
|
12
|
+
private nodeSpacingY;
|
|
13
|
+
private lastMouse;
|
|
14
|
+
constructor(options: PatternOptions);
|
|
15
|
+
private getIndex;
|
|
16
|
+
private getPoint;
|
|
17
|
+
protected render(firstRender: boolean): void;
|
|
18
|
+
private drawLine;
|
|
19
|
+
protected handleInput(char: string, _key: Buffer): void;
|
|
20
|
+
private addToPath;
|
|
21
|
+
protected handleMouse(event: MouseEvent): void;
|
|
22
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"PatternPrompt",{enumerable:true,get:function(){return PatternPrompt}});const _ansi=require("../ansi");const _base=require("../base");const _theme=require("../theme");function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}let PatternPrompt=class PatternPrompt extends _base.Prompt{getIndex(r,c){return r*this.cols+c}getPoint(index){return{r:Math.floor(index/this.cols),c:index%this.cols}}render(firstRender){let output="";const icon=this.errorMsg?`${_theme.theme.error}✖`:`${_theme.theme.success}?`;output+=`${icon} ${_ansi.ANSI.BOLD}${_theme.theme.title}${this.options.message}${_ansi.ANSI.RESET}
|
|
2
|
+
`;if(firstRender){output+=`${_ansi.ANSI.DIM}(Draw pattern with mouse or use Arrows + Space)${_ansi.ANSI.RESET}
|
|
3
|
+
`}const bufferHeight=this.rows*this.nodeSpacingY+1;const bufferWidth=this.cols*this.nodeSpacingX+1;const buffer=Array(bufferHeight).fill(null).map(()=>Array(bufferWidth).fill(" "));for(let i=0;i<this.path.length-1;i++){this.drawLine(buffer,this.path[i],this.path[i+1])}for(let r=0;r<this.rows;r++){for(let c=0;c<this.cols;c++){const index=this.getIndex(r,c);const isSelected=this.path.includes(index);const by=r*this.nodeSpacingY;const bx=c*this.nodeSpacingX;buffer[by][bx]=isSelected?"●":"○"}}const displayHeight=(this.rows-1)*this.nodeSpacingY+1;const displayWidth=(this.cols-1)*this.nodeSpacingX+1;for(let y=0;y<displayHeight;y++){output+=" ";for(let x=0;x<displayWidth;x++){const char=buffer[y][x];const isNodeRow=y%this.nodeSpacingY===0;const isNodeCol=x%this.nodeSpacingX===0;if(isNodeRow&&isNodeCol){const r=y/this.nodeSpacingY;const c=x/this.nodeSpacingX;const idx=this.getIndex(r,c);const isSelected=this.path.includes(idx);const isLast=this.path.length>0&&this.path[this.path.length-1]===idx;const isCursor=this.cursor.r===r&&this.cursor.c===c;let styledChar=this.nodeChar;if(isSelected)styledChar=_theme.theme.main+this.nodeChar+_ansi.ANSI.RESET;if(isLast)styledChar=_theme.theme.success+this.nodeChar+_ansi.ANSI.RESET;if(isCursor){styledChar=_ansi.ANSI.REVERSE+styledChar+_ansi.ANSI.RESET}else if(!isSelected){styledChar=_theme.theme.muted+"○"+_ansi.ANSI.RESET}output+=styledChar}else{if(char!==" "&&char!=="○"&&char!=="●"){output+=_theme.theme.main+char+_ansi.ANSI.RESET}else{output+=" "}}}output+="\n"}if(this.errorMsg){output+=`
|
|
4
|
+
${_theme.theme.error}>> ${this.errorMsg}${_ansi.ANSI.RESET}`}this.renderFrame(output)}drawLine(buffer,fromIdx,toIdx){const p1=this.getPoint(fromIdx);const p2=this.getPoint(toIdx);const y1=p1.r*this.nodeSpacingY;const x1=p1.c*this.nodeSpacingX;const y2=p2.r*this.nodeSpacingY;const x2=p2.c*this.nodeSpacingX;const dy=y2-y1;const dx=x2-x1;const steps=Math.max(Math.abs(dx),Math.abs(dy));if(steps===0)return;const yInc=dy/steps;const xInc=dx/steps;let y=y1;let x=x1;for(let i=0;i<=steps;i++){const ry=Math.round(y);const rx=Math.round(x);if(ry>=0&&ry<buffer.length&&rx>=0&&rx<buffer[0].length){const isNode=ry%this.nodeSpacingY===0&&rx%this.nodeSpacingX===0;if(!isNode){if(dy===0)buffer[ry][rx]="─";else if(dx===0)buffer[ry][rx]="│";else if(dx>0&&dy>0||dx<0&&dy<0)buffer[ry][rx]="╲";else buffer[ry][rx]="╱"}}y+=yInc;x+=xInc}}handleInput(char,_key){if(this.isUp(char)){this.cursor.r=Math.max(0,this.cursor.r-1);this.render(false);return}if(this.isDown(char)){this.cursor.r=Math.min(this.rows-1,this.cursor.r+1);this.render(false);return}if(this.isLeft(char)){this.cursor.c=Math.max(0,this.cursor.c-1);this.render(false);return}if(this.isRight(char)){this.cursor.c=Math.min(this.cols-1,this.cursor.c+1);this.render(false);return}if(char===" "){const index=this.getIndex(this.cursor.r,this.cursor.c);this.addToPath(index);this.render(false);return}if(char==="\r"||char==="\n"){if(this.path.length<2){this.errorMsg="Pattern too short";this.render(false);return}this.submit(this.path);return}if(char===""||char==="\b"){this.path.pop();this.render(false);return}}addToPath(index){if(this.path.includes(index)){return}this.path.push(index)}handleMouse(event){if(event.action==="release"){this.isDragging=false;this.lastMouse=null;if(this.path.length>=2){this.submit(this.path)}return}if(this.lastMouse){const dx=event.x-this.lastMouse.x;const dy=event.y-this.lastMouse.y;if(dx!==0||dy!==0){if(Math.abs(dx)>Math.abs(dy)){if(dx>0)this.cursor.c=Math.min(this.cols-1,this.cursor.c+1);else if(dx<0)this.cursor.c=Math.max(0,this.cursor.c-1)}else{if(dy>0)this.cursor.r=Math.min(this.rows-1,this.cursor.r+1);else if(dy<0)this.cursor.r=Math.max(0,this.cursor.r-1)}if(this.isDragging){const idx=this.getIndex(this.cursor.r,this.cursor.c);this.addToPath(idx)}this.render(false)}}else{if(event.action==="press"&&event.button===0){this.isDragging=true;this.path=[];const idx=this.getIndex(this.cursor.r,this.cursor.c);this.addToPath(idx);this.render(false)}}this.lastMouse={x:event.x,y:event.y}}constructor(options){super(options),_define_property(this,"path",[]),_define_property(this,"cursor",{r:0,c:0}),_define_property(this,"isDragging",false),_define_property(this,"errorMsg",""),_define_property(this,"rows",void 0),_define_property(this,"cols",void 0),_define_property(this,"nodeChar",void 0),_define_property(this,"nodeSpacingX",4),_define_property(this,"nodeSpacingY",2),_define_property(this,"lastMouse",null);this.rows=options.rows||3;this.cols=options.cols||3;this.nodeChar=options.nodeChar||"●"}};
|