diff options
-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 { + + } + } } |