-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
357 additions
and
326 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
/node_modules | ||
/demo | ||
yarn.lock | ||
package-lock.json | ||
package-lock.json | ||
example/ts-demo/node_modules | ||
.idea |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import inquirer from "inquirer"; | ||
import PromptConstructor = inquirer.prompts.PromptConstructor; | ||
declare const InterruptedPrompt: { | ||
EVENT_INTERRUPTED: string; | ||
from: (promptBase: PromptConstructor) => PromptConstructor; | ||
/** | ||
* @deprecated | ||
*/ | ||
replaceAllDefaults: (inquirer: any) => void; | ||
fromAll: (inquirer: any) => void; | ||
}; | ||
export default InterruptedPrompt; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import observe from "inquirer/lib/utils/events.js"; | ||
const rejectIfInterrupted = (event, hotkey, reject) => { | ||
let isReject = false; | ||
if (hotkey) { | ||
const hotkeys = hotkey.split('+'); | ||
if (hotkeys.length === 2) { | ||
const [specKey, key] = hotkeys; | ||
isReject = event.key[specKey] && event.key.name === key; | ||
} | ||
else { | ||
if (event.key.name === hotkey) | ||
isReject = true; | ||
} | ||
} | ||
if (isReject) { | ||
reject(InterruptedPrompt.EVENT_INTERRUPTED); | ||
} | ||
}; | ||
/** | ||
* Create an interrupted prompt from any Prompt from inquirer or its plugins | ||
*/ | ||
const from = (promptBase) => { | ||
class InterruptedPrompt extends promptBase { | ||
run() { | ||
const interruptedKeyName = this['opt'].interruptedKeyName || this['opt'].interruptedKeyname || 'escape'; | ||
return new Promise((resolve, reject) => { | ||
const events = observe(this['rl']); | ||
events.keypress.pipe().forEach(e => rejectIfInterrupted(e, interruptedKeyName, reject)); | ||
super.run().then(resolve, reject); | ||
}); | ||
} | ||
} | ||
return InterruptedPrompt; | ||
}; | ||
/** | ||
* Override all default inquirer prompts to interrupted prompts | ||
*/ | ||
const replaceAllDefaults = (inquirer) => { | ||
Object.keys(inquirer.prompt.prompts).forEach((key) => { | ||
inquirer.prompt.prompts[key] = InterruptedPrompt.from(inquirer.prompt.prompts[key]); | ||
}); | ||
}; | ||
const InterruptedPrompt = { | ||
EVENT_INTERRUPTED: 'EVENT_INTERRUPTED', | ||
from, | ||
/** | ||
* @deprecated | ||
*/ | ||
replaceAllDefaults, | ||
fromAll: replaceAllDefaults | ||
}; | ||
export default InterruptedPrompt; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "ts-demo", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"type": "module", | ||
"compilerOptions": { | ||
"moduleResolution": "node" | ||
}, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"start": "tsc && node ./dist/index.js" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"@types/node": "^18.15.11", | ||
"@types/inquirer": "^9.0.3", | ||
"ts-node": "^10.9.1", | ||
"tsconfig-paths": "^4.1.2", | ||
"typescript": "^5.0.2" | ||
}, | ||
"dependencies": { | ||
"inquirer": "^9.1.5", | ||
"inquirer-file-tree-selection-prompt": "^2.0.5" | ||
} | ||
} |
Oops, something went wrong.