Socket
Socket
Sign inDemoInstall

enquirer-prompt-editor

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

enquirer-prompt-editor - npm Package Compare versions

Comparing version 1.1.0 to 2.0.0

31

index.d.ts
import { Prompt } from 'enquirer';
// Copy/paste since enquirer doesn't really have usable typings...
interface BasePromptOptions {
name: string | (() => string);
type: string | (() => string);
message: string | (() => string) | (() => Promise<string>);
initial?: any;
required?: boolean;
format?(value: string): string | Promise<string>;
result?(value: string): string | Promise<string>;
skip?: ((state: object) => boolean | Promise<boolean>) | boolean;
validate?(
value: string
): boolean | Promise<boolean> | string | Promise<string>;
onSubmit?(
name: string,
value: any,
prompt: Enquirer.Prompt
): boolean | Promise<boolean>;
onCancel?(
name: string,
value: any,
prompt: Enquirer.Prompt
): boolean | Promise<boolean>;
stdin?: NodeJS.ReadStream;
stdout?: NodeJS.WriteStream;
}
declare const EditorPrompt: Prompt;
export = EditorPrompt;
export interface EditorPromptOptions extends BasePromptOptions {
extensions: string;
}

37

index.js
const { Prompt } = require('enquirer');
const { editAsync } = require('external-editor');
const { edit } = require('edit-briefly');

@@ -7,4 +7,17 @@ class Editor extends Prompt {

super(options);
this.value = options.initial || '';
this.cursorHide();
}
async keypress(input, event = {}) {
/**
* Whitelist only certain key events.
* This prevents accidental submits, when `return` is pressed.
*/
if (!['cancel'].includes(event.name)) {
return;
}
await super.keypress(input, event);
}
async hint() {

@@ -38,2 +51,12 @@ const message = this.state.cancelled

/**
* Call this as a side effect, otherwhise we'll end in a endless loop
* of submits if validation fails.
*
* submit -> invalid -> render -> ...
*/
this.openEditor();
}
async openEditor() {
if (this.state.submitted) {

@@ -43,10 +66,8 @@ return;

editAsync(this.value, async (err, text) => {
if (err) {
await this.cancel(err);
} else {
this.value = text;
await this.submit();
}
const text = await edit({
contents: this.value,
extension: this.options.extension || '',
});
this.value = text;
await this.submit();
}

@@ -53,0 +74,0 @@ }

{
"name": "enquirer-prompt-editor",
"version": "1.1.0",
"description": "Opens your text editor and waits for you to save your input during a prompt.",
"version": "2.0.0",
"description": "Use your text editor as prompt input.",
"license": "MIT",
"author": "Sebastian Sebald (https://github.com/sebald)",
"repository": "sebald/enquirer-prompt-editor",
"bugs": {
"url": "https://github.com/sebald/enquirer-prompt-editor/issues"
},
"keywords": [

@@ -29,4 +26,4 @@ "cli",

"dependencies": {
"enquirer": "^2.3.0",
"external-editor": "^3.0.3"
"edit-briefly": "^1.0.0",
"enquirer": "^2.3.0"
},

@@ -33,0 +30,0 @@ "scripts": {

@@ -23,2 +23,3 @@ # enquirer-prompt-editor

message: 'Please write a short bio of at least 3 lines.',
extension: 'md',
validate: text => {

@@ -31,3 +32,4 @@ if (text.split('\n').length < 2) {

})
.then(answers => console.log(answers));
.then(answers => console.log(answers))
.catch(err => console.log(err));
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc