@@ -50,6 +50,7 @@ import (
50
50
// do nothing.
51
51
func drawTUI (objs counterObjects , startTime time.Time ) {
52
52
app := tview .NewApplication ()
53
+ tableSort := bitrateSort
53
54
54
55
// packet statistics
55
56
statsTable := tview .NewTable ().
@@ -64,9 +65,25 @@ func drawTUI(objs counterObjects, startTime time.Time) {
64
65
65
66
statsTable .SetInputCapture (func (event * tcell.EventKey ) * tcell.EventKey {
66
67
switch event .Rune () {
68
+ case '0' :
69
+ tableSort = bitrateSort
70
+ statsTable .Select (0 , 0 )
71
+ case '1' :
72
+ tableSort = packetSort
73
+ statsTable .Select (0 , 0 )
74
+ case '2' :
75
+ tableSort = bytesSort
76
+ statsTable .Select (0 , 0 )
77
+ case '3' :
78
+ tableSort = srcIPSort
79
+ statsTable .Select (0 , 0 )
80
+ case '4' :
81
+ tableSort = dstIPSort
82
+ statsTable .Select (0 , 0 )
67
83
case 'q' , 'x' , 'Q' , 'X' :
68
84
app .Stop ()
69
- case 'r' , 'R' , 'l' , 'L' :
85
+ case 'r' , 'R' :
86
+ statsTable .Select (0 , 0 )
70
87
app .ForceDraw ()
71
88
}
72
89
@@ -90,16 +107,16 @@ func drawTUI(objs counterObjects, startTime time.Time) {
90
107
// navigation
91
108
naviView := tview .NewTextView ().
92
109
SetTextColor (tcell .ColorYellow )
93
- naviView .SetText ("Use cursor keys to move through the table. Press 'q' or 'x' to exit. Press 'r' or 'l ' for a redraw ." )
110
+ naviView .SetText ("Use cursor keys to move through the table. Press 'q' or 'x' to exit, 'r' for a jump to the beginning and a redraw. \n Press '0' for bitrate desc sort, '1' for packet desc sort, '2 ' for bytes desc sort, '3' for source IP asc sort, '4' for destination IP asc sort ." )
94
111
95
112
// grid layout
96
- grid := tview .NewGrid ().SetRows (2 , 0 , 2 ).
113
+ grid := tview .NewGrid ().SetRows (2 , 0 , 3 ).
97
114
AddItem (infoView , 0 , 0 , 1 , 1 , 0 , 0 , false ).
98
115
AddItem (statsTable , 1 , 0 , 1 , 1 , 0 , 0 , true ).
99
116
AddItem (naviView , 2 , 0 , 1 , 1 , 0 , 0 , false )
100
117
101
118
// start the update loop
102
- go updateStatsTable (app , statsTable , objs , startTime )
119
+ go updateStatsTable (app , statsTable , & tableSort , objs , startTime )
103
120
104
121
_ = app .SetRoot (grid , true ).
105
122
SetFocus (statsTable ).
@@ -125,7 +142,9 @@ func drawTUI(objs counterObjects, startTime time.Time) {
125
142
//
126
143
// Note that the table is cleared and recreated on each iteration, so any cell
127
144
// attributes are lost on each iteration.
128
- func updateStatsTable (app * tview.Application , table * tview.Table , objs counterObjects , startTime time.Time ) {
145
+ func updateStatsTable (app * tview.Application , table * tview.Table , tableSort * func (stats []statEntry ),
146
+ objs counterObjects , startTime time.Time ,
147
+ ) {
129
148
headers := []string {
130
149
"bitrate" , // column 0
131
150
"packets" , // column 1
@@ -153,7 +172,7 @@ func updateStatsTable(app *tview.Application, table *tview.Table, objs counterOb
153
172
})
154
173
}
155
174
156
- m , _ := processMap (objs .PktCount , startTime )
175
+ m , _ := processMap (objs .PktCount , startTime , * tableSort )
157
176
158
177
for i , v := range m {
159
178
// populate bitrate, packets, bytes and proto
0 commit comments