123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- 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")
- }
- }
|