Browse Source

Eliminate depedence on golang.org/x/term

tags/v1.0.0
codesoap 8 months ago
parent
commit
c7726d5857
2 changed files with 8 additions and 14 deletions
  1. 0
    1
      go.mod
  2. 8
    13
      send.go

+ 0
- 1
go.mod View File

@@ -5,5 +5,4 @@ go 1.15
require (
filippo.io/edwards25519 v1.0.0-beta.3
golang.org/x/crypto v0.0.0-20210317152858-513c2a44f670
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1
)

+ 8
- 13
send.go View File

@@ -7,8 +7,6 @@ import (
"os"
"regexp"
"strings"

"golang.org/x/term"
)

func sendFunds() error {
@@ -47,20 +45,17 @@ func getSeedForSending(amount, recipient string) (*big.Int, error) {
if !yFlag {
fmt.Printf("Send %s NANO to %s? [y/N]: ", amount, recipient)

// This code is inspired by code from filippo.io/age.
in := os.Stdin
if !term.IsTerminal(int(in.Fd())) {
tty, err := os.Open("/dev/tty")
if err != nil {
msg := "could not open terminal for confirmation input: %v"
return nil, fmt.Errorf(msg, err)
}
defer tty.Close()
in = tty
// Explicitly openning /dev/tty ensures function, even if the
// standard input is not a terminal.
tty, err := os.Open("/dev/tty")
if err != nil {
msg := "could not open terminal for confirmation input: %v"
return nil, fmt.Errorf(msg, err)
}
defer tty.Close()

var confirmation string
fmt.Fscanln(in, &confirmation)
fmt.Fscanln(tty, &confirmation)
if confirmation != "y" && confirmation != "Y" {
fmt.Fprintln(os.Stderr, "Send aborted.")
os.Exit(0)

Loading…
Cancel
Save