UI for Zipcoin Blue

environment.js 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const tslib_1 = require("tslib");
  4. const chalk_1 = require("chalk");
  5. class Environment {
  6. constructor({ bottomBar, client, config, daemon, events, flags, hooks, log, meta, namespace, plugins, project, prompt, session, shell, tasks, telemetry, }) {
  7. this.bottomBar = bottomBar;
  8. this.client = client;
  9. this.config = config;
  10. this.daemon = daemon;
  11. this.events = events;
  12. this.flags = flags;
  13. this.hooks = hooks;
  14. this.log = log;
  15. this.meta = meta;
  16. this.namespace = namespace;
  17. this.plugins = plugins;
  18. this.project = project;
  19. this.prompt = prompt;
  20. this.session = session;
  21. this.shell = shell;
  22. this.tasks = tasks;
  23. this.telemetry = telemetry;
  24. }
  25. load(p) {
  26. return require(p);
  27. }
  28. open() {
  29. return tslib_1.__awaiter(this, void 0, void 0, function* () {
  30. if (this.flags.interactive) {
  31. if (!this.bottomBar) {
  32. const inquirer = require('inquirer');
  33. this.bottomBar = new inquirer.ui.BottomBar();
  34. }
  35. try {
  36. // the mute() call appears to be necessary, otherwise when answering
  37. // inquirer prompts upon pressing enter, a copy of the prompt is
  38. // printed to the screen and looks gross
  39. const bottomBarHack = this.bottomBar;
  40. bottomBarHack.rl.output.mute();
  41. }
  42. catch (e) {
  43. console.error('EXCEPTION DURING BOTTOMBAR OUTPUT MUTE', e);
  44. }
  45. }
  46. this.log.stream = typeof this.bottomBar === 'undefined' ? process.stdout : this.bottomBar.log;
  47. });
  48. }
  49. close() {
  50. return tslib_1.__awaiter(this, void 0, void 0, function* () {
  51. this.tasks.cleanup();
  52. // instantiating inquirer.ui.BottomBar hangs, so when close() is called,
  53. // we close BottomBar streams and replace the log stream with stdout.
  54. // This means inquirer shouldn't be used after command execution finishes
  55. // (which could happen during long-running processes like serve).
  56. if (this.bottomBar) {
  57. this.bottomBar.close();
  58. this.bottomBar = undefined;
  59. this.log.stream = process.stdout;
  60. }
  61. });
  62. }
  63. runCommand(pargv, opts = {}) {
  64. return tslib_1.__awaiter(this, void 0, void 0, function* () {
  65. if (typeof opts.showExecution === 'undefined') {
  66. opts.showExecution = true;
  67. }
  68. if (opts.showExecution) {
  69. this.log.msg(`> ${chalk_1.default.green([this.namespace.name, ...pargv].map(a => a.includes(' ') ? `"${a}"` : a).join(' '))}`);
  70. }
  71. yield this.namespace.runCommand(this, pargv);
  72. });
  73. }
  74. }
  75. exports.Environment = Environment;