Make lotus wallet import respect sigint

Make `lotus wallet import` respect sigint
This commit is contained in:
Phi 2023-08-21 09:10:47 +02:00
parent cbbb76b2f0
commit c1fd48a14b

View File

@ -7,7 +7,9 @@ import (
"encoding/json"
"fmt"
"os"
"os/signal"
"strings"
"syscall"
"github.com/urfave/cli/v2"
"golang.org/x/term"
@ -335,6 +337,20 @@ var walletImport = &cli.Command{
if !cctx.Args().Present() || cctx.Args().First() == "-" {
if term.IsTerminal(int(os.Stdin.Fd())) {
fmt.Print("Enter private key(not display in the terminal): ")
// Create a channel to receive OS signals
sigCh := make(chan os.Signal, 1)
// Notify the channel when SIGINT is received
signal.Notify(sigCh, syscall.SIGINT)
go func() {
// Wait for SIGINT signal
<-sigCh
// Perform cleanup or other actions as needed
fmt.Println("\nInterrupt signal received. Exiting...")
os.Exit(1)
}()
inpdata, err = term.ReadPassword(int(os.Stdin.Fd()))
if err != nil {
return err