amplify-prompts
Advanced tools
Comparing version 1.1.2 to 1.2.0-headless-s3-not-for-production.0
@@ -6,2 +6,13 @@ # Change Log | ||
# [1.2.0-headless-s3-not-for-production.0](https://github.com/aws-amplify/amplify-cli/compare/amplify-prompts@1.1.2...amplify-prompts@1.2.0-headless-s3-not-for-production.0) (2021-09-22) | ||
### Features | ||
* update pick styling, hint text, and ctrl+z listener ([#8167](https://github.com/aws-amplify/amplify-cli/issues/8167)) ([620a36a](https://github.com/aws-amplify/amplify-cli/commit/620a36a8d4596cfd686820a5556431077977db5a)) | ||
## [1.1.2](https://github.com/aws-amplify/amplify-cli/compare/amplify-prompts@1.1.1...amplify-prompts@1.1.2) (2021-09-02) | ||
@@ -8,0 +19,0 @@ |
@@ -6,3 +6,3 @@ "use strict"; | ||
const validators_1 = require("../validators"); | ||
const printResult = (result) => console.log(`Prommpt result was [${result}]`); | ||
const printResult = (result) => console.log(`Prompt result was [${result}]`); | ||
const printTypeofResult = (result) => console.log(`Response type was [${typeof result}]`); | ||
@@ -49,3 +49,3 @@ const demo = async () => { | ||
printer_1.printer.blankLine(); | ||
printer_1.printer.info('prommpter.pick is used to select one or more items fromm a selection set'); | ||
printer_1.printer.info('prompter.pick is used to select one or more items fromm a selection set'); | ||
printer_1.printer.info('It supports autocomplete of choices automatically'); | ||
@@ -90,3 +90,3 @@ const choices1 = ['red', 'yellow', 'green', 'orange', 'purple']; | ||
}; | ||
demo(); | ||
demo().catch(console.error); | ||
//# sourceMappingURL=demo.js.map |
@@ -21,2 +21,5 @@ "use strict"; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -28,2 +31,3 @@ exports.prompter = void 0; | ||
const printer_1 = require("./printer"); | ||
const chalk_1 = __importDefault(require("chalk")); | ||
class AmplifyPrompter { | ||
@@ -117,12 +121,19 @@ constructor(prompter = enquirer_1.prompt, print = printer_1.printer) { | ||
else { | ||
const sigTstpListener = () => process.exit(); | ||
process.once('SIGTSTP', sigTstpListener); | ||
({ result } = await this.prompter({ | ||
actions, | ||
footer: (opts === null || opts === void 0 ? void 0 : opts.returnSize) === 'many' ? '(Use <space> to select, <ctrl + a> to toggle all)' : undefined, | ||
footer: (opts === null || opts === void 0 ? void 0 : opts.returnSize) === 'many' ? chalk_1.default.gray('(Use <space> to select, <ctrl + a> to toggle all)') : undefined, | ||
type: 'autocomplete', | ||
name: 'result', | ||
message, | ||
hint: '(Use arrow keys or type to filter)', | ||
initial: opts === null || opts === void 0 ? void 0 : opts.initial, | ||
multiple: (opts === null || opts === void 0 ? void 0 : opts.returnSize) === 'many', | ||
choices: enquirerChoices, | ||
pointer(_, i) { | ||
return this.state.index === i ? chalk_1.default.cyan('❯') : ' '; | ||
}, | ||
})); | ||
process.removeListener('SIGTSTP', sigTstpListener); | ||
} | ||
@@ -129,0 +140,0 @@ if (Array.isArray(result)) { |
{ | ||
"name": "amplify-prompts", | ||
"version": "1.1.2", | ||
"version": "1.2.0-headless-s3-not-for-production.0", | ||
"description": "Utility functions for Amplify CLI terminal I/O", | ||
@@ -51,3 +51,3 @@ "main": "lib/index.js", | ||
}, | ||
"gitHead": "8738095619ba2bc2f01d381d816fc0f65bb3f88f" | ||
"gitHead": "633fe35382bff0520a342b58bef3647ab07ee8f2" | ||
} |
@@ -5,7 +5,7 @@ import { printer } from '../printer'; | ||
const printResult = (result: any) => console.log(`Prommpt result was [${result}]`); | ||
const printResult = (result: any) => console.log(`Prompt result was [${result}]`); | ||
const printTypeofResult = (result: any) => console.log(`Response type was [${typeof result}]`); | ||
/** | ||
* The following is meant to be a runnable example of functionality offered by amplify-prommpts | ||
* The following is meant to be a runnable example of functionality offered by amplify-prompts | ||
* Run `yarn demo` to see it in action | ||
@@ -80,3 +80,3 @@ */ | ||
printer.blankLine(); | ||
printer.info('prommpter.pick is used to select one or more items fromm a selection set'); | ||
printer.info('prompter.pick is used to select one or more items fromm a selection set'); | ||
printer.info('It supports autocomplete of choices automatically'); | ||
@@ -116,11 +116,7 @@ const choices1 = ['red', 'yellow', 'green', 'orange', 'purple']; | ||
printer.info('A default selection can be specified by providing the index of the option'); | ||
printResult( | ||
await prompter.pick<'one', number>('Pick it again, this time with a default value', choices2, { initial: 2 }), | ||
); | ||
printResult(await prompter.pick<'one', number>('Pick it again, this time with a default value', choices2, { initial: 2 })); | ||
printer.info('Multiple choices can be selected by specifying multiSelect true'); | ||
printer.info('When multiSelect is on, an array of initial indexes can be specified'); | ||
printResult( | ||
await prompter.pick<'many', number>('Pick your favorite colors', choices2, { returnSize: 'many', initial: [1, 2] }), | ||
); | ||
printResult(await prompter.pick<'many', number>('Pick your favorite colors', choices2, { returnSize: 'many', initial: [1, 2] })); | ||
@@ -130,7 +126,5 @@ printer.info('Individual choices can be disabled or have hint text next to them'); | ||
(choices2[2] as any).disabled = true; | ||
printResult( | ||
await prompter.pick<'many', number>('Pick your favorite Skittle color', choices2, { returnSize: 'many' }), | ||
); | ||
printResult(await prompter.pick<'many', number>('Pick your favorite Skittle color', choices2, { returnSize: 'many' })); | ||
}; | ||
demo(); | ||
demo().catch(console.error); |
@@ -9,2 +9,3 @@ import { prompt } from 'enquirer'; | ||
import { printer } from './printer'; | ||
import chalk from 'chalk'; | ||
@@ -93,5 +94,5 @@ /** | ||
} | ||
return (opts.transform(result as string) as unknown) as PromptReturn<RS, T>; | ||
return opts.transform(result as string) as unknown as PromptReturn<RS, T>; | ||
} else { | ||
return (result as unknown) as PromptReturn<RS, T>; | ||
return result as unknown as PromptReturn<RS, T>; | ||
} | ||
@@ -125,3 +126,3 @@ }; | ||
typeof choices[0] === 'string' | ||
? (((choices as string[]).map(choice => ({ name: choice, value: choice })) as unknown) as GenericChoice<T>[]) // this assertion is safe because the choice array can only be a string[] if the generic type is a string | ||
? ((choices as string[]).map(choice => ({ name: choice, value: choice })) as unknown as GenericChoice<T>[]) // this assertion is safe because the choice array can only be a string[] if the generic type is a string | ||
: (choices as GenericChoice<T>[]); | ||
@@ -153,2 +154,6 @@ | ||
} else { | ||
// enquirer does not clear the stdout buffer on TSTP (Ctrl + Z) so this listener maps it to process.exit() which will clear the buffer | ||
// This does mean that the process can't be resumed, but enquirer errors when trying to resume the process anyway because it can't reattach to the TTY buffer | ||
const sigTstpListener = () => process.exit(); | ||
process.once('SIGTSTP', sigTstpListener); | ||
({ result } = await this.prompter<{ result: RS extends 'many' ? string[] : string }>({ | ||
@@ -162,6 +167,7 @@ // actions is not part of the TS interface but it's part of the JS API | ||
// @ts-ignore | ||
footer: opts?.returnSize === 'many' ? '(Use <space> to select, <ctrl + a> to toggle all)' : undefined, | ||
footer: opts?.returnSize === 'many' ? chalk.gray('(Use <space> to select, <ctrl + a> to toggle all)') : undefined, | ||
type: 'autocomplete', | ||
name: 'result', | ||
message, | ||
hint: '(Use arrow keys or type to filter)', | ||
initial: opts?.initial, | ||
@@ -173,3 +179,9 @@ // there is a typo in the .d.ts file for this field -- muliple -> multiple | ||
choices: enquirerChoices, | ||
pointer(_: unknown, i: number) { | ||
// this.state is bound to a property of enquirer's prompt object, it does not reference a property of AmplifyPrompter | ||
return this.state.index === i ? chalk.cyan('❯') : ' '; | ||
}, | ||
})); | ||
// remove the TSTP listener | ||
process.removeListener('SIGTSTP', sigTstpListener); | ||
} | ||
@@ -176,0 +188,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
151091
1219
1