UNPKG

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