source: trip-planner-front/node_modules/external-editor/example_sync.js@ bdd6491

Last change on this file since bdd6491 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.2 KB
Line 
1var ExternalEditor = require('./main').ExternalEditor;
2var readline = require('readline');
3
4var rl = readline.createInterface({
5 input: process.stdin,
6 output: null
7});
8
9var message = '\n\n# Please Write a message\n# Any line starting with # is ignored';
10
11process.stdout.write('Please write a message. (press enter to launch your preferred editor)');
12
13editor = new ExternalEditor(message);
14
15rl.on('line', function () {
16 try {
17 // Get response, remove all lines starting with #, remove any trailing newlines.
18 var response = editor.run().replace(/^#.*\n?/gm, '').replace(/\n+$/g, '').trim();
19
20 if (editor.lastExitStatus !== 0) {
21 process.stderr.write("WARN: The editor exited with a non-zero status\n\n")
22 }
23
24 if (response.length === 0) {
25 readline.moveCursor(process.stdout, 0, -1);
26 process.stdout.write('Your message was empty, please try again. (press enter to launch your preferred editor)');
27 } else {
28 process.stdout.write('Your Message:\n');
29 process.stdout.write(response);
30 process.stdout.write('\n');
31 rl.close();
32 }
33 } catch (err) {
34 process.stderr.write(err.message);
35 process.stdout.write('\n');
36 rl.close();
37 }
38});
Note: See TracBrowser for help on using the repository browser.