forked from draios/sysdig
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcursescomponents.cpp
1913 lines (1617 loc) · 41.8 KB
/
cursescomponents.cpp
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
/*
Copyright (C) 2013-2015 Draios inc.
This file is part of sysdig.
sysdig is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation.
sysdig is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with sysdig. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <stdint.h>
#ifndef _WIN32
#include <unistd.h>
#include <algorithm>
#endif
#include <string>
#include <unordered_map>
#include <map>
#include <queue>
#include <vector>
#include <set>
using namespace std;
#include "sinsp.h"
#include "sinsp_int.h"
#include "../../driver/ppm_ringbuffer.h"
#include "filter.h"
#include "filterchecks.h"
#ifdef CSYSDIG
#ifndef NOCURSESUI
#include <curses.h>
#include "table.h"
#include "ctext.h"
#include "cursescomponents.h"
#include "cursestable.h"
#include "viewinfo.h"
#include "cursesui.h"
#include "utils.h"
///////////////////////////////////////////////////////////////////////////////
// curses_scrollable_list implementation
///////////////////////////////////////////////////////////////////////////////
curses_scrollable_list::curses_scrollable_list()
{
m_selct = 0;
m_firstrow = 0;
m_lastrow_selected = true;
}
void curses_scrollable_list::sanitize_selection(int32_t datasize)
{
if(m_firstrow > (datasize - (int32_t)m_h + 1))
{
m_firstrow = datasize - (int32_t)m_h + 1;
}
if(m_firstrow < 0)
{
m_firstrow = 0;
}
if(m_selct > datasize - 1)
{
m_selct = datasize - 1;
}
if(m_selct < 0)
{
m_selct = 0;
}
if(m_firstrow > m_selct)
{
m_firstrow = m_selct;
}
}
void curses_scrollable_list::selection_up(int32_t datasize)
{
if(m_selct > 0)
{
if(m_selct <= (int32_t)m_firstrow)
{
m_firstrow--;
}
m_selct--;
sanitize_selection(datasize);
}
m_lastrow_selected = false;
}
void curses_scrollable_list::selection_down(int32_t datasize)
{
if(m_selct < datasize - 1)
{
if(m_selct - m_firstrow > (int32_t)m_h - 3)
{
m_firstrow++;
}
m_selct++;
sanitize_selection(datasize);
}
if(m_selct == datasize - 1)
{
m_lastrow_selected = true;
}
}
void curses_scrollable_list::selection_pageup(int32_t datasize)
{
m_firstrow -= (m_h - 1);
m_selct -= (m_h - 1);
sanitize_selection(datasize);
m_lastrow_selected = false;
}
void curses_scrollable_list::selection_pagedown(int32_t datasize)
{
m_firstrow += (m_h - 1);
m_selct += (m_h - 1);
sanitize_selection(datasize);
if(m_selct == datasize - 1)
{
m_lastrow_selected = true;
}
}
void curses_scrollable_list::selection_home(int32_t datasize)
{
m_firstrow = 0;
m_selct = 0;
sanitize_selection(datasize);
m_lastrow_selected = false;
}
void curses_scrollable_list::selection_end(int32_t datasize)
{
m_firstrow = datasize - 1;
m_selct = datasize - 1;
sanitize_selection(datasize);
m_lastrow_selected = true;
}
void curses_scrollable_list::selection_goto(int32_t datasize, int32_t row)
{
if(row == -1 ||
row >= datasize)
{
ASSERT(false);
return;
}
m_firstrow = row - (m_h /2);
m_selct = row;
sanitize_selection(datasize);
}
///////////////////////////////////////////////////////////////////////////////
// curses_table_sidemenu implementation
///////////////////////////////////////////////////////////////////////////////
curses_table_sidemenu::curses_table_sidemenu(sidemenu_type type, sinsp_cursesui* parent, uint32_t selct, uint32_t width)
{
ASSERT(parent != NULL);
m_parent = parent;
m_h = m_parent->m_screenh - TABLE_Y_START - 1;
m_w = width;
m_y_start = TABLE_Y_START;
m_win = newwin(m_h, m_w, m_y_start, 0);
m_selct = selct;
m_selct_ori = m_selct;
m_type = type;
if(m_selct > (int32_t)(m_h - 2))
{
m_firstrow = m_selct - (int32_t)(m_h - 2);
}
}
curses_table_sidemenu::~curses_table_sidemenu()
{
delwin(m_win);
}
void curses_table_sidemenu::render()
{
int32_t j, k;
ASSERT(m_entries.size() != 0);
//
// Render window header
//
wattrset(m_win, m_parent->m_colors[sinsp_cursesui::PANEL_HEADER_FOCUS]);
wmove(m_win, 0, 0);
for(j = 0; j < (int32_t)m_w - 1; j++)
{
waddch(m_win, ' ');
}
// white space at the right
wattrset(m_win, m_parent->m_colors[sinsp_cursesui::PROCESS]);
waddch(m_win, ' ');
ASSERT(m_title != "");
wattrset(m_win, m_parent->m_colors[sinsp_cursesui::PANEL_HEADER_FOCUS]);
mvwaddnstr(m_win, 0, 0, m_title.c_str(), m_w);
//
// Render the rows
//
for(j = m_firstrow; j < MIN(m_firstrow + (int32_t)m_h - 1, (int32_t)m_entries.size()); j++)
{
if(j == m_selct)
{
wattrset(m_win, m_parent->m_colors[sinsp_cursesui::PANEL_HIGHLIGHT_FOCUS]);
}
else
{
wattrset(m_win, m_parent->m_colors[sinsp_cursesui::PROCESS]);
}
// clear the line
wmove(m_win, j - m_firstrow + 1, 0);
for(k = 0; k < (int32_t)m_w - 1; k++)
{
waddch(m_win, ' ');
}
// add the new line
mvwaddnstr(m_win, j - m_firstrow + 1, 0, m_entries.at(j).m_name.c_str(), m_w);
// put sorting order indicator at the right end of this row
if(m_parent->m_sidemenu_sorting_col == j)
{
wmove(m_win, j - m_firstrow + 1, m_w - 4);
char sort_order = m_parent->m_datatable->is_sorting_ascending() ? '^' : 'V';
waddch(m_win, '(');
waddch(m_win, sort_order);
waddch(m_win, ')');
}
// white space at the right
wattrset(m_win, m_parent->m_colors[sinsp_cursesui::PROCESS]);
wmove(m_win, j - m_firstrow + 1, m_w - 1);
waddch(m_win, ' ');
}
wrefresh(m_win);
}
//
// Update the view info page in the parent
//
void curses_table_sidemenu::update_view_info()
{
if(m_parent->m_viewinfo_page)
{
delete m_parent->m_viewinfo_page;
ASSERT(m_selct < (int32_t)m_entries.size());
m_parent->m_viewinfo_page = new curses_viewinfo_page(m_parent,
m_entries.at(m_selct).m_id,
TABLE_Y_START,
m_w,
m_parent->m_screenh - TABLE_Y_START - 1,
m_parent->m_screenw - m_w);
}
}
//
// Return true if the parent should handle the event
//
sysdig_table_action curses_table_sidemenu::handle_input(int ch)
{
int32_t prev_select;
int input;
switch(ch)
{
case KEY_F(1):
case KEY_F(4):
case KEY_F(5):
case KEY_F(6):
case KEY_F(7):
case 6:
return STA_NONE;
case '\n':
case '\r':
case KEY_ENTER:
ASSERT(m_selct < (int32_t)m_entries.size());
if(m_type == ST_VIEWS)
{
if(m_parent->m_spy_box == NULL)
{
m_parent->m_selected_view = m_entries.at(m_selct).m_id;
}
m_parent->m_selected_view_sidemenu_entry = m_selct;
} else if(m_type == ST_COLUMNS) {
m_parent->m_selected_view_sort_sidemenu_entry = m_selct;
}
else
{
m_parent->m_selected_action_sidemenu_entry = m_selct;
}
return STA_SWITCH_VIEW;
case KEY_BACKSPACE:
case 127:
case 27: // ESC
case KEY_RESIZE:
ASSERT(m_selct < (int32_t)m_entries.size());
if(m_type == ST_VIEWS)
{
if(m_parent->m_spy_box == NULL)
{
m_parent->m_selected_view = m_entries.at(m_selct).m_id;
}
m_parent->m_selected_view_sidemenu_entry = m_selct_ori;
return STA_SWITCH_VIEW;
}
else if(m_type == ST_COLUMNS)
{
m_parent->m_selected_view_sort_sidemenu_entry = m_selct_ori;
return STA_DESTROY_CHILD;
}
else
{
m_parent->m_selected_action_sidemenu_entry = m_selct_ori;
return STA_DESTROY_CHILD;
}
case KEY_UP:
if(m_entries.size() == 0)
{
return STA_NONE;
}
prev_select = m_selct;
selection_up((int32_t)m_entries.size());
input = getch();
if(input != -1)
{
return handle_input(input);
}
if(m_selct != prev_select)
{
update_view_info();
}
render();
return STA_NONE;
case KEY_DOWN:
if(m_entries.size() == 0)
{
return STA_NONE;
}
prev_select = m_selct;
selection_down((int32_t)m_entries.size());
input = getch();
if(input != -1)
{
return handle_input(input);
}
if(m_selct != prev_select)
{
update_view_info();
}
render();
return STA_NONE;
case KEY_PPAGE:
if(m_entries.size() == 0)
{
return STA_NONE;
}
prev_select = m_selct;
selection_pageup((int32_t)m_entries.size());
input = getch();
if(input != -1)
{
return handle_input(input);
}
if(m_selct != prev_select)
{
update_view_info();
}
render();
return STA_NONE;
case KEY_NPAGE:
if(m_entries.size() == 0)
{
return STA_NONE;
}
prev_select = m_selct;
selection_pagedown((int32_t)m_entries.size());
input = getch();
if(input != -1)
{
return handle_input(input);
}
if(m_selct != prev_select)
{
update_view_info();
}
render();
return STA_NONE;
case KEY_HOME:
if(m_entries.size() == 0)
{
return STA_NONE;
}
prev_select = m_selct;
selection_home((int32_t)m_entries.size());
input = getch();
if(input != -1)
{
return handle_input(input);
}
if(m_selct != prev_select)
{
update_view_info();
}
render();
return STA_NONE;
case KEY_END:
if(m_entries.size() == 0)
{
return STA_NONE;
}
prev_select = m_selct;
selection_end((int32_t)m_entries.size());
input = getch();
if(input != -1)
{
return handle_input(input);
}
if(m_selct != prev_select)
{
update_view_info();
}
render();
return STA_NONE;
case KEY_MOUSE:
{
if(m_entries.size() == 0)
{
return STA_NONE;
}
if(getmouse(&m_last_mevent) == OK)
{
//
// Bottom menu clicks are handled by the parent
//
if((uint32_t)m_last_mevent.y == m_parent->m_screenh - 1)
{
return STA_PARENT_HANDLE;
}
if(m_last_mevent.bstate & BUTTON1_CLICKED)
{
if((uint32_t)m_last_mevent.y > TABLE_Y_START &&
(uint32_t)m_last_mevent.y < TABLE_Y_START + m_h - 1)
{
//
// This is a click one of the menu entries. Update the selection.
//
m_selct = m_firstrow + (m_last_mevent.y - TABLE_Y_START - 1);
sanitize_selection((int32_t)m_entries.size());
update_view_info();
render();
}
}
else if(m_last_mevent.bstate & BUTTON1_DOUBLE_CLICKED)
{
if((uint32_t)m_last_mevent.y > TABLE_Y_START &&
(uint32_t)m_last_mevent.y < TABLE_Y_START + m_h - 1)
{
//
// This is a double click one of the menu entries.
// Update the selection.
//
m_selct = m_firstrow + (m_last_mevent.y - TABLE_Y_START - 1);
sanitize_selection((int32_t)m_entries.size());
render();
//
// This delay is here just as a lazy way to give the user the
// feeling that the row has been clicked
//
usleep(200000);
//
// Notify the parent that a selection has happened
//
ASSERT(m_selct < (int32_t)m_entries.size());
if(m_parent->m_spy_box == NULL)
{
m_parent->m_selected_view = m_entries.at(m_selct).m_id;
}
if(m_type == ST_VIEWS)
{
m_parent->m_selected_view_sidemenu_entry = m_selct;
}
else if(m_type == ST_COLUMNS)
{
m_parent->m_selected_view_sort_sidemenu_entry = m_selct;
}
else
{
m_parent->m_selected_action_sidemenu_entry = m_selct;
}
return STA_SWITCH_VIEW;
}
}
}
}
return STA_NONE;
default:
break;
}
return STA_PARENT_HANDLE;
}
///////////////////////////////////////////////////////////////////////////////
// curses_textbox implementation
///////////////////////////////////////////////////////////////////////////////
curses_textbox::curses_textbox(sinsp* inspector, sinsp_cursesui* parent, int32_t viz_type, sysdig_output_type sotype)
{
ASSERT(inspector != NULL);
ASSERT(parent != NULL);
m_parent = parent;
m_win = NULL;
m_ctext = NULL;
m_filter = NULL;
m_inspector = inspector;
n_prints = 0;
m_paused = false;
m_sidemenu = NULL;
m_viz_type = viz_type;
m_searcher = NULL;
m_has_searched = false;
m_last_progress_update_ts = 0;
ctext_config config;
m_win = newwin(m_parent->m_screenh - 4, m_parent->m_screenw, TABLE_Y_START + 1, 0);
m_ctext = new ctext(m_win);
m_ctext->get_config(&config);
config.m_buffer_size = 500000;
config.m_scroll_on_append = true;
config.m_bounding_box = true;
//
// visualization-type inits
//
if(m_viz_type == VIEW_ID_DIG)
{
if(sotype == OT_LATENCY)
{
if(m_parent->m_print_containers)
{
m_formatter = new sinsp_evt_formatter(m_inspector,
"*(latency=%evt.latency.human) (fd=%fd.name) %evt.num %evt.time %evt.cpu %container.name (%container.id) %proc.name (%thread.tid:%thread.vtid) %evt.dir %evt.type %evt.info");
}
else
{
m_formatter = new sinsp_evt_formatter(m_inspector,
"*(latency=%evt.latency.human) (fd=%fd.name) %evt.num %evt.time %evt.cpu %proc.name %thread.tid %evt.dir %evt.type %evt.info");
}
}
else if(sotype == OT_LATENCY_APP)
{
if(m_parent->m_print_containers)
{
m_formatter = new sinsp_evt_formatter(m_inspector,
"*(latency=%tracer.latency.human) %evt.num %evt.time %evt.cpu %container.name (%container.id) %proc.name (%thread.tid:%thread.vtid) %evt.dir %evt.type %evt.info");
}
else
{
m_formatter = new sinsp_evt_formatter(m_inspector,
"*(latency=%tracer.latency.human) %evt.num %evt.time %evt.cpu %proc.name %thread.tid %evt.dir %evt.type %evt.info");
}
}
else
{
if(m_parent->m_print_containers)
{
m_formatter = new sinsp_evt_formatter(m_inspector,
"*%evt.num %evt.time %evt.cpu %container.name (%container.id) %proc.name (%thread.tid:%thread.vtid) %evt.dir %evt.type %evt.info");
}
else
{
m_formatter = new sinsp_evt_formatter(m_inspector, DEFAULT_OUTPUT_STR);
}
}
config.m_do_wrap = false;
}
else
{
m_formatter = NULL;
config.m_do_wrap = true;
}
//
// set the config back
//
m_ctext->set_config(&config);
//
// Allocate the searcher
//
m_searcher = new ctext_search();
//
// If we're offline, disable screen refresh until we've parsed the file
//
if(!m_inspector->is_live())
{
m_ctext->ob_start();
}
//
// Initialize the inspector to capture longer buffers and format them in a
// readable way
//
m_inspector->set_buffer_format(sinsp_evt::PF_NORMAL);
m_inspector->set_snaplen(2000);
//
// Tell the parent to check for input more often
//
m_parent->m_input_check_period_ns = 100000;
//
// Initial screen refresh
//
render();
}
curses_textbox::~curses_textbox()
{
if(m_sidemenu)
{
delete m_sidemenu;
}
delwin(m_win);
delete m_ctext;
if(m_searcher)
{
delete m_searcher;
}
if(m_filter != NULL)
{
delete m_filter;
}
if(m_formatter)
{
delete m_formatter;
}
//
// Restore default snaplen and output formatting
//
m_inspector->set_snaplen(80);
m_inspector->set_buffer_format(sinsp_evt::PF_EOLS);
//
// Tell the parent to check for input at the usual frequency
//
m_parent->m_input_check_period_ns = UI_USER_INPUT_CHECK_PERIOD_NS;
}
void curses_textbox::set_filter(string filter)
{
sinsp_filter_compiler compiler(m_inspector, filter);
m_filter = compiler.compile();
}
void curses_textbox::print_no_data()
{
attrset(m_parent->m_colors[sinsp_cursesui::PROCESS]);
string wstr = "No Data For This Selection";
mvprintw(m_parent->m_screenh / 2,
m_parent->m_screenw / 2 - wstr.size() / 2,
wstr.c_str());
refresh();
}
void curses_textbox::process_event_spy(sinsp_evt* evt, int32_t next_res)
{
//
// Drop any non I/O event
//
ppm_event_flags eflags = evt->get_info_flags();
if(!(eflags & EF_READS_FROM_FD || eflags & EF_WRITES_TO_FD))
{
return;
}
//
// Get and validate the length
//
sinsp_evt_param* parinfo = evt->get_param(0);
ASSERT(parinfo->m_len == sizeof(int64_t));
int64_t len = *(int64_t*)parinfo->m_val;
if(len <= 0)
{
return;
}
//
// Get thread and fd
//
sinsp_threadinfo* m_tinfo = evt->get_thread_info();
if(m_tinfo == NULL)
{
return;
}
sinsp_fdinfo_t* m_fdinfo = evt->get_fd_info();
if(m_fdinfo == NULL)
{
return;
}
string fdname = m_fdinfo->m_name;
if(fdname == "")
{
fdname = "unnamed FD";
}
//
// Get the buffer
//
const char* resolved_argstr;
const char* argstr;
argstr = evt->get_param_value_str("data", &resolved_argstr, m_inspector->get_buffer_format());
if(argstr != NULL)
{
//
// Create the info string
//
string info_str = "------ ";
string dirstr;
string cnstr;
if(eflags & EF_READS_FROM_FD)
{
dirstr = "Read ";
cnstr = "from ";
wattrset(m_win, m_parent->m_colors[sinsp_cursesui::SPY_READ]);
}
else if(eflags & EF_WRITES_TO_FD)
{
wattrset(m_win, m_parent->m_colors[sinsp_cursesui::SPY_WRITE]);
dirstr = "Write ";
cnstr = "to ";
}
info_str += dirstr + to_string(len) +
"B " +
cnstr +
fdname +
" (" + m_tinfo->m_comm.c_str() + ")";
//
// Sanitize the info string
//
sanitize_string(info_str);
//
// Print the whole thing
//
m_ctext->printf("%s", info_str.c_str());
if(m_parent->m_print_containers)
{
wattrset(m_win, m_parent->m_colors[sinsp_cursesui::LED_COLOR]);
m_ctext->printf(" [%s]", m_inspector->m_container_manager.get_container_name(m_tinfo).c_str());
if(eflags & EF_READS_FROM_FD)
{
wattrset(m_win, m_parent->m_colors[sinsp_cursesui::SPY_READ]);
}
else if(eflags & EF_WRITES_TO_FD)
{
wattrset(m_win, m_parent->m_colors[sinsp_cursesui::SPY_WRITE]);
}
}
m_ctext->printf("\n");
m_ctext->printf("\n");
m_ctext->printf("%s", argstr);
}
m_ctext->printf("\n");
m_ctext->printf("\n");
n_prints++;
if(n_prints == 1)
{
render();
}
}
void curses_textbox::process_event_dig(sinsp_evt* evt, int32_t next_res)
{
if(!m_inspector->is_debug_enabled() && evt->get_category() & EC_INTERNAL)
{
return;
}
string line;
m_formatter->tostring(evt, &line);
m_ctext->printf("%s\n", line.c_str());
n_prints++;
if(n_prints == 1)
{
render();
}
uint64_t ts = evt->get_ts();
if(ts > (m_last_progress_update_ts + 100000000))
{
render();
m_last_progress_update_ts = ts;
}
}
void curses_textbox::process_event(sinsp_evt* evt, int32_t next_res)
{
//
// Check if this the end of the capture file, and if yes take note of that
//
if(next_res == SCAP_EOF)
{
m_parent->m_eof = 2;
m_ctext->jump_to_first_line();
m_ctext->ob_end();
render();
if(n_prints == 0)
{
print_no_data();
}
return;
}
//
// If the user pressed 'p', skip the event
//
if(m_paused)
{
return;
}
//
// Filter the event
//
if(m_filter)
{
if(!m_filter->run(evt))
{
return;
}
}
if(m_viz_type == VIEW_ID_SPY)
{
process_event_spy(evt, next_res);
}
else
{
process_event_dig(evt, next_res);
}
}
void curses_textbox::populate_sidemenu()
{
ASSERT(m_sidemenu != NULL);
m_entries.clear();
m_entries.push_back(sidemenu_list_entry("Dotted ASCII", -1));
m_entries.push_back(sidemenu_list_entry("Printable ASCII", -1));
m_entries.push_back(sidemenu_list_entry("Hex", -1));
m_sidemenu->set_entries(&m_entries);
switch(m_parent->m_spybox_text_format)
{
case sinsp_evt::PF_NORMAL:
m_sidemenu->m_selct = 0;
break;
case sinsp_evt::PF_EOLS:
m_sidemenu->m_selct = 1;
break;
case sinsp_evt::PF_HEXASCII:
m_sidemenu->m_selct = 2;
break;
case sinsp_evt::PF_JSON:
m_sidemenu->m_selct = 3;
break;
default:
ASSERT(false);
m_sidemenu->m_selct = 0;
break;
}
m_sidemenu->set_title("View As");
}
void curses_textbox::render_header()
{
move(2, 0);
attrset(m_parent->m_colors[sinsp_cursesui::FUNCTION_BAR]);
for(uint32_t j = 0; j < m_parent->m_screenw; j++)
{