plugin.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. 'use strict';
  4. import {
  5. TerminalWidget
  6. } from './index';
  7. import {
  8. Application
  9. } from 'phosphide/lib/core/application';
  10. import {
  11. TabPanel
  12. } from 'phosphor-tabs';
  13. /**
  14. * The default terminal extension.
  15. */
  16. export
  17. const terminalExtension = {
  18. id: 'jupyter.extensions.terminal',
  19. activate: activateTerminal
  20. };
  21. function activateTerminal(app: Application): Promise<void> {
  22. let newTerminalId = 'terminal:create-new';
  23. app.commands.add([{
  24. id: newTerminalId,
  25. handler: () => {
  26. let term = new TerminalWidget();
  27. term.color = 'black';
  28. term.background = 'white';
  29. term.title.closable = true;
  30. app.shell.addToMainArea(term);
  31. let stack = term.parent;
  32. if (!stack) {
  33. return;
  34. }
  35. let tabs = stack.parent;
  36. if (tabs instanceof TabPanel) {
  37. tabs.currentWidget = term;
  38. }
  39. }
  40. }]);
  41. app.palette.add([
  42. {
  43. command: newTerminalId,
  44. category: 'Terminal',
  45. text: 'New Terminal',
  46. caption: 'Start a new terminal session'
  47. }
  48. ]);
  49. return Promise.resolve(void 0);
  50. }