From 127d636b8aff05b9a9d3919cf8e4eefe2f72fb08 Mon Sep 17 00:00:00 2001 From: Ink33 Date: Fri, 30 Apr 2021 16:31:35 +0800 Subject: [PATCH] fix unexpected ReadPassword behavior in linux(#794) (cherry picked from commit a361366916013e7c47ee7a70910b1295ac18d3b5) --- main.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index 8667fc4..a4f2e91 100644 --- a/main.go +++ b/main.go @@ -8,9 +8,6 @@ import ( "encoding/base64" "encoding/hex" "fmt" - "github.com/Mrs4s/go-cqhttp/global/terminal" - rotatelogs "github.com/lestrrat-go/file-rotatelogs" - easy "github.com/t-tomalak/logrus-easy-formatter" "io" "io/ioutil" "net/http" @@ -25,18 +22,21 @@ import ( "syscall" "time" - "github.com/Mrs4s/go-cqhttp/server" + "github.com/Mrs4s/MiraiGo/binary" + "github.com/Mrs4s/MiraiGo/client" "github.com/guonaihong/gout" + jsoniter "github.com/json-iterator/go" + rotatelogs "github.com/lestrrat-go/file-rotatelogs" + log "github.com/sirupsen/logrus" + easy "github.com/t-tomalak/logrus-easy-formatter" "github.com/tidwall/gjson" "golang.org/x/crypto/pbkdf2" "golang.org/x/term" - "github.com/Mrs4s/MiraiGo/binary" - "github.com/Mrs4s/MiraiGo/client" "github.com/Mrs4s/go-cqhttp/coolq" "github.com/Mrs4s/go-cqhttp/global" - jsoniter "github.com/json-iterator/go" - log "github.com/sirupsen/logrus" + "github.com/Mrs4s/go-cqhttp/global/terminal" + "github.com/Mrs4s/go-cqhttp/server" ) var json = jsoniter.ConfigCompatibleWithStandardLibrary @@ -187,6 +187,7 @@ func main() { if len(byteKey) == 0 { log.Infof("密码加密已启用, 请输入Key对密码进行解密以继续: (Enter 提交)") cancel := make(chan struct{}, 1) + state, _ := term.GetState(int(os.Stdin.Fd())) go func() { select { case <-cancel: @@ -194,6 +195,7 @@ func main() { case <-time.After(time.Second * 45): log.Infof("解密key输入超时") time.Sleep(3 * time.Second) + _ = term.Restore(int(os.Stdin.Fd()), state) os.Exit(0) } }()