forked from edhuardotierrez/hyper-quickssh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
661 lines (569 loc) · 45.7 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
'use strict';
const { shell, app } = require('electron');
let { exec } = require('child_process');
const color = require('color');
const fs = require('fs');
const path = require('path');
const fuzzy = require('fuzzy');
const DEBUG = process.env.NODE_ENV === 'development' || process.env.DEBUG || false;
const isMac = process.platform === 'darwin';
let log = require('electron-log');
const CHAR_CODE_1 = 161;
const CHAR_CODE_2 = 8482;
const CHAR_CODE_3 = 163;
const QUICK_SELECT_CHAR_CODE = [CHAR_CODE_1, CHAR_CODE_2, CHAR_CODE_3];
// default icons and colors
const QUICKSSH_ICONS = [ "default", "bug", "cpu", "cycle", "data", "image", "king", "load", "mail", "net", "rain", "spring" ];
const QUICKSSH_COLORS = [ "#50E3C2", "#B8E986", "#4A90E2", "#FF864C", "#D764EF", "#7ED321", "#54D3FF", "#54D3FF" ];
const QUICKSSH_CONFIG_FILE = "hyper-quickssh-config.json";
let reactHistoryNav;
let allTerminals = {};
let currTerminal;
let currFocusedUid;
let currPid = '';
let currUserInputData = '';
let lastKeyCodeTerminal = -1;
let currCwd = '/';
let quicksshEntries = [];
let supressMode = false;
let visor;
let visibleQuickComponent = false;
const navigation = {
keys: {
up: 38,
down: 40
}
};
const LEAD_KEY = process.platform === 'darwin' ? 'Cmd' : 'Ctrl';
exports.decorateMenu = (menu) =>
menu.map(
item => {
if (item.label !== 'Plugins') return item;
const newItem = Object.assign({}, item);
newItem.submenu = newItem.submenu.concat(
{
label: 'Quick SSH',
type: 'submenu',
submenu:[
{
label: 'Show/Hide List',
accelerator: `${LEAD_KEY}+O`,
click: (clickedItem, focusedWindow) => {
if (focusedWindow !== null) {
focusedWindow.rpc.emit('hyper-quickssh:open:window', { focusedWindow });
}
}
},
{
label: 'Open Config',
click: (clickedItem, focusedWindow) => {
if (focusedWindow !== null) {
focusedWindow.rpc.emit('hyper-quickssh:open:config', { focusedWindow });
}
}
}
],
});
return newItem;
}
);
exports.decorateConfig = (config) => {
const colorForeground = color(config.foregroundColor);
const colorBackground = color(config.backgroundColor);
const colorDefault = color(QUICKSSH_COLORS[0]);
// Define default colors
const configColors = Object.assign({
black: '#000000',
red: '#ff0000',
green: '#33ff00',
yellow: '#ffff00',
blue: '#0066ff',
magenta: '#cc00ff',
cyan: '#00ffff',
white: '#d0d0d0',
lightBlack: '#808080',
lightRed: '#ff0000',
lightGreen: '#33ff00',
lightYellow: '#ffff00',
lightBlue: '#0066ff',
lightMagenta: '#cc00ff',
lightCyan: '#00ffff',
lightWhite: '#ffffff',
}, config.colors);
// change colors
const isDark = colorBackground.dark();
const colors = {
default: colorDefault.string(),
foreground: colorForeground.string(),
background: colorBackground.string(),
backgroundDarked: colorBackground.darken(0.3).string(),
backgroundLighted: colorBackground.lighten(0.2).string(),
highlight: isDark ? colorBackground.lighten(0.31).string() : colorBackground.darken(0.09).string(),
highlightier: isDark ? colorBackground.lighten(0.43).string() : colorBackground.darken(0.09).string(),
inactive: isDark ? colorBackground.desaturate(0.3).lightness(36).string() : colorBackground.desaturate(0.3).lightness(58).string(),
back: isDark ? colorBackground.darken(0.2).string() : colorBackground.darken(0.05).string(),
command: color(configColors.white).desaturate(0.3).darken(0.2).string()
};
const hyperQuickSSH = Object.assign({
activityColor: configColors.lightCyan,
fontFamily: '"SF UI Text", "Helvetica Neue", "Open Sans", sans-serif'
}, config.hyperQuickSSH);
///*
return Object.assign({}, config, {
css: `
${config.css || ''}
.hyper-quickssh {
font-family: ${hyperQuickSSH.fontFamily};
display: block;
position: fixed;
z-index: 200;
top: 0px;
bottom: 0px;
right: 0px;
width: 40%;
min-width: 200px;
max-width: 480px;
pointer-events: none;
box-shadow: -6px 0px 20px rgba(0, 0, 0, 0.2);
color: ${hyperQuickSSH.activityColor};
background-color: ${colors.background || '#000'};
animation: animationFrames cubic-bezier(0.11, 1.03, 0.36, 1) 200ms;
}
@keyframes animationFrames{
0% { transform: translate(100%,0px); }
100% { transform: translate(0px,0px); }
}
.hyper-quickssh.hidden{
display: none;
}
.hyper-quickssh-list {
pointer-events: initial;
bottom: 0;
width: 100%;
height: 99%;
overflow: hidden;
overflow-y: auto;
padding: 20px 0 60px 0;
margin-bottom: 0px;
}
.hyper-quickssh-list__item{
display: table;
width: 100%;
opacity: 1.0;
padding: 10px 20px;
margin: 4px 0;
transition: background 150ms ease;
}
.hyper-quickssh-list__item:hover,
.hyper-quickssh-list__item:focus,
.hyper-quickssh-list__item.active{
background: ${colors.backgroundDarked};
}
.hyper-quickssh-list__item:hover .hyper-quickssh__icon:before,
.hyper-quickssh-list__item:focus .hyper-quickssh__icon:before{
}
.hyper-quickssh__info{ display: table-cell; vertical-align: top; padding: 3px 0 3px 0; }
.hyper-quickssh__item_title{
font-size: 14px; font-weight: 600; text-transform: uppercase; color: ${configColors.lightWhite}; margin: 0 0 6px 0;
}
.hyper-quickssh__item_cmd{
font-size: 12px; color: ${colors.command};
max-width: 300px;
}
.item_clickable{ cursor: pointer; }
.hyper-quickssh__avatar{ display: table-cell; width: 80px; vertical-align: top; position: relative; }
.hyper-quickssh__icon {
position: relative;
width: 60px;
height: 60px;
border-radius: 20px;
transition: transform 150ms ease, background 150ms ease;
}
.hyper-quickssh__icon:before {
content: '';
position: absolute;
width: 100%;
height: 100%;
left: 0; right: 0; top: 0; bottom: 0;
background-color: ${colors.background};
-webkit-mask-image: url('data:image/svg+xml;utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 32 14"><g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><polygon id="default" fill="#000000" points="26 0 24 0 29 6 3 6 8 0 6 0 0 7 6 14 8 14 3 8 29 8 24 14 26 14 32 7"/></g></svg>');
-webkit-mask-repeat: no-repeat;
-webkit-mask-size: 30px;
-webkit-mask-position: center;
transition: transform 150ms ease, background 150ms ease;
}
.hyper-quickssh__icon.i_bug:before{
-webkit-mask-image: url('data:image/svg+xml;utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 32 32"><g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><path d="M32,20 L28,20 C28,21.5000075 27.7083362,22.9791594 27.125,24.4375 L30,26.1875 L29,28 L26.1875,26.3125 C25.8958319,26.7291688 25.583335,27.1666644 25.25,27.625 C22.8333213,30.5416812 19.7500187,32 16,32 C15.33333,32 14.6458369,31.9375006 13.9375,31.8125 C10.4374825,31.1874969 7.72917625,29.3541819 5.8125,26.3125 L3,28 L2,26.1875 L4.875,24.4375 C4.29166375,23.0208263 4,21.5416744 4,20 L0,20 L0,18 L4.1875,18 C4.43750125,16.6249931 4.93749625,15.2916731 5.6875,14 L2,11.8125 L3,10 L6.875,12.3125 C8.75000937,10.1041556 11.2291513,8.7500025 14.3125,8.25 L10,1 L11.6875,0 L16,7.3125 L20.3125,0 L22,1 L17.75,8.1875 C20.7083481,8.64583563 23.1666569,10.0208219 25.125,12.3125 L29,10 L30,11.8125 L26.3125,14 C27.0625037,15.2500062 27.5624988,16.5833263 27.8125,18 L32,18 L32,20 Z M16,10 C12.7499837,10.0416669 10.1041769,11.3749869 8.0625,14 L23.9375,14 C21.93749,11.4166538 19.2916831,10.0833337 16,10 Z M16,30 C18.333345,30 20.3958244,29.2708406 22.1875,27.8125 C24.7291794,25.81249 26,23.2083494 26,20 C26,18.66666 25.7083362,17.33334 25.125,16 L6.875,16 C6.29166375,17.2916731 6,18.6249931 6,20 C6,22.2916781 6.72915938,24.3541575 8.1875,26.1875 C10.18751,28.7291794 12.7916506,30 16,30 Z" id="i_bug" fill="%23293340"></path></g></svg>');
}
.hyper-quickssh__icon.i_cpu:before{
-webkit-mask-image: url('data:image/svg+xml;utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 33 32"><g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><path d="M32.869231,8 L28.869231,8 L28.869231,12 L32.869231,12 L32.869231,14 L28.869231,14 L28.869231,18 L32.869231,18 L32.869231,20 L28.869231,20 L28.869231,24 L32.869231,24 L32.869231,26 L28.869231,26 L28.869231,28 L26.869231,28 L26.869231,32 L24.869231,32 L24.869231,28 L20.869231,28 L20.869231,32 L18.869231,32 L18.869231,28 L14.869231,28 L14.869231,32 L12.869231,32 L12.869231,28 L8.86923096,28 L8.86923096,32 L6.86923096,32 L6.86923096,28 L4.86923096,28 L4.86923096,26 L0.869230956,26 L0.869230956,24 L4.86923096,24 L4.86923096,20 L0.869230956,20 L0.869230956,18 L4.86923096,18 L4.86923096,14 L0.869230956,14 L0.869230956,12 L4.86923096,12 L4.86923096,8 L0.869230956,8 L0.869230956,6 L4.86923096,6 L4.86923096,4 L6.86923096,4 L6.86923096,0 L8.86923096,0 L8.86923096,4 L12.869231,4 L12.869231,0 L14.869231,0 L14.869231,4 L18.869231,4 L18.869231,0 L20.869231,0 L20.869231,4 L24.869231,4 L24.869231,0 L26.869231,0 L26.869231,4 L28.869231,4 L28.869231,6 L32.869231,6 L32.869231,8 Z M26.869231,6 L6.86923096,6 L6.86923096,26 L26.869231,26 L26.869231,6 Z" id="i_cpu" fill="#000000"></path></g></svg>');
}
.hyper-quickssh__icon.i_spring:before{
-webkit-mask-image: url('data:image/svg+xml;utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 29 28"><g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><path d="M5.86923096,6.25 C9.03591346,3.16665125 14.8483553,1.31250312 23.306731,0.6875 L28.869231,0.5 L28.681731,3.25 C27.7233928,13.7500525 25.8484116,20.3541531 23.056731,23.0625 C21.2233885,24.8541756 19.0775766,25.8541656 16.619231,26.0625 C12.952546,26.395835 9.64007908,25.1250144 6.68173096,22.25 L6.43173096,22 C6.34839721,21.8749994 6.28589783,21.7916669 6.24423096,21.75 C5.82756221,22.3333362 5.39006658,22.9791631 4.93173096,23.6875 L2.55673096,27.6875 C2.05672846,28.020835 1.57756658,28.020835 1.11923096,27.6875 C0.744229081,27.2291644 0.744229081,26.7708356 1.11923096,26.3125 L1.55673096,25.5 C1.84839908,24.9583306 2.31714439,24.1770884 2.96298096,23.15625 C3.60881752,22.1354116 4.26506096,21.1458381 4.93173096,20.1875 C4.01505971,18.8958269 3.36923283,17.5000075 2.99423096,16 C2.07755971,12.2499813 3.03588346,9.00001375 5.86923096,6.25 Z M21.619231,21.6875 C23.5359072,19.7291569 25.0358922,15.3958669 26.119231,8.6875 L26.869231,2.375 L25.494231,2.3125 C24.5358928,2.27083313 23.2963219,2.31249938 21.775481,2.4375 C20.25464,2.56250062 18.6400728,2.78124844 16.931731,3.09375 C15.2233891,3.40625156 13.4838231,3.94791281 11.712981,4.71875 C9.94213877,5.48958719 8.45257033,6.4583275 7.24423096,7.625 C6.99422971,7.87500125 6.74423221,8.14583188 6.49423096,8.4375 C3.86921783,11.6458494 3.76505221,15.0416488 6.18173096,18.625 C7.05673533,17.5833281 7.76506158,16.8125025 8.30673096,16.3125 C10.1400735,14.5208244 12.2025528,13.0000062 14.494231,11.75 L17.244231,10.5 C17.7025666,10.1249981 18.1817285,10.1249981 18.681731,10.5 C19.0567328,10.9583356 19.0567328,11.4166644 18.681731,11.875 L17.369231,12.375 C16.5358935,12.708335 15.3692385,13.374995 13.869231,14.375 C12.3692235,15.375005 10.952571,16.5208269 9.61923096,17.8125 C8.78589346,18.6458375 8.07756721,19.4374963 7.49423096,20.1875 C7.53589783,20.2708337 7.61923033,20.3749994 7.74423096,20.5 C7.91089846,20.6666675 8.01506408,20.7916663 8.05673096,20.875 C9.14006971,21.9166719 10.2650585,22.7499969 11.431731,23.375 C15.098416,25.2500094 18.4942153,24.687515 21.619231,21.6875 Z" id="i_spring" fill="#000000"></path></g></svg>');
}
.hyper-quickssh__icon.i_rain:before{
-webkit-mask-image: url('data:image/svg+xml;utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 33 32"><g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><path d="M24.994231,5.1875 C26.4942385,5.43750125 27.8900578,6.04166188 29.181731,7 C31.6400766,8.91667625 32.869231,11.4166513 32.869231,14.5 C32.869231,16.166675 32.4317353,17.7499925 31.556731,19.25 C30.0567235,21.8333462 27.8275791,23.3749975 24.869231,23.875 L24.869231,21.875 C25.869236,21.6666656 26.7650603,21.2708362 27.556731,20.6875 C29.7650753,19.1874925 30.869231,17.1250131 30.869231,14.5 C30.869231,13.0416594 30.4525685,11.6666731 29.619231,10.375 C28.2025572,8.2083225 26.1817441,7.08333375 23.556731,7 C23.3483966,6.37499687 23.077566,5.77083625 22.744231,5.1875 C21.3275572,3.06248938 19.3692435,2 16.869231,2 C15.7442253,2 14.6609028,2.27083063 13.619231,2.8125 C11.4942203,3.93750563 10.2858991,5.666655 9.99423096,8 L9.86923096,8 C8.45255721,8 7.14007033,8.39582938 5.93173096,9.1875 C3.89005408,10.5625069 2.86923096,12.4999875 2.86923096,15 C2.86923096,16.1666725 3.14006158,17.249995 3.68173096,18.25 C4.80673658,20.3750106 6.53588596,21.5833319 8.86923096,21.875 L8.86923096,23.875 C7.28588971,23.7083325 5.82757096,23.1458381 4.49423096,22.1875 C2.07755221,20.3958244 0.869230956,18.000015 0.869230956,15 C0.869230956,13.4583256 1.24422721,12.0000069 1.99423096,10.625 C3.41090471,8.1249875 5.53588346,6.6250025 8.36923096,6.125 C8.66089908,5.24999562 9.09839471,4.41667062 9.68173096,3.625 C11.4734066,1.20832125 13.869216,0 16.869231,0 C17.6192347,0 18.3900603,0.104165625 19.181731,0.3125 C21.848411,1.02083687 23.7858916,2.64582062 24.994231,5.1875 Z M19.806731,23.6875 C19.806731,23.7291669 19.8275641,23.7916663 19.869231,23.875 L19.869231,24.125 C19.8275641,24.2083337 19.806731,24.2708331 19.806731,24.3125 L19.744231,24.4375 L19.744231,24.5 L15.744231,31.5 C15.4525628,32.0000025 14.9942341,32.1250012 14.369231,31.875 C13.8692285,31.4999981 13.7442297,31.0416694 13.994231,30.5 L17.181731,25 L13.806731,25 C13.7650641,25 13.7233978,24.9791669 13.681731,24.9375 C13.5983972,24.9375 13.5150647,24.9166669 13.431731,24.875 L13.369231,24.875 L13.119231,24.625 L13.056731,24.5 C13.0150641,24.4583331 12.9733978,24.3958337 12.931731,24.3125 C12.931731,24.2708331 12.9108978,24.2083337 12.869231,24.125 L12.869231,23.875 C12.9108978,23.7916663 12.931731,23.7291669 12.931731,23.6875 L12.994231,23.5625 L12.994231,23.5 L16.994231,16.5 C17.327566,16.0416644 17.7858947,15.9166656 18.369231,16.125 C18.8692335,16.5000019 18.9942322,16.9583306 18.744231,17.5 L15.619231,23 L18.931731,23 C19.0150647,23.0416669 19.0775641,23.0625 19.119231,23.0625 C19.1608978,23.0625 19.2233972,23.0833331 19.306731,23.125 L19.369231,23.125 L19.619231,23.375 L19.681731,23.5 C19.7233978,23.5416669 19.7650641,23.6041663 19.806731,23.6875 Z" id="i_rain" fill="#000000"></path></g></svg>');
}
.hyper-quickssh__icon.i_net:before{
-webkit-mask-image: url('data:image/svg+xml;utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 33 32"><g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><path d="M16.869231,0 C21.0359185,0 24.6608822,1.43748563 27.744231,4.3125 C31.1609147,7.4791825 32.869231,11.3749769 32.869231,16 C32.869231,20.1666875 31.4317453,23.7916513 28.556731,26.875 C25.3900485,30.2916838 21.4942541,32 16.869231,32 C12.7025435,32 9.07757971,30.5625144 5.99423096,27.6875 C2.57754721,24.5208175 0.869230956,20.6250231 0.869230956,16 C0.869230956,11.8333125 2.30671658,8.20834875 5.18173096,5.125 C8.34841346,1.70831625 12.2442078,0 16.869231,0 Z M12.869231,16 C12.869231,18.333345 13.0150628,20.3958244 13.306731,22.1875 C14.4317366,22.0624994 15.6192247,22 16.869231,22 C18.1192372,22 19.3067253,22.0624994 20.431731,22.1875 C20.7233991,20.4374913 20.869231,18.3750119 20.869231,16 L12.869231,16 Z M12.931731,14 L20.806731,14 C20.7650641,12.5416594 20.6400653,11.14584 20.431731,9.8125 C19.3067253,9.93750063 18.1192372,10 16.869231,10 C15.6192247,10 14.4317366,9.93750063 13.306731,9.8125 C13.1400635,11.1041731 13.0150647,12.4999925 12.931731,14 Z M28.244231,7.875 C26.577556,8.7083375 24.6192422,9.27083188 22.369231,9.5625 C22.6192322,11.4375094 22.7650641,12.9166612 22.806731,14 L30.681731,14 C30.3900628,11.8749894 29.577571,9.83334312 28.244231,7.875 Z M30.869231,16 L22.869231,16 C22.869231,18.1666775 22.702566,20.2916562 22.369231,22.375 C24.7859097,22.7500019 26.7442235,23.3124963 28.244231,24.0625 C29.9525728,21.6041544 30.8275641,18.9166812 30.869231,16 Z M27.494231,7 C25.494221,4.62498813 22.994246,3.08333687 19.994231,2.375 C20.7859016,3.66667313 21.4525616,5.43748875 21.994231,7.6875 C23.3692378,7.56249937 24.6400585,7.333335 25.806731,7 L27.494231,7 Z M16.869231,2 C15.535891,2.04166687 14.4525685,3.99998062 13.619231,7.875 C14.9942378,7.95833375 16.0775603,8 16.869231,8 C17.6192347,8 18.7025572,7.95833375 20.119231,7.875 C19.2858935,4.0416475 18.202571,2.08333375 16.869231,2 Z M13.744231,2.375 C10.7858828,3.08333687 8.28590783,4.62498813 6.24423096,7 L7.93173096,7 C9.05673658,7.333335 10.3275572,7.56249937 11.744231,7.6875 C12.2859003,5.47915563 12.9525603,3.70834 13.744231,2.375 Z M5.49423096,7.875 C4.20255783,9.79167625 3.39006596,11.8333225 3.05673096,14 L10.931731,14 C10.9733978,12.9166612 11.1192297,11.4583425 11.369231,9.625 C9.07755283,9.24999812 7.11923908,8.66667062 5.49423096,7.875 Z M10.869231,16 L2.86923096,16 C2.86923096,18.8750144 3.74422221,21.5624875 5.49423096,24.0625 C6.95257158,23.3541631 8.91088533,22.7916688 11.369231,22.375 C11.035896,20.3333231 10.869231,18.2083444 10.869231,16 Z M6.18173096,25 C8.18174096,27.333345 10.7025491,28.8749963 13.744231,29.625 C12.9525603,28.3333269 12.2859003,26.5625113 11.744231,24.3125 C10.3692241,24.4375006 9.05673721,24.666665 7.80673096,25 L6.18173096,25 Z M16.869231,30 C18.202571,29.9583331 19.2858935,28.0000194 20.119231,24.125 C18.7442241,24.0416663 17.6609016,24 16.869231,24 C16.1192272,24 15.0359047,24.0416663 13.619231,24.125 C14.4525685,27.9583525 15.535891,29.9166663 16.869231,30 Z M19.994231,29.625 C22.994246,28.9166631 25.5150541,27.3750119 27.556731,25 L25.931731,25 C24.7233916,24.666665 23.4109047,24.4375006 21.994231,24.3125 C21.4525616,26.5208444 20.7859016,28.29166 19.994231,29.625 Z" id="i_net" fill="#000000"></path></g></svg>');
}
.hyper-quickssh__icon.i_mail:before{
-webkit-mask-image: url('data:image/svg+xml;utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 33 26"><g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><path d="M32.806731,25 C32.7650641,25.5833362 32.4317341,25.9166663 31.806731,26 L1.86923096,26 C1.36922846,25.8749994 1.05673158,25.5416694 0.931730956,25 L0.931730956,0.9375 C0.931730956,0.729165625 1.01506346,0.5416675 1.18173096,0.375 L1.18173096,0.25 L1.24423096,0.25 C1.36923158,0.16666625 1.55672971,0.08333375 1.80673096,0 L31.931731,0 C32.1400653,0.08333375 32.3275635,0.16666625 32.494231,0.25 L32.556731,0.25 L32.556731,0.3125 C32.6817316,0.4791675 32.7650641,0.68749875 32.806731,0.9375 L32.806731,25 Z M28.994231,2 L4.74423096,2 L16.869231,11.75 L28.994231,2 Z M30.869231,23 L30.869231,3.0625 L17.619231,13.625 L17.556731,13.6875 C17.3483966,13.8541675 17.1192322,13.9583331 16.869231,14 C16.6608966,14 16.4317322,13.8958344 16.181731,13.6875 L16.119231,13.6875 L2.86923096,3.0625 L2.86923096,23 C2.99423158,23.5416694 3.32756158,23.8749994 3.86923096,24 L29.869231,24 C30.4109003,23.8749994 30.7442303,23.5416694 30.869231,23 Z" id="i_mail" fill="#000000"></path></g></svg>');
}
.hyper-quickssh__icon.i_load:before{
-webkit-mask-image: url('data:image/svg+xml;utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 33 28"><g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><path d="M26.869231,16 C27.9942366,16 29.056726,16.3124969 30.056731,16.9375 C31.9317403,18.1041725 32.869231,19.7916556 32.869231,22 C32.869231,23.1250056 32.5567341,24.187495 31.931731,25.1875 C30.7650585,27.0625094 29.0775753,28 26.869231,28 C25.7442253,28 24.681736,27.6875031 23.681731,27.0625 C21.8067216,25.8958275 20.869231,24.2083444 20.869231,22 L20.869231,21.5625 C20.9108978,21.3541656 20.931731,21.2083337 20.931731,21.125 L11.931731,17.125 C10.7650585,19.0000094 9.07757533,19.9583331 6.86923096,20 C5.74422533,20 4.68173596,19.6875031 3.68173096,19.0625 C1.80672158,17.8958275 0.869230956,16.2083444 0.869230956,14 C0.869230956,12.8749944 1.18172783,11.812505 1.80673096,10.8125 C2.97340346,8.93749063 4.66088658,8 6.86923096,8 C9.11924221,8.04166687 10.8900578,9.10415625 12.181731,11.1875 L20.994231,7.25 C20.9108972,6.79166437 20.869231,6.37500188 20.869231,6 C20.869231,4.87499437 21.1817278,3.812505 21.806731,2.8125 C22.9734035,0.937490625 24.6608866,0 26.869231,0 C27.9942366,0 29.056726,0.312496875 30.056731,0.9375 C31.9317403,2.1041725 32.869231,3.79165563 32.869231,6 C32.869231,7.12500563 32.5567341,8.187495 31.931731,9.1875 C30.7650585,11.0625094 29.0775753,12 26.869231,12 C24.7858872,11.8749994 23.0984041,10.9166756 21.806731,9.125 L12.806731,13.125 C12.806731,13.2083337 12.8275641,13.3541656 12.869231,13.5625 L12.869231,14 C12.869231,14.333335 12.8275647,14.7499975 12.744231,15.25 L21.556731,19.1875 C21.556731,19.1458331 21.5775641,19.1041669 21.619231,19.0625 C22.8275703,17.0208231 24.5775528,16 26.869231,16 Z M26.869231,2 C26.2442278,2 25.6400672,2.14583188 25.056731,2.4375 C23.5983903,3.18750375 22.869231,4.37499187 22.869231,6 C22.869231,6.62500313 23.0150628,7.22916375 23.306731,7.8125 C24.0567347,9.27084062 25.2442228,10 26.869231,10 C27.4942341,10 28.0983947,9.85416812 28.681731,9.5625 C30.1400716,8.81249625 30.869231,7.62500813 30.869231,6 C30.869231,5.37499687 30.7233991,4.77083625 30.431731,4.1875 C29.6817272,2.72915938 28.4942391,2 26.869231,2 Z M6.86923096,18 C7.49423408,18 8.09839471,17.8541681 8.68173096,17.5625 C10.1400716,16.8124963 10.869231,15.6250081 10.869231,14 C10.869231,13.3749969 10.7233991,12.7708362 10.431731,12.1875 C9.68172721,10.7291594 8.49423908,10 6.86923096,10 C6.24422783,10 5.64006721,10.1458319 5.05673096,10.4375 C3.59839033,11.1875037 2.86923096,12.3749919 2.86923096,14 C2.86923096,14.6250031 3.01506283,15.2291638 3.30673096,15.8125 C4.05673471,17.2708406 5.24422283,18 6.86923096,18 Z M26.869231,26 C27.4942341,26 28.0983947,25.8541681 28.681731,25.5625 C30.1400716,24.8124963 30.869231,23.6250081 30.869231,22 C30.869231,21.3749969 30.7233991,20.7708362 30.431731,20.1875 C29.6817272,18.7291594 28.4942391,18 26.869231,18 C26.2442278,18 25.6400672,18.1458319 25.056731,18.4375 C23.5983903,19.1875037 22.869231,20.3749919 22.869231,22 C22.869231,22.6250031 23.0150628,23.2291638 23.306731,23.8125 C24.0567347,25.2708406 25.2442228,26 26.869231,26 Z" id="i_load" fill="#000000"></path></g></svg>');
}
.hyper-quickssh__icon.i_king:before{
-webkit-mask-image: url('data:image/svg+xml;utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 29 28"><g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><path d="M21.869231,14 L28.869231,8 L28.869231,28 L0.869230956,28 L0.869230956,8 L7.86923096,14 L12.556731,7.25 C11.4733922,6.45832938 10.9108978,5.37500688 10.869231,4 C10.869231,3.37499687 11.0150628,2.77083625 11.306731,2.1875 C12.0567347,0.729159375 13.2442228,0 14.869231,0 C15.4942341,0 16.0983947,0.145831875 16.681731,0.4375 C18.1400716,1.18750375 18.869231,2.37499187 18.869231,4 C18.8275641,5.37500688 18.2650697,6.45832938 17.181731,7.25 L21.869231,14 Z M14.869231,2 C14.7025635,2 14.4942322,2.02083313 14.244231,2.0625 C13.3275597,2.35416812 12.869231,2.999995 12.869231,4 C12.869231,4.1666675 12.8900641,4.37499875 12.931731,4.625 C13.2233991,5.54167125 13.869226,6 14.869231,6 C15.0358985,6 15.2442297,5.97916687 15.494231,5.9375 C16.4109022,5.64583188 16.869231,5.000005 16.869231,4 C16.869231,3.8333325 16.8483978,3.62500125 16.806731,3.375 C16.5150628,2.45832875 15.869236,2 14.869231,2 Z M26.869231,26 L26.869231,24 L2.86923096,24 L2.86923096,26 L26.869231,26 Z M26.869231,22 L26.869231,12.375 L21.494231,16.9375 L15.181731,7.9375 C15.1400641,7.97916687 15.0358985,8 14.869231,8 L14.556731,8 L9.49423096,15.125 L8.24423096,16.9375 L2.86923096,12.375 L2.86923096,22 L26.869231,22 Z" id="i_king" fill="#000000"></path></g></svg>');
}
.hyper-quickssh__icon.i_image:before{
-webkit-mask-image: url('data:image/svg+xml;utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 33 28"><g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><path d="M2.86923096,21 C2.91089783,21.5833363 3.24422783,21.9166662 3.86923096,22 L4.86923096,22 L4.86923096,24 L2.86923096,24 C2.70256346,24 2.49423221,23.9791669 2.24423096,23.9375 C1.32755971,23.6458319 0.869230956,23.000005 0.869230956,22 L0.869230956,2 C0.869230956,1.8333325 0.890064081,1.62500125 0.931730956,1.375 C1.22339908,0.45832875 1.86922596,0 2.86923096,0 L26.869231,0 C27.0358985,0 27.2442297,0.020833125 27.494231,0.0625 C28.4109022,0.354168125 28.869231,0.999995 28.869231,2 L28.869231,4 L26.869231,4 L26.869231,3 C26.8275641,2.41666375 26.4942341,2.08333375 25.869231,2 L3.86923096,2 C3.28589471,2.04166687 2.95256471,2.37499688 2.86923096,3 L2.86923096,21 Z M30.869231,6 C31.0358985,6 31.2442297,6.02083313 31.494231,6.0625 C32.4109022,6.35416812 32.869231,6.999995 32.869231,8 L32.869231,26 C32.869231,26.1666675 32.8483978,26.3749988 32.806731,26.625 C32.5150628,27.5416713 31.869236,28 30.869231,28 L8.86923096,28 C8.70256346,28 8.49423221,27.9791669 8.24423096,27.9375 C7.32755971,27.6458319 6.86923096,27.000005 6.86923096,26 L6.86923096,8 C6.86923096,7.8333325 6.89006408,7.62500125 6.93173096,7.375 C7.22339908,6.45832875 7.86922596,6 8.86923096,6 L30.869231,6 Z M30.869231,23.1797753 L27.306731,19.9375 L23.431731,24 L23.244231,24 L19.431731,19.9375 L13.369231,26 L29.869231,26 C30.4525672,25.9583331 30.7858972,25.6250031 30.869231,25 L30.869231,23.1797753 Z M30.869231,20.5 L30.869231,9 C30.8275641,8.41666375 30.4942341,8.08333375 29.869231,8 L9.86923096,8 C9.28589471,8.04166687 8.95256471,8.37499688 8.86923096,9 L8.86923096,25 C8.91089783,25.5833363 9.24422783,25.9166662 9.86923096,26 L10.369231,26 L19.306731,17 L19.306731,17.0625 L19.369231,17 L23.369231,21.0625 L27.369231,17 L27.431731,17.0625 L27.494231,17 L30.869231,20.5 Z M13.869231,12 C14.2442328,12 14.6400622,12.0833325 15.056731,12.25 C16.2650703,12.7500025 16.869231,13.66666 16.869231,15 C16.869231,15.3750019 16.7858985,15.7708312 16.619231,16.1875 C16.1192285,17.3958394 15.202571,18 13.869231,18 C13.4942291,18 13.0983997,17.9166675 12.681731,17.75 C11.4733916,17.2499975 10.869231,16.33334 10.869231,15 C10.869231,14.5833312 10.9525635,14.208335 11.119231,13.875 C11.6192335,12.6249937 12.535891,12 13.869231,12 Z M13.869231,16 C14.4525672,15.9583331 14.7858972,15.6250031 14.869231,15 C14.8275641,14.4166637 14.4942341,14.0833338 13.869231,14 C13.2858947,14.0416669 12.9525647,14.3749969 12.869231,15 C12.9108978,15.5833363 13.2442278,15.9166662 13.869231,16 Z" id="i_image" fill="#000000"></path></g></svg>');
}
.hyper-quickssh__icon.i_data:before{
-webkit-mask-image: url('data:image/svg+xml;utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 25 30"><g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><path d="M24.869231,6 L24.869231,25.125 C24.6192297,25.8750037 24.0567353,26.58333 23.181731,27.25 C20.8067191,29.0833425 17.3692535,30 12.869231,30 C10.8275541,30 8.91090658,29.7708356 7.11923096,29.3125 C3.57754658,28.3958287 1.49423408,27.0000094 0.869230956,25.125 L0.869230956,6 C0.910897831,4.87499437 1.51505846,3.83333812 2.68173096,2.875 C5.01507596,0.95832375 8.41087533,0 12.869231,0 C15.7442453,0 18.3067197,0.45832875 20.556731,1.375 C23.4317453,2.58333937 24.869231,4.12499063 24.869231,6 Z M22.869231,24 L22.869231,21.3125 C20.535886,23.1041756 17.202586,24 12.869231,24 C8.57754283,24 5.24424283,23.1041756 2.86923096,21.3125 L2.86923096,24 C2.86923096,24.6250031 3.24422721,25.2291637 3.99423096,25.8125 C5.86924033,27.2708406 8.82754408,28 12.869231,28 C15.0775753,28 17.0983885,27.7291694 18.931731,27.1875 C21.5567441,26.3541625 22.869231,25.2916731 22.869231,24 Z M22.869231,18 L22.869231,15.3125 C20.535886,17.1041756 17.202586,18 12.869231,18 C8.57754283,18 5.24424283,17.1041756 2.86923096,15.3125 L2.86923096,18 C2.86923096,18.6250031 3.24422721,19.2291637 3.99423096,19.8125 C5.86924033,21.2708406 8.82754408,22 12.869231,22 C15.0775753,22 17.0983885,21.7291694 18.931731,21.1875 C21.5567441,20.3541625 22.869231,19.2916731 22.869231,18 Z M22.869231,12 L22.869231,9.3125 C20.535886,11.1041756 17.202586,12 12.869231,12 C8.57754283,12 5.24424283,11.1041756 2.86923096,9.3125 L2.86923096,12 C2.86923096,12.6250031 3.24422721,13.2291637 3.99423096,13.8125 C5.86924033,15.2708406 8.82754408,16 12.869231,16 C15.0775753,16 17.0983885,15.7291694 18.931731,15.1875 C21.5567441,14.3541625 22.869231,13.2916731 22.869231,12 Z M12.869231,10 C15.0775753,10 17.0983885,9.72916938 18.931731,9.1875 C21.5567441,8.3541625 22.869231,7.29167312 22.869231,6 C22.869231,5.37499688 22.4942347,4.77083625 21.744231,4.1875 C19.8692216,2.72915938 16.9109178,2 12.869231,2 C10.6608866,2 8.64007346,2.27083062 6.80673096,2.8125 C4.18171783,3.6458375 2.86923096,4.70832688 2.86923096,6 C2.86923096,6.62500312 3.24422721,7.22916375 3.99423096,7.8125 C5.86924033,9.27084062 8.82754408,10 12.869231,10 Z" id="i_data" fill="#000000"></path></g></svg>');
}
.hyper-quickssh__icon.i_cycle:before{
-webkit-mask-image: url('data:image/svg+xml;utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 33 32"><g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><path d="M1.43173096,11.875 L3.49423096,12 L11.869231,12 C12.4942341,11.9166663 12.8275641,11.5833362 12.869231,11 C12.7858972,10.3749969 12.4525672,10.0416669 11.869231,10 L4.24423096,10 C5.86923908,6.58331625 8.45254658,4.20834 11.994231,2.875 C13.5775722,2.29166375 15.202556,2 16.869231,2 C21.0775853,2 24.5567172,3.5833175 27.306731,6.75 C29.1400735,8.87501062 30.2650622,11.2916531 30.681731,14 L32.744231,14 C32.1608947,9.54164438 30.0775822,5.95834688 26.494231,3.25 C23.6608835,1.0833225 20.4525822,0 16.869231,0 C12.1608741,0 8.22341346,1.7499825 5.05673096,5.25 C4.22339346,6.20833812 3.49423408,7.22916125 2.86923096,8.3125 L2.86923096,1 C2.78589721,0.374996875 2.45256721,0.041666875 1.86923096,0 C1.24422783,0.08333375 0.910897831,0.41666375 0.869230956,1 L0.869230956,11.125 C0.869230956,11.1666669 0.890064081,11.2291663 0.931730956,11.3125 C0.973397831,11.3958337 0.994230956,11.4583331 0.994230956,11.5 L1.05673096,11.5625 C1.22339846,11.7291675 1.34839721,11.8333331 1.43173096,11.875 Z M32.869231,20.875 C32.869231,20.8333331 32.8483978,20.7708337 32.806731,20.6875 C32.7650641,20.6041663 32.744231,20.5416669 32.744231,20.5 L32.681731,20.4375 C32.5150635,20.2708325 32.3900647,20.1666669 32.306731,20.125 L30.244231,20 L21.869231,20 C21.2442278,20.0833337 20.9108978,20.4166638 20.869231,21 C20.9525647,21.6250031 21.2858947,21.9583331 21.869231,22 L29.494231,22 C27.8692228,25.4166838 25.2859153,27.79166 21.744231,29.125 C20.1608897,29.7083362 18.535906,30 16.869231,30 C12.6608766,30 9.18174471,28.4166825 6.43173096,25.25 C4.59838846,23.1249894 3.47339971,20.7083469 3.05673096,18 L0.994230956,18 C1.57756721,22.4583556 3.64004658,26.0416531 7.18173096,28.75 C10.0567453,30.9166775 13.2858797,32 16.869231,32 C21.5775878,32 25.5150485,30.2500175 28.681731,26.75 C29.5150685,25.7916619 30.2442278,24.7708388 30.869231,23.6875 L30.869231,31 C30.9525647,31.6250031 31.2858947,31.9583331 31.869231,32 C32.4942341,31.9166663 32.8275641,31.5833362 32.869231,31 L32.869231,20.875 Z" id="i_cycle" fill="#000000"></path></g></svg>');
}
.hyper-quickssh__prefs{ background-color: ${colors.backgroundLighted}; font-size: 11px; color: ${configColors.lightBlack}; position: absolute; bottom: 0; left: 0; right: 0; padding: 8px 12px; z-index: 1000; }
.hyper-quickssh__prefs:hover{ text-decoration: underline; color: ${configColors.lightBlue} }
.hyper-quickssh__float{
background-color: ${configColors.lightBlue};
position: fixed;
right: 20px;
bottom: 20px;
width: 45px;
height: 45px;
border-radius: 23px;
color: ${colors.background};
text-align: center;
line-height: 40px;
font-size: 24px;
box-shadow: 0 2px 8px rgba(0,0,0,0.2);
transition: background 150ms ease, opacity 150ms ease;
}
.hyper-quickssh__float:hover,
.hyper-quickssh__float:focus{ opacity: 0.9; }
`
});
};
function dirname (path) {
return path.replace(/\\/g, '/')
.replace(/\/[^/]*\/?$/, '')
}
function getPrefsFile(){
return path.join(process.env['HOME'], '.hyper_plugins/'+QUICKSSH_CONFIG_FILE);
}
function openFilePrefs(e) {
let filefull = getPrefsFile();
let filedir = dirname(filefull);
shell.openExternal('file://'+filedir);
}
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min;
}
exports.decorateHyper = (Hyper, { React }) => {
return class extends React.Component {
constructor(props) {
super(props);
reactHistoryNav = this;
this.handleClick = this.handleClick.bind(this);
this.handlePrefsClick = this.handlePrefsClick.bind(this);
//this.handleKeyDown = this.handleKeyDown.bind(this);
this.state = {
cursor: 0,
result: quicksshEntries
}
}
handleClick(e) { }
handlePrefsClick(e){
openFilePrefs(e);
}
render() {
const color = require('color');
const { cursor } = this.state;
this.state.results = quicksshEntries;
return (
React.createElement(Hyper, Object.assign({}, this.props, {
customChildren:
React.createElement('div', { style: { display: 'false'}, className: `hyper-quickssh hidden`, id: 'id_hyper_quickssh', ref: 'quickssh' },
React.createElement('div', { className: 'hyper-quickssh__prefs item_clickable', onClick: _ => { openFilePrefs(); } }, getPrefsFile()),
React.createElement('div', { className: 'hyper-quickssh-list' },
...quicksshEntries.map(entry => {
return React.createElement('div',
{
key: entry.index,
className: `hyper-quickssh-list__item item_clickable ${cursor === entry.index ? 'active' : ''}`,
onClick: _ => {
activeItem(entry);
}
},
React.createElement('div', { className: `hyper-quickssh__avatar` },
React.createElement('div', { className: `hyper-quickssh__icon i_${entry.icon}`, style: { backgroundColor: (color(String(entry.color||QUICKSSH_COLORS[entry.index]||QUICKSSH_COLORS[getRandomInt(0, QUICKSSH_COLORS.length)])).string()) } })
),
React.createElement('div', { className: 'hyper-quickssh__info' },
React.createElement('div', { className: 'hyper-quickssh__item_title', title: entry.title }, entry.title ? String(entry.title): ''),
React.createElement('div', { className: 'hyper-quickssh__item_cmd', title: entry.command }, entry.command ? String(entry.command): '')
)
)
})
)
)
}))
)
}
};
};
exports.middleware = (store) => (next) => (action) => {
if (supressMode) {
return next(action);
}
const uids = store.getState().sessions.sessions;
switch (action.type) {
case 'SESSION_USER_DATA':
const { data } = action;
let charCode = data.charCodeAt(0);
if (QUICK_SELECT_CHAR_CODE.includes(charCode)) {
let idxQuickSel = QUICK_SELECT_CHAR_CODE.indexOf(charCode);
if (idxQuickSel >= 0 && quicksshEntries.length > idxQuickSel) {
activeItem(quicksshEntries[idxQuickSel]);
}
reset();
return; //prevent input
} else if (data.charCodeAt(0) === 13) {
currUserInputData = '';
toggleComponentWindow(false);
} else if (data.charCodeAt(0) === 127) {
currUserInputData = (currUserInputData ? currUserInputData.slice(0, -1) : '').toString();
getQuickList();
} else {
currUserInputData += (data ? data : '').toString().toLowerCase();
currUserInputData.length === 0 ? reset() : getQuickList();
}
// ctrl + c ?
if(charCode == 3)
currUserInputData = '';
if(charCode == 27)
currUserInputData = '';
break;
case 'SESSION_ADD':
window.HYPER_HISTORY_TERM = currTerminal = allTerminals[action.uid];
break;
case 'SESSION_SET_ACTIVE':
currPid = uids[action.uid].pid;
window.HYPER_HISTORY_TERM = currTerminal = allTerminals[action.uid];
setCwd(currPid);
break;
}
next(action);
};
exports.decorateTerm = (Term, { React }) => {
class HyperSSHTerm extends React.Component {
constructor(props, context) {
super(props, context);
// this.onTerminal = this.onTerminal.bind(this, this);
this.isVisible = false;
this.handleOpenWindow = this.handleOpenWindow.bind(this);
this.handleOpenConfig = this.handleOpenConfig.bind(this);
visibleQuickComponent = this.isVisible;
}
componentDidMount() {
window.rpc.on('hyper-quickssh:open:window', this.handleOpenWindow);
window.rpc.on('hyper-quickssh:open:config', this.handleOpenConfig);
}
handleOpenWindow() {
const { sessions, term, uid, focussedSessionUid } = this.props;
// terminal config (new)
if (term != null)
allTerminals[focussedSessionUid] = term;
window.HYPER_HISTORY_TERM_ALL = allTerminals;
window.HYPER_HISTORY_TERM = currTerminal = term;
currFocusedUid = focussedSessionUid;
// update
getQuickList();
toggleComponentWindow();
}
handleOpenConfig() {
// update
openFilePrefs(this);
}
render() {
let props = Object.assign({}, this.props, {
onTerminal: this.onTerminal
});
return React.createElement(Term, props);
}
};
return HyperSSHTerm;
};
function reset() {
currUserInputData = '';
quicksshEntries = [];
updateReact();
}
function filterQuickSSH(results){
if(!results) return;
if(results.length <= 0) return;
quicksshEntries = Object.keys(results)
.map((e, i) => {
let item = results[e];
item.index = e;
item.title = item.title || "";
item.command = item.command || item.cmd || "";
item.fulltext = item.title + " "+item.command;
return item
}) || [];
let typed = currUserInputData.toString().trim() || "";
if(isVisibleComponent() && (lastKeyCodeTerminal == 38 || lastKeyCodeTerminal == 40)){
updateReact();
return;
}
if(typed.length <= 1){
updateReact();
return;
}
let set = {};
let list = quicksshEntries.map(obj => {
let e = obj.fulltext;
if (e.length <= 2) {
return undefined;
} else if (set[e] === true) {
return undefined;
} else {
set[e] = true;
return e.toLowerCase();
}
})
let matches = fuzzy.filter(typed, list);
let filtered = [];
matches.map(function(mt){
filtered = [...filtered, quicksshEntries[mt.index]];
});
quicksshEntries = filtered;
updateReact();
}
function saveQuickListConfig(quickssh){
fs.writeFile(getPrefsFile(), JSON.stringify(quickssh), (err) => {
if(!err){
filterQuickSSH(quickssh.results);
}else{
debug('Could not save file: '+getPrefsFile());
}
});
}
function getQuickList() {
let example = {
icon: "default",
title: "Example > Hello World",
command: "echo 'Hello World'"
};
let error = {
icon: "bug",
title: "[Config file error]",
command: "open '"+getPrefsFile()+"'",
color: "red"
};
// default
let quickssh = { results: [ example ], icons: QUICKSSH_ICONS, colors: QUICKSSH_COLORS };
fs.readFile(getPrefsFile(), (err, data) => {
if (!err){
let data_json = {};
try{
data_json = JSON.parse(data.toString());
}catch(e){
if(!data.toString().length){
data_json = quickssh;
}else{
data_json.results = [ error ];
}
}
// update icons and colors
quickssh.icons = QUICKSSH_ICONS;
quickssh.colors = QUICKSSH_COLORS;
// get results or default
quickssh.results = data_json.results || quickssh.results;
// resave to defaulting if file not exists or empty
if(!data.toString() || data.toString().length < 10){
if(!data_json.length || !data_json.results || data_json.results.length <= 0){
saveQuickListConfig(quickssh);
}
}
filterQuickSSH(quickssh.results);
} else {
if (err.code === 'ENOENT'){
saveQuickListConfig(quickssh);
filterQuickSSH(quickssh.results);
}
}
});
}
function updateReact() {
if(reactHistoryNav)
reactHistoryNav.forceUpdate();
}
// Current shell cwd
function setCwd(pid) {
exec(`lsof -p ${pid} | grep cwd | tr -s ' ' | cut -d ' ' -f9-`, (err, cwd) => {
currCwd = cwd.trim();
})
};
function isVisibleComponent(){
var el = document.getElementById('id_hyper_quickssh');
if(el.style.display == "none" || el.classList.contains("hidden"))
return false; else
return true;
}
function getReactListNav(){
return reactHistoryNav;
}
function toggleComponentWindow(isVisible){
if(isVisible == undefined) isVisible = !isVisibleComponent();
var el = document.getElementById('id_hyper_quickssh');
el.classList.remove('hidden');
if(!isVisible){
// focus
if(currTerminal) currTerminal.focus();
el.classList.add('hidden');
// clean filter string
currUserInputData = '';
}
}
function sendString(uid, data){
window.rpc.emit('data', {uid:uid, data: data, escaped: false});
}
function activeItem(entry) {
supressMode = true;
let command = entry.command;
if (currFocusedUid != null){
sendString(currFocusedUid, '\b'.repeat(currUserInputData.length));
sendString(currFocusedUid, command + '\r');
}
currUserInputData = '';
quicksshEntries = [];
updateReact();
supressMode = false;
currTerminal.focus();
if(isVisibleComponent()){
toggleComponentWindow(false);
}
}
function debug(...args) {
if (DEBUG) {
console.info(...args);
log.info(...args);
}
}
exports.mapTermsState = (state, map) => (
Object.assign(map, {
focussedSessionUid: state.sessions.activeUid
})
);
exports.passProps = (uid, parentProps, props) => (
Object.assign(props, {
focussedSessionUid: parentProps.focussedSessionUid
})
);
exports.getTermGroupProps = exports.passProps;
exports.getTermProps = exports.passProps;