Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

example_sync.js 1.2KB

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