Detect interfaces per platform; add macOS and single-interface support (closes #2)

Linux runs exactly as before when both bridge interfaces exist. When they do
not, the lone default-route interface is monitored, and a single interface now
draws a single UI pane instead of an empty second one.

macOS is newly supported: a running VPN tunnel (utun) is monitored as the
primary pane alongside the physical default-route interface, or the physical
interface alone when no VPN is up.

Detection lives in internal/netdetect: interface/route data types, pure
selection logic keyed on OS name, and route parsers, all unit-tested on Linux
for both platforms. Only the real route query and the per-platform TCP dial
binding (source address on Linux, IP_BOUND_IF on macOS) are build-tagged. Ping
argument construction is a pure, OS-keyed function. NewMonitor now takes a list
of interfaces.

Model: opus-4-8
This commit is contained in:
2026-09-21 06:53:39 +00:00
parent cf9dc39053
commit ef3c373a12
18 changed files with 933 additions and 85 deletions
+4 -6
View File
@@ -1,6 +1,3 @@
//go:build linux
// +build linux
package monitor
import (
@@ -345,10 +342,11 @@ func (m *Monitor) uiLoop(ctx context.Context) {
// Draw the runtime
Put(m.screen, 0, 3, "Runtime: "+time.Since(m.startTime).Round(time.Second).String(), CDefault)
// Draw interfaces
// Draw interfaces (one pane each; a single interface draws one pane)
y := 5
y = m.DrawInterface(m.screen, y, w, m.interfaceA)
_ = m.DrawInterface(m.screen, y, w, m.interfaceB)
for _, st := range m.interfaces {
y = m.DrawInterface(m.screen, y, w, st)
}
// Show the screen
m.screen.Show()