source: trip-planner-front/node_modules/external-editor/example_async.js@ fa375fe

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

initial commit

  • Property mode set to 100644
File size: 1.1 KB
RevLine 
[6a3a178]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 rl.pause();
18 editor.runAsync(function (error, response)
19 {
20 if (error) {
21 process.stdout.write(error.message);
22 process.exit(1);
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 rl.resume();
28 } else {
29 process.stdout.write('Your Message:\n');
30 process.stdout.write(response);
31 process.stdout.write('\n');
32 rl.close();
33 }
34 });
35 } catch (err) {
36 process.stderr.write(err.message);
37 process.stdout.write('\n');
38 rl.close();
39 }
40});
Note: See TracBrowser for help on using the repository browser.