package main import ( "fmt" "github.com/chzyer/readline" "strings" ) // 开发指令在控制台操作屏 func lcCmdServer() { rl, err := readline.New("> ") if err != nil { fmt.Println("start cmd server Error:", err) return } defer rl.Close() for { var line []byte _, err := rl.Readline() if err != nil { fmt.Println("read line Error:", err) break } // 判断输入是否以"lc"作为前缀 if strings.HasPrefix(string(line), "lc") { args := strings.Fields(string(line)) // 将输入按空格分割成多个字段 if len(args) >= 2 { command := args[1] switch command { case "rm": handleRmCommand(args[2:]) case "text": handleTextCommand(args[2:]) default: fmt.Println("Unknown command:", command) } } else { fmt.Println("Missing command") } } else { fmt.Println("Invalid command") } } } func handleRmCommand(args []string) { // 处理rm指令 for _, arg := range args { fmt.Println("Deleting:", arg) // 执行删除操作... } } func handleTextCommand(args []string) { // 处理text指令 if len(args) > 0 { text := strings.Join(args, " ") fmt.Println("Text:", text) // 执行文本处理操作... } else { fmt.Println("Missing text argument") } }