@@ -27,7 +27,7 @@ type packetsTablemodel struct {
27
27
28
28
func buildTable (rows []table.Row , terminalWidth int ) table.Model {
29
29
return table .New ([]table.Column {
30
- table .NewColumn (columnKeyID , "#" , (2 * terminalWidth )/ 100 ),
30
+ table .NewColumn (columnKeyID , "#" , (3 * terminalWidth )/ 100 ),
31
31
table .NewColumn (columnKeyDate , "Date" , (8 * terminalWidth )/ 100 ),
32
32
table .NewColumn (columnKeySource , "Source" , (20 * terminalWidth )/ 100 ),
33
33
table .NewColumn (columnKeyDestination , "Destination" , (20 * terminalWidth )/ 100 ),
@@ -42,7 +42,7 @@ func buildTable(rows []table.Row, terminalWidth int) table.Model {
42
42
}
43
43
44
44
func newPacketsTable (max int , terminalWidth int ) packetsTablemodel {
45
- rows := make ([]table.Row , 0 , max )
45
+ rows := make ([]table.Row , max )
46
46
47
47
return packetsTablemodel {
48
48
maxRows : max ,
@@ -82,15 +82,26 @@ func (m packetsTablemodel) View() string {
82
82
}
83
83
84
84
func (m * packetsTablemodel ) addRows (packets []sockets.NetworkPacket ) {
85
- for _ , np := range packets {
86
- if len (m .cachedRows ) >= m .maxRows {
87
- m .cachedRows = m .cachedRows [1 :]
85
+ lp := len (packets )
86
+ lc := len (m .cachedRows )
87
+
88
+ if (lp + lc ) > m .maxRows {
89
+ newCache := make ([]table.Row , 0 , m .maxRows )
90
+ if lp > m .maxRows {
91
+ packets = packets [lp - m .maxRows :]
92
+ } else {
93
+ oldToKeep := m .maxRows - lp
94
+ newCache = append (newCache , m .cachedRows [lc - oldToKeep :]... )
88
95
}
96
+ m .cachedRows = newCache
97
+ }
98
+
99
+ for _ , np := range packets {
89
100
m .counter += 1
90
101
91
102
newRow := table .NewRow (table.RowData {
92
103
columnKeyID : m .counter ,
93
- columnKeyDate : time .Now ().Local ().Format (time .Stamp ),
104
+ columnKeyDate : time .Now ().Local ().Format (time .TimeOnly ),
94
105
columnKeySource : np .Source (),
95
106
columnKeyDestination : np .Destination (),
96
107
columnKeyInfo : np .Info (),
0 commit comments