From 81fe341a26b3a9706f8cbfb0d66576909891342d Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Sun, 27 Mar 2022 18:09:22 -0500 Subject: Don't use golang.org/x/term --- go.mod | 4 ---- go.sum | 4 ---- sd.go | 29 +++++++++++++++++++++-------- 3 files changed, 21 insertions(+), 16 deletions(-) delete mode 100644 go.sum 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 { + + } + } } -- cgit v1.2.3-70-g09d2