aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Wang2022-03-27 18:09:22 -0500
committerAnthony Wang2022-03-27 18:09:22 -0500
commit81fe341a26b3a9706f8cbfb0d66576909891342d (patch)
treea641d6bd8d0b93db08e9908bc60b057a98d90f1a
parent2e0dac3994581e944e839e3dc8245243d08e8804 (diff)
Don't use golang.org/x/term
-rw-r--r--go.mod4
-rw-r--r--go.sum4
-rw-r--r--sd.go29
3 files changed, 21 insertions, 16 deletions
diff --git a/go.mod b/go.mod
index 6bfaa81..94d9d02 100644
--- a/go.mod
+++ b/go.mod
@@ -1,7 +1,3 @@
module sd
go 1.18
-
-require golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
-
-require golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect
diff --git a/go.sum b/go.sum
deleted file mode 100644
index 26b086d..0000000
--- a/go.sum
+++ /dev/null
@@ -1,4 +0,0 @@
-golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4=
-golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
-golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
diff --git a/sd.go b/sd.go
index 26438f8..efe442c 100644
--- a/sd.go
+++ b/sd.go
@@ -2,9 +2,9 @@ package main
import (
"flag"
+ "fmt"
"os"
-
- "golang.org/x/term"
+ "os/exec"
)
var file = flag.String("f", "cards", "cards file")
@@ -12,12 +12,25 @@ var file = flag.String("f", "cards", "cards file")
func main() {
flag.Parse()
- // Put terminal into raw mode
- oldState, err := term.MakeRaw(int(os.Stdin.Fd()))
- if err != nil {
- panic(err)
- }
- defer term.Restore(int(os.Stdin.Fd()), oldState)
+ // https://stackoverflow.com/questions/14094190/function-similar-to-getchar
+ // disable input buffering
+ exec.Command("stty", "-F", "/dev/tty", "cbreak", "min", "1").Run()
+ // do not display entered characters on the screen
+ exec.Command("stty", "-F", "/dev/tty", "-echo").Run()
+ // restore the echoing state when exiting
+ defer exec.Command("stty", "-F", "/dev/tty", "echo").Run()
+ for {
+ fmt.Println("hello world")
+
+ var b []byte = make([]byte, 1)
+ os.Stdin.Read(b)
+ if string(b) == 'y' {
+ } else if string(b) == 'n' {
+
+ } else {
+
+ }
+ }
}