Add 's' shortcut to switch next view mode on the fly
This commit is contained in:
parent
61117145b1
commit
0f3c3e93a6
|
|
@ -76,6 +76,15 @@ Flags:
|
|||
-v, --version version for sniffer
|
||||
```
|
||||
|
||||
**Shortcuts**
|
||||
|
||||
| Keys | Description |
|
||||
| ---- | ----------- |
|
||||
| <kbd>Space</kbd> | pause refreshing |
|
||||
| <kbd>Tab</kbd> | rearrange tables |
|
||||
| <kbd>s</kbd> | switch next view mode |
|
||||
| <kbd>q</kbd> / <kbd>Ctrl</kbd>+<kbd>C</kbd> | quit |
|
||||
|
||||
## View Mode
|
||||
|
||||
***Bytes Mode:*** display traffic stats in bytes by the Table widget.
|
||||
|
|
|
|||
2
cli.go
2
cli.go
|
|
@ -6,7 +6,7 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
const version = "v0.1.1"
|
||||
const version = "v0.2.0"
|
||||
|
||||
func NewApp() *cobra.Command {
|
||||
defaultOpts := DefaultOptions()
|
||||
|
|
|
|||
|
|
@ -91,16 +91,6 @@ func (lc *lsofConn) getOpenSockets(pids ...int32) (OpenSockets, error) {
|
|||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if len(pids) > 0 {
|
||||
pid, err := strconv.Atoi(fields[1])
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if !set[int32(pid)] {
|
||||
continue
|
||||
}
|
||||
}
|
||||
sockets[LocalSocket{IP: ipport[0], Port: uint16(port), Protocol: ProtoTCP}] = procName
|
||||
|
||||
case "UDP":
|
||||
|
|
|
|||
5
pcap.go
5
pcap.go
|
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
|
@ -139,6 +140,10 @@ func (c *PcapClient) getAvailableDevices() error {
|
|||
}
|
||||
}
|
||||
|
||||
if len(c.handlers) == 0 {
|
||||
return errors.New("no available devices found")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
12
sniffer.go
12
sniffer.go
|
|
@ -85,6 +85,14 @@ func NewSniffer(opts Options) (*Sniffer, error) {
|
|||
}, nil
|
||||
}
|
||||
|
||||
func (s *Sniffer) SwitchViewMode() {
|
||||
s.opts.ViewMode = (s.opts.ViewMode + 1) % 3
|
||||
s.statsManager = NewStatsManager(s.opts)
|
||||
|
||||
s.ui.Close()
|
||||
s.ui = NewUIComponent(s.opts)
|
||||
}
|
||||
|
||||
func (s *Sniffer) Start() {
|
||||
events := termui.PollEvents()
|
||||
s.Refresh()
|
||||
|
|
@ -102,6 +110,8 @@ func (s *Sniffer) Start() {
|
|||
case "<Resize>":
|
||||
payload := e.Payload.(termui.Resize)
|
||||
s.ui.viewer.Resize(payload.Width, payload.Height)
|
||||
case "s", "S":
|
||||
s.SwitchViewMode()
|
||||
case "q", "Q", "<C-c>":
|
||||
return
|
||||
}
|
||||
|
|
@ -115,9 +125,9 @@ func (s *Sniffer) Start() {
|
|||
}
|
||||
|
||||
func (s *Sniffer) Close() {
|
||||
s.ui.Close()
|
||||
s.pcapClient.Close()
|
||||
s.dnsResolver.Close()
|
||||
s.ui.Close()
|
||||
}
|
||||
|
||||
func (s *Sniffer) Refresh() {
|
||||
|
|
|
|||
2
ui.go
2
ui.go
|
|
@ -76,7 +76,7 @@ func (u Unit) Ratio() float64 {
|
|||
}
|
||||
|
||||
func newFooter() *widgets.Paragraph {
|
||||
return newParagraph("Press <Space> to pause, <q>/<Ctrl+C> to exit. Use <Tab> to rearrange tables")
|
||||
return newParagraph("Press <Space> to pause, <q>/<Ctrl+C> to exit, <s> to switch mode. Use <Tab> to rearrange tables")
|
||||
}
|
||||
|
||||
func newParagraph(text string) *widgets.Paragraph {
|
||||
|
|
|
|||
Loading…
Reference in New Issue