From be3b6cbd8dd2fd99315404b909fd958307c42c8f Mon Sep 17 00:00:00 2001 From: Tyler McGoffin Date: Tue, 8 Oct 2024 16:03:14 -0700 Subject: [PATCH] Make the X in the error message red and print with io writer --- pkg/cmd/issue/create/create.go | 2 +- pkg/cmd/pr/create/create.go | 2 +- pkg/cmd/pr/shared/survey.go | 7 +++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pkg/cmd/issue/create/create.go b/pkg/cmd/issue/create/create.go index 82d4ab133..f51cde4c9 100644 --- a/pkg/cmd/issue/create/create.go +++ b/pkg/cmd/issue/create/create.go @@ -222,7 +222,7 @@ func createRun(opts *CreateOptions) (err error) { defer prShared.PreserveInput(opts.IO, &tb, &err)() if opts.Title == "" { - err = prShared.TitleSurvey(opts.Prompter, &tb) + err = prShared.TitleSurvey(opts.Prompter, opts.IO, &tb) if err != nil { return } diff --git a/pkg/cmd/pr/create/create.go b/pkg/cmd/pr/create/create.go index 7e893395c..1242af2c5 100644 --- a/pkg/cmd/pr/create/create.go +++ b/pkg/cmd/pr/create/create.go @@ -379,7 +379,7 @@ func createRun(opts *CreateOptions) (err error) { } else { if !opts.TitleProvided { - err = shared.TitleSurvey(opts.Prompter, state) + err = shared.TitleSurvey(opts.Prompter, opts.IO, state) if err != nil { return } diff --git a/pkg/cmd/pr/shared/survey.go b/pkg/cmd/pr/shared/survey.go index a059b288c..2ee343bfb 100644 --- a/pkg/cmd/pr/shared/survey.go +++ b/pkg/cmd/pr/shared/survey.go @@ -110,7 +110,7 @@ func BodySurvey(p Prompt, state *IssueMetadataState, templateContent string) err return nil } -func TitleSurvey(p Prompt, state *IssueMetadataState) error { +func TitleSurvey(p Prompt, io *iostreams.IOStreams, state *IssueMetadataState) error { var err error result := "" for result == "" { @@ -119,7 +119,10 @@ func TitleSurvey(p Prompt, state *IssueMetadataState) error { return err } if result == "" { - fmt.Println("X Title cannot be blank.") + colorizeRed := io.ColorScheme().ColorFromString("red") + msg := fmt.Sprintf("%s Title cannot be blank.", colorizeRed("X")) + // For some reason, only Fprintln and Println work here. I can't use Fprintf or Printf to eliminate the line above + fmt.Fprintln(io.ErrOut, msg) } }