1
0
mirror of https://github.com/zu1k/nali.git synced 2025-01-23 21:59:02 +08:00
nali/internal/app/command.go

32 lines
702 B
Go
Raw Normal View History

2020-08-10 13:01:43 +08:00
package app
import (
"bufio"
2021-08-03 07:54:35 +08:00
"fmt"
2020-08-10 13:01:43 +08:00
"os"
2021-08-03 07:54:35 +08:00
"strings"
2020-08-10 13:01:43 +08:00
2022-02-08 18:01:55 +08:00
"github.com/fatih/color"
2021-08-03 07:54:35 +08:00
"github.com/zu1k/nali/internal/entity"
2020-08-10 13:01:43 +08:00
"golang.org/x/text/encoding/simplifiedchinese"
"golang.org/x/text/transform"
)
2021-08-03 07:54:35 +08:00
func Root(args []string, needTransform bool) {
2020-08-10 13:01:43 +08:00
if len(args) == 0 {
stdin := bufio.NewScanner(os.Stdin)
for stdin.Scan() {
line := stdin.Text()
2020-08-10 13:29:21 +08:00
if needTransform {
2020-08-10 13:01:43 +08:00
line, _, _ = transform.String(simplifiedchinese.GBK.NewDecoder(), line)
}
if line == "quit" || line == "exit" {
return
}
2022-02-08 18:01:55 +08:00
fmt.Fprintf(color.Output, "%s\n", entity.ParseLine(line).ColorString())
2020-08-10 13:01:43 +08:00
}
} else {
2022-02-08 18:01:55 +08:00
fmt.Fprintf(color.Output, "%s\n", entity.ParseLine(strings.Join(args, " ")).ColorString())
2020-08-10 13:01:43 +08:00
}
}