From 56be0c61cae1ce6e653fefcca974e1be371a6a91 Mon Sep 17 00:00:00 2001 From: M09Ic Date: Sun, 21 May 2023 14:10:31 +0800 Subject: [PATCH] revolt output behavior, making it consistent with the original. --- cmd/root.go | 6 ++++-- pkg/entity/entity.go | 19 ++++++++----------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 660ec0e..d37113d 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -77,14 +77,16 @@ Find document on: https://github.com/zu1k/nali if isJson { _, _ = fmt.Fprintf(color.Output, "%s", entity.ParseLine(line).Json()) } else { - _, _ = fmt.Fprintf(color.Output, "%s\n", entity.ParseLine(line).ColorString()) + _, _ = fmt.Fprintf(color.Output, "%s", entity.ParseLine(line).ColorString()) } } } else { if isJson { _, _ = fmt.Fprintf(color.Output, "%s", entity.ParseLine(strings.Join(args, " ")).Json()) } else { - _, _ = fmt.Fprintf(color.Output, "%s\n", entity.ParseLine(strings.Join(args, " ")).ColorString()) + for _, line := range args { + _, _ = fmt.Fprintf(color.Output, "%s\n", entity.ParseLine(line).ColorString()) + } } } }, diff --git a/pkg/entity/entity.go b/pkg/entity/entity.go index d3946a8..19b97dc 100644 --- a/pkg/entity/entity.go +++ b/pkg/entity/entity.go @@ -68,24 +68,21 @@ func (es Entities) String() string { func (es Entities) ColorString() string { var line strings.Builder for _, e := range es { + s := e.Text switch e.Type { case TypeIPv4: - line.WriteString(color.GreenString(e.Text)) + s = color.GreenString(e.Text) case TypeIPv6: - line.WriteString(color.BlueString(e.Text)) + s = color.BlueString(e.Text) case TypeDomain: - line.WriteString(color.YellowString(e.Text)) - default: - line.WriteString(e.Text) + s = color.YellowString(e.Text) } - if e.Type != TypePlain { - if len(e.InfoText) > 0 { - line.WriteString(" [" + color.RedString(e.InfoText) + "] ") - } + if e.Type != TypePlain && len(e.InfoText) > 0 { + s += " [" + color.RedString(e.InfoText) + "] " } - line.WriteString("\n") + line.WriteString(s) } - return strings.TrimSpace(line.String()) + return line.String() } func (es Entities) Json() string {