termux.js 797 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. 'use strict';
  2. const execa = require('execa');
  3. const handler = error => {
  4. if (error.code === 'ENOENT') {
  5. throw new Error('Couldn\'t find the termux-api scripts. You can install them with: apt install termux-api');
  6. }
  7. throw error;
  8. };
  9. module.exports = {
  10. copy: async options => {
  11. try {
  12. await execa('termux-clipboard-set', options);
  13. } catch (error) {
  14. handler(error);
  15. }
  16. },
  17. paste: async options => {
  18. try {
  19. return await execa.stdout('termux-clipboard-get', options);
  20. } catch (error) {
  21. handler(error);
  22. }
  23. },
  24. copySync: options => {
  25. try {
  26. execa.sync('termux-clipboard-set', options);
  27. } catch (error) {
  28. handler(error);
  29. }
  30. },
  31. pasteSync: options => {
  32. try {
  33. return execa.sync('termux-clipboard-get', options);
  34. } catch (error) {
  35. handler(error);
  36. }
  37. }
  38. };