multiplex.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #!/usr/bin/env node
  2. /**
  3. * multiplex.js
  4. * https://github.com/chjj/blessed
  5. * Copyright (c) 2013-2015, Christopher Jeffrey (MIT License)
  6. * A terminal multiplexer created by blessed.
  7. */
  8. process.title = 'multiplex.js';
  9. var blessed = require('blessed')
  10. , screen;
  11. screen = blessed.screen({
  12. smartCSR: true,
  13. log: process.env.HOME + '/blessed-terminal.log',
  14. fullUnicode: true,
  15. dockBorders: true,
  16. ignoreDockContrast: true
  17. });
  18. var topleft = blessed.terminal({
  19. parent: screen,
  20. cursor: 'line',
  21. cursorBlink: true,
  22. screenKeys: false,
  23. label: ' multiplex.js ',
  24. left: 0,
  25. top: 0,
  26. width: '50%',
  27. height: '50%',
  28. border: 'line',
  29. style: {
  30. fg: 'default',
  31. bg: 'default',
  32. focus: {
  33. border: {
  34. fg: 'green'
  35. }
  36. }
  37. }
  38. });
  39. topleft.pty.on('data', function(data) {
  40. screen.log(JSON.stringify(data));
  41. });
  42. var topright = blessed.terminal({
  43. parent: screen,
  44. cursor: 'block',
  45. cursorBlink: true,
  46. screenKeys: false,
  47. label: ' multiplex.js ',
  48. left: '50%-1',
  49. top: 0,
  50. width: '50%+1',
  51. height: '50%',
  52. border: 'line',
  53. style: {
  54. fg: 'red',
  55. bg: 'black',
  56. focus: {
  57. border: {
  58. fg: 'green'
  59. }
  60. }
  61. }
  62. });
  63. var bottomleft = blessed.terminal({
  64. parent: screen,
  65. cursor: 'block',
  66. cursorBlink: true,
  67. screenKeys: false,
  68. label: ' multiplex.js ',
  69. left: 0,
  70. top: '50%-1',
  71. width: '50%',
  72. height: '50%+1',
  73. border: 'line',
  74. style: {
  75. fg: 'default',
  76. bg: 'default',
  77. focus: {
  78. border: {
  79. fg: 'green'
  80. }
  81. }
  82. }
  83. });
  84. var bottomright = blessed.terminal({
  85. parent: screen,
  86. cursor: 'block',
  87. cursorBlink: true,
  88. screenKeys: false,
  89. label: ' multiplex.js ',
  90. left: '50%-1',
  91. top: '50%-1',
  92. width: '50%+1',
  93. height: '50%+1',
  94. border: 'line',
  95. style: {
  96. fg: 'default',
  97. bg: 'default',
  98. focus: {
  99. border: {
  100. fg: 'green'
  101. }
  102. }
  103. }
  104. });
  105. [topleft, topright, bottomleft, bottomright].forEach(function(term) {
  106. term.enableDrag(function(mouse) {
  107. return !!mouse.ctrl;
  108. });
  109. term.on('title', function(title) {
  110. screen.title = title;
  111. term.setLabel(' ' + title + ' ');
  112. screen.render();
  113. });
  114. term.on('click', term.focus.bind(term));
  115. });
  116. topleft.focus();
  117. screen.key('C-q', function() {
  118. topleft.kill();
  119. topright.kill();
  120. bottomleft.kill();
  121. bottomright.kill();
  122. return screen.destroy();
  123. });
  124. screen.program.key('S-tab', function() {
  125. screen.focusNext();
  126. screen.render();
  127. });
  128. screen.render();