mirror of
https://github.com/jixishi/SerialTerminalForWindowsTerminal.git
synced 2026-06-16 00:52:44 +00:00
refactor: split termapp into proper internal packages
Replace monolithic internal/termapp with proper separation: - internal/app: App struct, lifecycle, output loops - internal/command: CommandHost interface, Dispatcher, handlers - internal/tui: Model, hotkeys, panels, render (with panelError + border fixes) - internal/console: RunConsole, escape parsing, entry point logic - cmd/serialterminal: thin main() calling console.Run() Eliminate global vars (cfg, sess, out) via dependency injection. Break App->CommandDispatcher cycle via CommandHost interface. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
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", "stats"}
|
||||
}
|
||||
|
||||
if len(args) == 3 && args[1] == "add" {
|
||||
return []string{"tcp", "udp"}
|
||||
}
|
||||
|
||||
if len(args) == 4 && args[1] == "update" {
|
||||
return []string{"tcp", "udp"}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user