Last change
on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Rev | Line | |
---|
[6a3a178] | 1 | var ExternalEditor = require('./main').ExternalEditor;
|
---|
| 2 | var readline = require('readline');
|
---|
| 3 |
|
---|
| 4 | var rl = readline.createInterface({
|
---|
| 5 | input: process.stdin,
|
---|
| 6 | output: null
|
---|
| 7 | });
|
---|
| 8 |
|
---|
| 9 | var message = '\n\n# Please Write a message\n# Any line starting with # is ignored';
|
---|
| 10 |
|
---|
| 11 | process.stdout.write('Please write a message. (press enter to launch your preferred editor)');
|
---|
| 12 |
|
---|
| 13 | editor = new ExternalEditor(message);
|
---|
| 14 |
|
---|
| 15 | rl.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.