forked from jain-harshil/vtop_new
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
1164 lines (1000 loc) · 34.1 KB
/
app.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
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
'use strict'
const App = ((() => {
// Load in required libs
const Canvas = require('drawille')
const blessed = require('blessed')
var contrib = require('blessed-contrib')
const os = require('os')
const cli = require('commander')
const upgrade = require('./upgrade.js')
const VERSION = require('./package.json').version
const childProcess = require('child_process')
const glob = require('glob')
const path = require('path')
const time_start = Date.now()
const mem_2 = os.totalmem()/(Math.pow(10, 9))
// var flag = 1
var cpu_current
var mem_current
var cpu_sum = 0
var cpu_avg = 0
var count = 0
var mem_sum = 0
var mem_avg = 0
var count1 = 0
let themes = ''
let program = blessed.program()
let selectedProcess;
const files = glob.sync(path.join(__dirname, 'themes', '*.json'))
for (var i = 0; i < files.length; i++) {
let themeName = files[i].replace(path.join(__dirname, 'themes') + path.sep, '').replace('.json', '')
themes += `${themeName}|`
}
themes = themes.slice(0, -1)
// Set up the commander instance and add the required options
cli
.option('-t, --theme [name]', `set the vtop theme [${themes}]`, 'parallax')
.option('--no-mouse', 'Disables mouse interactivity')
.option('--quit-after [seconds]', 'Quits vtop after interval', '0')
.option('--update-interval [milliseconds]', 'Interval between updates', '300')
.version(VERSION)
.parse(process.argv)
/**
* Instance of blessed screen, and the charts object
*/
let screen
const charts = []
let loadedTheme
const intervals = []
let upgradeNotice = false
let disableTableUpdate = false
let disableTableUpdateTimeout = setTimeout(() => {}, 0)
let graphScale = 1
// Private variables
/**
* This is the number of data points drawn
* @type {Number}
*/
let position = 0
const size = {
pixel: {
width: 0,
height: 0
},
character: {
width: 0,
height: 0
}
}
// @todo: move this into charts array
// This is an instance of Blessed Box
let graph
let treelist
let treelist1
let treelist2
let treelist3
let processListSelectiontree
let processListSelectiontree_1
let processListSelectiontree_2
let processListSelectiontree_3
let list_process
let graph2
let processList
let processListSelection
// Private functions
/**
* Draw header
* @param {string} left This is the text to go on the left
* @param {string} right This is the text for the right
* @return {void}
*/
const drawHeader = () => {
let headerText
let headerTextNoTags
if (upgradeNotice) {
upgradeNotice = `${upgradeNotice}`
headerText = ` {bold}vtop{/bold}{white-fg} for ${os.hostname()} {red-bg} Press 'u' to upgrade to v${upgradeNotice} {/red-bg}{/white-fg}`
headerTextNoTags = ` vtop for ${os.hostname()} Press 'u' to upgrade to v${upgradeNotice} `
} else {
headerText = ` {bold}vtop{/bold}{white-fg} for ${os.hostname()} `
headerTextNoTags = ` vtop for ${os.hostname()} `
}
const header = blessed.text({
top: 'top',
left: 'left',
width: headerTextNoTags.length,
height: '1',
fg: loadedTheme.title.fg,
content: headerText,
tags: true
})
const date = blessed.text({
top: 'top',
right: 0,
width: 9,
height: '1',
align: 'right',
content: '',
tags: true
})
const loadAverage = blessed.text({
top: 'top',
height: '1',
align: 'center',
content: '',
tags: true,
left: Math.floor(program.cols / 2 - (28 / 2))
})
screen.append(header)
screen.append(date)
screen.append(loadAverage)
const zeroPad = input => (`0${input}`).slice(-2)
const updateTime = () => {
const time = new Date()
date.setContent(`${zeroPad(time.getHours())}:${zeroPad(time.getMinutes())}:${zeroPad(time.getSeconds())} `)
screen.render()
}
const updateLoadAverage = () => {
const avg = os.loadavg()
loadAverage.setContent(`Load Average: ${avg[0].toFixed(2)} ${avg[1].toFixed(2)} ${avg[2].toFixed(2)}`)
screen.render()
}
updateTime()
updateLoadAverage()
setInterval(updateTime, 1000)
setInterval(updateLoadAverage, 1000)
}
/**
* Draw the footer
*
* @todo This appears to break on some viewports
*/
const drawFooter = () => {
const commands = {
'dd': 'Kill proc',
'j': 'Down',
'k': 'Up',
'g': 'top jump',
'G': 'bottom jump',
'c': 'CPU sort',
'm': 'Mem sort',
'p': 'Mem usage in %', //added
'b': 'Mem usage in GB',
'i': 'Sort by PID',
't': 'Process Tree',
'v': 'Stack size',
'l': 'Real Memory',
'r': 'Malloc Zone'
}
let text = ''
for (const c in commands) {
const command = commands[c]
text += ` {white-bg}{black-fg}${c}{/black-fg}{/white-bg} ${command}`
}
text += '{|}http://parall.ax/vtop'
const footerRight = blessed.box({
width: '100%',
top: program.rows - 1,
tags: true,
fg: loadedTheme.footer.fg
})
footerRight.setContent(text)
screen.append(footerRight)
}
/**
* Repeats a string
* @var string The string to repeat
* @var integer The number of times to repeat
* @return {string} The repeated chars as a string.
*/
const stringRepeat = (string, num) => {
if (num < 0) {
return ''
}
return new Array(num + 1).join(string)
}
/**
* This draws a chart
* @param {int} chartKey The key of the chart.
* @return {string} The text output to draw.
*/
const drawChart = chartKey => {
const chart = charts[chartKey]
const c = chart.chart
c.clear()
if (!charts[chartKey].plugin.initialized) {
return false
}
const dataPointsToKeep = 5000
charts[chartKey].values[position] = charts[chartKey].plugin.currentValue
const computeValue = input => chart.height - Math.floor(((chart.height + 1) / 100) * input) - 1
if (position > dataPointsToKeep) {
delete charts[chartKey].values[position - dataPointsToKeep]
}
for (const pos in charts[chartKey].values) {
if (graphScale >= 1 || (graphScale < 1 && pos % (1 / graphScale) === 0)) {
const p = parseInt(pos, 10) + (chart.width - charts[chartKey].values.length)
// calculated x-value based on graphScale
const x = (p * graphScale) + ((1 - graphScale) * chart.width)
// draws top line of chart
if (p > 1 && computeValue(charts[chartKey].values[pos - 1]) > 0) {
c.set(x, computeValue(charts[chartKey].values[pos - 1]))
}
// Start deleting old data points to improve performance////////////////////////////////////////////////////
// @todo: This is not be the best place to do this
// fills all area underneath top line
for (let y = computeValue(charts[chartKey].values[pos - 1]); y < chart.height; y++) {
if (graphScale > 1 && p > 0 && y > 0) {
const current = computeValue(charts[chartKey].values[pos - 1])
const next = computeValue(charts[chartKey].values[pos])
const diff = (next - current) / graphScale
// adds columns between data if graph is zoomed in, takes average where data is missing to make smooth curve
for (let i = 0; i < graphScale; i++) {
c.set(x + i, y + (diff * i))
for (let j = y + (diff * i); j < chart.height; j++) {
c.set(x + i, j)
}
}
} else if (graphScale <= 1) {
// magic number used to calculate when to draw a value onto the chart
// @TODO: Remove this?
// var allowedPValues = (charts[chartKey].values.length - ((graphScale * charts[chartKey].values.length) + 1)) * -1
c.set(x, y)
}
}
}
}
// Add percentage to top right of the chart by splicing it into the braille data
//var today = new Date();
const time_now = (Date.now() - time_start)/10**3
//var str_name = "Last ";
const textOutput = c.frame().split('\n')
if(chartKey==0){
count += 1
cpu_sum += chart.plugin.currentValue
cpu_avg = Math.round((cpu_sum/count)*100)/100
cpu_current = chart.plugin.currentValue
const percent = ` ${chart.plugin.currentValue}`
if(cpu_current>15){
const time_use = `${"Average CPU usage in last "}${time_now}${"s"}${" is "}${cpu_avg}%{red-fg}${"\t\t\t\t\t\t\t\t\t\t\tWarning!!!! Current CPU usage is "}${"\t"}${percent.slice(-3)}%{/red-fg}${textOutput[0].slice(0, textOutput[0].length - 4)}`
textOutput[0] = `${time_use}`
graph = blessed.box({
top: 1,
left: 'left',
width: '100%',
height: '50%',
content: textOutput.join('\n'),
fg: require(`./themes/${"wizard"}.json`).chart.fg,
tags: true,
border: require(`./themes/${"wizard"}.json`).chart.border
})
graph.setLabel(` ${charts[0].plugin.title} `)
screen.append(graph)
}
else{
const time_use = `${"Average CPU usage in last "}${time_now}${"s"}${" is "}${cpu_avg}%{white-fg}${"\t\t\t\t\t\t\t\t\t\t\tCurrent CPU usage is "}${"\t"}${percent.slice(-3)}%{/white-fg}${textOutput[0].slice(0, textOutput[0].length - 4)}`
textOutput[0] = `${time_use}`
graph = blessed.box({
top: 1,
left: 'left',
width: '100%',
height: '50%',
content: textOutput.join('\n'),
fg: require(`./themes/${cli.theme}.json`).chart.fg,
tags: true,
border: require(`./themes/${cli.theme}.json`).chart.border
})
graph.setLabel(` ${charts[0].plugin.title} `)
screen.append(graph)
}
return textOutput.join('\n')
}
else{
count1 += 1
mem_current = chart.plugin.currentValue
mem_sum += chart.plugin.currentValue
mem_avg = Math.round((mem_sum/count1)*100)/100
const percent = ` ${chart.plugin.currentValue}`
if(mem_current>60){
const time_use = `${"Average Memory usage in last "}${time_now}${"s"}${" is "}${mem_avg}%{red-fg}${"\tWarning!!! Current Memory usage is "}${"\t"}${percent.slice(-3)}%{/red-fg}${textOutput[0].slice(0, textOutput[0].length - 4)}`
textOutput[0] = `${time_use}`
// graph2.fg = require(`./themes/${"brew"}.json`).chart.fg
// graph2.border = require(`./themes/${"brew"}.json`).chart.border
// graph2.content = textOutput.join('\n')
graph2 = blessed.box({
top: graph.height + 1,
left: 'left',
width: '50%',
height: graph.height - 2,
content: textOutput.join('\n'),
fg: require(`./themes/${"brew"}.json`).chart.fg,
tags: true,
border: require(`./themes/${"brew"}.json`).chart.border
})
graph2.setLabel(` ${charts[1].plugin.title} `)
screen.append(graph2)
}
else{
const time_use = `${"Average Memory usage in last "}${time_now}${"s"}${" is "}${mem_avg}%{white-fg}${"\tCurrent Memory usage is "}${"\t"}${percent.slice(-3)}%{/white-fg}${textOutput[0].slice(0, textOutput[0].length - 4)}`
textOutput[0] = `${time_use}`
graph2 = blessed.box({
top: graph.height + 1,
left: 'left',
width: '50%',
height: graph.height - 2,
content: textOutput.join('\n'),
fg: require(`./themes/${cli.theme}.json`).chart.fg,
tags: true,
border: require(`./themes/${cli.theme}.json`).chart.border
})
graph2.setLabel(` ${charts[1].plugin.title} `)
screen.append(graph2)
}
return textOutput.join('\n')
}
}
/**
* Draws a table.
* @param {int} chartKey The key of the chart.
* @return {string} The text output to draw.
*/
const drawTable = chartKey => {
const chart = charts[chartKey]
const columnLengths = {}
// Clone the column array
const columns = chart.plugin.columns.slice(0)
columns.reverse()
let removeColumn = false
const lastItem = columns[columns.length -1]
const minimumWidth = 12
let padding = 1
if (chart.width > 50) {
padding = 2
}
if (chart.width > 80) {
padding = 3
}
// Keep trying to reduce the number of columns
do {
let totalUsed = 0
let firstLength = 0
// var totalColumns = columns.length
// Allocate space for each column in reverse order
for (const column in columns) {
const item = columns[column]
i++
// If on the last column (actually first because of array order)
// then use up all the available space
if (item === lastItem) {
columnLengths[item] = chart.width - totalUsed
firstLength = columnLengths[item]
} else {
columnLengths[item] = item.length + padding
}
totalUsed += columnLengths[item]
}
if (firstLength < minimumWidth && columns.length > 1) {
totalUsed = 0
columns.shift()
removeColumn = true
} else {
removeColumn = false
}
} while (removeColumn)
// And back again
columns.reverse()
let titleOutput = '{bold}'
for (const headerColumn in columns) {
var colText = ` ${columns[headerColumn]}`
titleOutput += (colText + stringRepeat(' ', columnLengths[columns[headerColumn]] - colText.length))
}
titleOutput += '{/bold}' + '\n'
const bodyOutput = []
for (const row in chart.plugin.currentValue) {
const currentRow = chart.plugin.currentValue[row]
let rowText = ''
for (const bodyColumn in columns) {
let colText = ` ${currentRow[columns[bodyColumn]]}`
rowText += (colText + stringRepeat(' ', columnLengths[columns[bodyColumn]] - colText.length)).slice(0, columnLengths[columns[bodyColumn]])
}
bodyOutput.push(rowText)
}
return {
title: titleOutput,
body: bodyOutput,
processWidth: columnLengths[columns[0]]
}
}
// This is set to the current items displayed
let currentItems = []
let processWidth = 0
/**
* Overall draw function, this should poll and draw results of
* the loaded sensors.
*/
const draw = () => {
position++
const chartKey = 0
graph.setContent(drawChart(chartKey))
graph2.setContent(drawChart(chartKey + 1))
//console.log(cpu_current)
if (!disableTableUpdate) {
const table = drawTable(chartKey + 2)
processList.setContent(table.title)
// If we keep the stat numbers the same immediately, then update them
// after, the focus will follow. This is a hack.
const existingStats = {}
// Slice the start process off, then store the full stat,
// so we can inject the same stat onto the new order for a brief render
// cycle.
for (var stat in currentItems) {
var thisStat = currentItems[stat]
existingStats[thisStat.slice(0, table.processWidth)] = thisStat
}
processWidth = table.processWidth
// Smush on to new stats
const tempStats = []
for (let stat in table.body) {
let thisStat = table.body[stat]
tempStats.push(existingStats[thisStat.slice(0, table.processWidth)])
}
// Move cursor position with temp stats
// processListSelection.setItems(tempStats);
// Update the numbers
processListSelection.setItems(table.body)
processListSelection.focus()
currentItems = table.body
}
screen.render()
}
// Public function (just the entry point)
return {
init () {
let theme
if (typeof process.theme !== 'undefined') {
theme = process.theme
} else {
theme = cli.theme
}
/**
* Quits running vtop after so many seconds
* This is mainly for perf testing.
*/
if (cli['quitAfter'] !== '0') {
setTimeout(() => {
process.exit(0)
}, parseInt(cli['quitAfter'], 10) * 1000)
}
try {
loadedTheme = require(`./themes/${theme}.json`)
} catch (e) {
console.log(`The theme '${theme}' does not exist.`)
process.exit(1)
}
// Create a screen object.
screen = blessed.screen()
// Configure 'q', esc, Ctrl+C for quit
let upgrading = false
const doCheck = () => {
upgrade.check(v => {
upgradeNotice = v
drawHeader()
})
}
doCheck()
// Check for updates every 5 minutes
// setInterval(doCheck, 300000);
let lastKey = ''
screen.on('keypress', (ch, key) => {
if (key === 'up' || key === 'down' || key === 'k' || key === 'j') {
// Disable table updates for half a second
disableTableUpdate = true
clearTimeout(disableTableUpdateTimeout)
disableTableUpdateTimeout = setTimeout(() => {
disableTableUpdate = false
}, 1000)
}
if (
upgrading === false &&
(
key.name === 'q' ||
key.name === 'escape' ||
(key.name === 'c' && key.ctrl === true)
)
) {
return process.exit(0)
}
// dd killall
// @todo: Factor this out
if (lastKey === 'd' && key.name === 'd') {
let selectedProcess = processListSelection.getItem(processListSelection.selected).content
selectedProcess = selectedProcess.slice(7, processWidth).trim()
childProcess.exec(`killall "${selectedProcess}"`, () => {})
}
if(key.name === 'b'){
charts[2].plugin.mem1 = mem_2/100
//charts[2].plugin.columns[1] = "CPU(GB)"
}
if(key.name === 'p'){
charts[2].plugin.mem1 = 1
//charts[2].plugin.columns[1] = "CPU %"
}
// if(key.name === 't'){
// screen.remove(processList)
// let selectedProcess = processListSelection.getItem(processListSelection.selected).content
// selectedProcess = selectedProcess.slice(0, 7).trim()
// console.log(selectedProcess)
// processListSelectiontree.setItems(list1)
// //charts[2].plugin.columns[1] = "CPU %"
// }
if (key.name === 'z') {
screen.append(processList)
}
if (key.name === 'c' && charts[2].plugin.sort !== 'cpu') {
charts[2].plugin.flag = 0
charts[2].plugin.sort = 'cpu'
charts[2].plugin.poll()
setTimeout(() => {
processListSelection.select(0)
}, 200)
}
if (key.name === 'm' && charts[2].plugin.sort !== 'mem') {
charts[2].plugin.flag = 0
charts[2].plugin.sort = 'mem'
charts[2].plugin.poll()
setTimeout(() => {
processListSelection.select(0)
}, 200)
}
if (key.name === 'i' && charts[2].plugin.sort !== 'pid') {
charts[2].plugin.flag = 1
charts[2].plugin.sort = 'pid'
//console.log(charts[2].plugin)
charts[2].plugin.poll()
setTimeout(() => {
processListSelection.select(0)
}, 200)
}
lastKey = key.name
if (key.name === 'u' && upgrading === false) {
upgrading = true
// Clear all intervals
for (const interval in intervals) {
clearInterval(intervals[interval])
}
processListSelection.detach()
program = blessed.program()
program.clear()
program.disableMouse()
program.showCursor()
program.normalBuffer()
// @todo: show changelog AND smush existing data into it :D
upgrade.install('vtop', [
{
'theme': theme
}
])
}
if ((key.name === 'left' || key.name === 'h') && graphScale < 8) {
graphScale *= 2
} else if ((key.name === 'right' || key.name === 'l') && graphScale > 0.125) {
graphScale /= 2
}
})
drawHeader()
// setInterval(drawHeader, 1000);
drawFooter()
graph = blessed.box({
top: 1,
left: 'left',
width: '100%',
height: '50%',
content: '',
fg: loadedTheme.chart.fg,
tags: true,
border: loadedTheme.chart.border
})
screen.append(graph)
let graph2appended = false
const createBottom = () => {
if (graph2appended) {
screen.remove(graph2)
//screen.remove(graph)
screen.remove(processList)
}
graph2appended = true
graph2 = blessed.box({
top: graph.height + 1,
left: 'left',
width: '50%',
height: graph.height - 2,
content: '',
fg: loadedTheme.chart.fg,
tags: true,
border: loadedTheme.chart.border
})
screen.append(graph2)
processList = blessed.box({
top: graph.height + 1,
left: '50%',
width: screen.width - graph2.width,
height: graph.height - 2,
keys: true,
mouse: cli.mouse,
fg: loadedTheme.table.fg,
tags: true,
border: loadedTheme.table.border
})
screen.append(processList)
processListSelection = blessed.list({
height: processList.height - 3,
top: 1,
width: processList.width - 2,
left: 0,
keys: true,
vi: true,
search (jump) {
// @TODO
// jump('string of thing to jump to');
},
style: loadedTheme.table.items,
mouse: cli.mouse
})
processList.append(processListSelection)
processListSelection.focus()
drawFooter()
screen.render()
}
screen.on('resize', () => {
createBottom()
})
createBottom()
//////////////////////////////////////////////////////////////////////////////////
graph2 = blessed.box({
top: graph.height + 1,
left: 'left',
width: '50%',
height: graph.height - 2,
content: '',
fg: loadedTheme.chart.fg,
tags: true,
border: loadedTheme.chart.border
})
screen.append(graph2)
processList = blessed.box({
top: graph.height + 1,
left: '50%',
width: screen.width - graph2.width,
height: graph.height - 2,
keys: true,
mouse: cli.mouse,
fg: loadedTheme.table.fg,
tags: true,
border: loadedTheme.table.border
})
screen.append(processList)
processListSelection = blessed.list({
height: processList.height - 3,
top: 1,
width: processList.width - 2,
left: 0,
keys: true,
vi: true,
search (jump) {
// @TODO
// jump('string of thing to jump to');
},
style: loadedTheme.table.items,
mouse: cli.mouse
})
processList.append(processListSelection)
processListSelection.focus()
//////////////////////////////////////////////////////////////////////////////////
treelist = blessed.box({
top: graph.height + 1,
left: '50%',
width: screen.width - graph2.width,
height: graph.height -2,
keys: true,
mouse: cli.mouse,
fg: loadedTheme.table.fg,
tags: true,
border: loadedTheme.table.border
})
var list1 = []
processListSelectiontree = blessed.list({
height: processList.height - 3,
top: 1,
width: processList.width - 2,
left: 0,
keys: true,
vi: true,
search (jump) {
// @TODO
// jump('string of thing to jump to');
},
items:list1,
style: loadedTheme.table.items,
mouse: cli.mouse
})
//processListSelectiontree.setItems(list1)
screen.on('keypress', (ch, key) => {
if(key.name === 't'){
screen.remove(processList)
let selectedProcess = processListSelection.getItem(processListSelection.selected).content
selectedProcess = selectedProcess.slice(0, 7).trim()
//console.log(selectedProcess)
//let selectedProcess = '13864'
var child_process = require("child_process");
try{
var test = child_process.execSync(`pgrep -P ${selectedProcess}`)
test = test.toString()
}
catch(err){
var test = ''
}
const lines = test.split('\n')
list1 = []
for (const line in lines) {
const currentLine = lines[line].trim().replace(' ', ' ')
const words = currentLine.split(' ')
list1.push(words[0])
}
processListSelectiontree.setItems(list1)
screen.append(treelist)
}
})
treelist.append(processListSelectiontree)
processListSelectiontree.focus()
processListSelectiontree.setItems(list1)
//////----------/////////
treelist1 = blessed.box({
top: graph.height + 1,
left: '50%',
width: screen.width - graph2.width,
height: graph.height -2,
keys: true,
mouse: cli.mouse,
fg: loadedTheme.table.fg,
tags: true,
border: loadedTheme.table.border
})
var list2 = []
processListSelectiontree_1 = blessed.list({
height: processList.height - 3,
top: 1,
width: processList.width - 2,
left: 0,
keys: true,
vi: true,
search (jump) {
// @TODO
// jump('string of thing to jump to');
},
items:list2,
style: loadedTheme.table.items,
mouse: cli.mouse
})
//processListSelectiontree_1.setItems(list2)
screen.on('keypress', (ch, key) => {
if(key.name === 'v'){
screen.remove(processList)
let selectedProcess = processListSelection.getItem(processListSelection.selected).content
selectedProcess = selectedProcess.slice(0, 7).trim()
//console.log(selectedProcess)
//let selectedProcess = '13864'
var child_process = require("child_process");
try{
var test = child_process.execSync(`vmmap -summary ${selectedProcess} | grep Stack`)
test = test.toString()
}
catch(err){
var test = ''
}
const lines = test.split('\n')
list2 = []
for (const line in lines) {
var currentLine = lines[line].trim().replace(' ', '')
var words = currentLine.split(' ')
//console.log(currentLine)
list2.push(currentLine.slice(40,48))
}
processListSelectiontree_1.setItems(list2)
screen.append(treelist1)
}
})
treelist1.append(processListSelectiontree_1)
processListSelectiontree_1.focus()
processListSelectiontree_1.setItems(list2)
//////----------/////////
//////----------/////////
treelist2 = blessed.box({
top: graph.height + 1,
left: '50%',
width: screen.width - graph2.width,
height: graph.height -2,
keys: true,
mouse: cli.mouse,
fg: loadedTheme.table.fg,
tags: true,
border: loadedTheme.table.border
})
var list3 = []
processListSelectiontree_2 = blessed.list({
height: processList.height - 3,
top: 1,
width: processList.width - 2,
left: 0,
keys: true,
vi: true,
search (jump) {
// @TODO
// jump('string of thing to jump to');
},
items:list3,
style: loadedTheme.table.items,
mouse: cli.mouse
})
//processListSelectiontree_1.setItems(list2)
screen.on('keypress', (ch, key) => {
if(key.name === 'l'){
screen.remove(processList)
let selectedProcess = processListSelection.getItem(processListSelection.selected).content
selectedProcess = selectedProcess.slice(0, 7).trim()
//console.log(selectedProcess)
//let selectedProcess = '13864'
var child_process = require("child_process");
try{
var test = child_process.execSync(`vmmap -summary ${selectedProcess} | grep Writable`)
test = test.toString()
}
catch(err){
var test = ''
}
const lines = test.split('\n')
list3 = []
for (const line in lines) {
var currentLine = lines[line].trim().replace(' ', '')
var words = currentLine.split(' ')
var x = currentLine.slice(59,63)
var match = x.matchAll(/(\d+\.\d+(M|G))/)
var match1 = /(\d+\.\d+(M|G))/.exec(x)
//console.log(match1)
list3.push(currentLine.slice(55,65))
}
processListSelectiontree_2.setItems(list3)
screen.append(treelist2)
}