From a72922386f52cb79bab4d406aeda26371a07cf2a Mon Sep 17 00:00:00 2001 From: congqixia Date: Thu, 26 Sep 2024 11:55:07 +0800 Subject: [PATCH] fix: [Cherry-pick] Remove unused Unsafe reflection code (#315) (#316) Cherry-pick from master pr: #315 Related to #314 Signed-off-by: Congqi Xia --- bapps/go_prompt.go | 3 ++- bapps/go_prompt_parser.go | 19 +------------------ 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/bapps/go_prompt.go b/bapps/go_prompt.go index 84c0770f..bacfe346 100644 --- a/bapps/go_prompt.go +++ b/bapps/go_prompt.go @@ -64,7 +64,8 @@ func NewPromptApp(config *configs.Config, opts ...AppOption) BApp { pa.sugguestHistory = !pa.sugguestHistory }, }), - HandleFD, + // setup InputParser with `TearDown` overrided + prompt.OptionParser(NewBInputParser()), ) pa.prompt = p return pa diff --git a/bapps/go_prompt_parser.go b/bapps/go_prompt_parser.go index 096dd8d5..78bb980e 100644 --- a/bapps/go_prompt_parser.go +++ b/bapps/go_prompt_parser.go @@ -3,8 +3,6 @@ package bapps import ( "os" "os/exec" - "reflect" - "unsafe" "github.com/c-bata/go-prompt" ) @@ -24,24 +22,9 @@ func (t *bInputParser) TearDown() error { return nil } -func NewInputParser(parser *prompt.PosixParser) *bInputParser { +func NewBInputParser() *bInputParser { p := &bInputParser{ PosixParser: prompt.NewStandardInputParser(), } return p } - -func HandleFD(p *prompt.Prompt) error { - in, ok := GetUnexportedField(reflect.ValueOf(p).Elem().FieldByName("in")).(*prompt.PosixParser) - if !ok { - // failed to reflect - return nil - } - - return prompt.OptionParser(NewInputParser(in))(p) -} - -func GetUnexportedField(field reflect.Value) interface{} { - // nolint - return reflect.NewAt(field.Type(), unsafe.Pointer(field.UnsafeAddr())).Elem().Interface() -}