Browse Source

Eliminate depedence on golang.org/x/term

xno
codesoap 1 year ago
parent
commit
c7726d5857
  1. 1
      go.mod
  2. 21
      send.go

1
go.mod

@ -5,5 +5,4 @@ go 1.15 @@ -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
)

21
send.go

@ -7,8 +7,6 @@ import ( @@ -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) { @@ -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