Last active
May 7, 2020 09:04
-
-
Save mkideal/19f06e04d612c735cf52ee7c7be25400 to your computer and use it in GitHub Desktop.
demo terminal app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package xyz | |
import ( | |
"io" | |
"os" | |
"golang.org/x/crypto/ssh/terminal" | |
) | |
type readerWriter struct { | |
io.Reader | |
io.Writer | |
} | |
func run(stdin *os.File, stdout io.Writer) (err error) { | |
term := terminal.NewTerminal(readerWriter{stdin, stdout}, "$> ") | |
stdinFD := int(stdin.Fd()) | |
stdinState, err := terminal.MakeRaw(stdinFD) | |
if err != nil { | |
return err | |
} | |
defer func() { | |
terminal.Restore(stdinFD, stdinState) | |
}() | |
for { | |
prompt := "$> " | |
term.SetPrompt(prompt) | |
line, err := term.ReadLine() | |
if err != nil { | |
return err | |
} | |
//TODO: handle the line | |
_ = line | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!