From 462027547adf9064184b5e52054c17c70e1c8ed9 Mon Sep 17 00:00:00 2001 From: Wendell Sun Date: Wed, 24 Nov 2021 13:45:59 +0800 Subject: [PATCH] add prefix for enum type --- fill/proto/interactive_filler.go | 1 + prompt/prompt.go | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/fill/proto/interactive_filler.go b/fill/proto/interactive_filler.go index cec67758..1730d6e1 100644 --- a/fill/proto/interactive_filler.go +++ b/fill/proto/interactive_filler.go @@ -152,6 +152,7 @@ func (r *resolver) resolveField(f *desc.FieldDescriptor) error { ) return msgr.resolve() case descriptorpb.FieldDescriptorProto_TYPE_ENUM: + fmt.Printf("%s%s%s\n", r.color.ForegroundANSI(), f.GetName(), "\033[0m") return r.resolveEnum(f.GetEnumType()) case descriptorpb.FieldDescriptorProto_TYPE_DOUBLE: converter = func(v string) (interface{}, error) { return strconv.ParseFloat(v, 64) } diff --git a/prompt/prompt.go b/prompt/prompt.go index 72e517ab..06e2d980 100644 --- a/prompt/prompt.go +++ b/prompt/prompt.go @@ -2,6 +2,7 @@ package prompt import ( + "fmt" "io" "os" @@ -53,6 +54,15 @@ func (c *Color) NextVal() Color { return (*c + 1) % 16 } +func (c Color) ForegroundANSI() string { + return fmt.Sprintf("\033[%sm", foregroundANSIColors[c]) +} + +var foregroundANSIColors = map[Color][]byte{ + ColorInitial: {'3', '2'}, + ColorBlue: {'9', '4'}, +} + type Prompt interface { // Input reads keyboard input. // If ctrl+d is entered, Input returns io.EOF.