diff options
author | Anthony Wang | 2022-03-27 18:09:22 -0500 |
---|---|---|
committer | Anthony Wang | 2022-03-27 18:09:22 -0500 |
commit | 81fe341a26b3a9706f8cbfb0d66576909891342d (patch) | |
tree | a641d6bd8d0b93db08e9908bc60b057a98d90f1a | |
parent | 2e0dac3994581e944e839e3dc8245243d08e8804 (diff) |
Don't use golang.org/x/term
-rw-r--r-- | go.mod | 4 | ||||
-rw-r--r-- | go.sum | 4 | ||||
-rw-r--r-- | sd.go | 29 |
3 files changed, 21 insertions, 16 deletions
@@ -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 @@ -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= @@ -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 { + + } + } } |