From 24b56af2d633ec734108e10c2c293d6af763e37d Mon Sep 17 00:00:00 2001 From: M09Ic Date: Wed, 8 Feb 2023 19:17:42 +0800 Subject: [PATCH] =?UTF-8?q?-F=E6=96=B0=E5=A2=9E=E4=BB=8Estdin=E4=B8=AD?= =?UTF-8?q?=E8=AF=BB,=20=E5=B9=B6=E6=B7=BB=E5=8A=A0=E9=A2=9C=E8=89=B2?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/cmd.go | 2 +- internal/format.go | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/cmd/cmd.go b/cmd/cmd.go index c4d4109..b29b86e 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -50,7 +50,7 @@ func Spray() { } if option.Format != "" { - internal.Format(option.Format) + internal.Format(option.Format, !option.NoColor) os.Exit(0) } diff --git a/internal/format.go b/internal/format.go index 12fbab9..40b1d3b 100644 --- a/internal/format.go +++ b/internal/format.go @@ -6,10 +6,18 @@ import ( "github.com/chainreactors/logs" "github.com/chainreactors/spray/pkg" "io/ioutil" + "os" ) -func Format(filename string) { - content, err := ioutil.ReadFile(filename) +func Format(filename string, color bool) { + var content []byte + var err error + if filename == "stdin" { + content, err = ioutil.ReadAll(os.Stdin) + } else { + content, err = ioutil.ReadFile(filename) + } + if err != nil { return } @@ -24,6 +32,10 @@ func Format(filename string) { results = append(results, &result) } for _, result := range results { - logs.Log.Info(result.String()) + if color { + logs.Log.Info(result.ColorString()) + } else { + logs.Log.Info(result.String()) + } } }