Files
JiXieShi 30d6c2bc3c feat: add TCP Server, UDP Server, and COM port forwarding modes
Extend Mode constants (3=TCPServer, 4=UDPServer, 5=COMPort) with
explicit values. Refactor Target to support multiple connection types
(listener+conns map, packetConn, serialPort). Add acceptLoop,
readLoopPacket, readLoopSerial. Mode-aware Broadcast dispatches to
all accepted conns (TCP-S), known remotes (UDP-S), or serial port.
Update flag help, command completions, and TUI panel hints.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-23 23:10:02 +08:00

68 lines
1.5 KiB
Go

package command
import "strings"
func completeFirstToken(line, token string, cands []string) (string, []string) {
matches := filterPrefix(cands, token)
if len(matches) == 0 {
return line, nil
}
if len(matches) == 1 {
prefix := strings.TrimSuffix(line, token)
return prefix + matches[0] + " ", matches
}
return line, matches
}
func filterPrefix(cands []string, cur string) []string {
if cur == "" {
return append([]string{}, cands...)
}
res := make([]string, 0, len(cands))
for _, c := range cands {
if strings.HasPrefix(strings.ToLower(c), strings.ToLower(cur)) {
res = append(res, c)
}
}
return res
}
func completeForward(args []string) []string {
if len(args) <= 2 {
return []string{"list", "add", "remove", "enable", "disable", "update"}
}
if len(args) == 3 && args[1] == "add" {
return []string{"tcp", "udp", "tcp-s", "udp-s", "com"}
}
if len(args) == 4 && args[1] == "update" {
return []string{"tcp", "udp", "tcp-s", "udp-s", "com"}
}
return nil
}
func completePlugin(args []string) []string {
if len(args) <= 2 {
return []string{"list", "load", "unload", "enable", "disable", "reload"}
}
return nil
}
func completeMode(args []string) []string {
if len(args) <= 2 {
return []string{"show", "set"}
}
if len(args) == 3 && args[1] == "set" {
return []string{"in", "out", "end", "frame", "timestamp", "timefmt"}
}
if len(args) == 4 && args[1] == "set" && args[2] == "timestamp" {
return []string{"on", "off"}
}
return nil
}