6
6
"encoding/json"
7
7
"fmt"
8
8
"os"
9
+ "os/signal"
9
10
"strings"
11
+ "syscall"
10
12
11
13
"github.com/dustin/go-humanize"
12
14
"github.com/filecoin-project/boost/cli/node"
@@ -18,6 +20,7 @@ import (
18
20
lcli "github.com/filecoin-project/lotus/cli"
19
21
"github.com/filecoin-project/lotus/lib/tablewriter"
20
22
"github.com/urfave/cli/v2"
23
+ "golang.org/x/term"
21
24
)
22
25
23
26
var walletCmd = & cli.Command {
@@ -388,13 +391,32 @@ var walletImport = &cli.Command{
388
391
389
392
var inpdata []byte
390
393
if ! cctx .Args ().Present () || cctx .Args ().First () == "-" {
391
- reader := bufio .NewReader (os .Stdin )
392
- fmt .Print ("Enter private key: " )
393
- indata , err := reader .ReadBytes ('\n' )
394
- if err != nil {
395
- return err
394
+ if term .IsTerminal (int (os .Stdin .Fd ())) {
395
+ fmt .Print ("Enter private key(not display in the terminal): " )
396
+
397
+ sigCh := make (chan os.Signal , 1 )
398
+ // Notify the channel when SIGINT is received
399
+ signal .Notify (sigCh , syscall .SIGINT , syscall .SIGTERM )
400
+
401
+ go func () {
402
+ <- sigCh
403
+ fmt .Println ("\n Interrupt signal received. Exiting..." )
404
+ os .Exit (1 )
405
+ }()
406
+
407
+ inpdata , err = term .ReadPassword (int (os .Stdin .Fd ()))
408
+ if err != nil {
409
+ return err
410
+ }
411
+ fmt .Println ()
412
+ } else {
413
+ reader := bufio .NewReader (os .Stdin )
414
+ indata , err := reader .ReadBytes ('\n' )
415
+ if err != nil {
416
+ return err
417
+ }
418
+ inpdata = indata
396
419
}
397
- inpdata = indata
398
420
399
421
} else {
400
422
fdata , err := os .ReadFile (cctx .Args ().First ())
0 commit comments