mirror of
https://github.com/hymkor/lispect.git
synced 2026-09-01 22:57:46 -04:00
New class Term
This commit is contained in:
@@ -5,63 +5,29 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"golang.org/x/term"
|
||||
|
||||
"github.com/aymanbagabas/go-pty"
|
||||
|
||||
"github.com/hymkor/go-windows1x-virtualterminal"
|
||||
)
|
||||
|
||||
func loop(ptmx pty.Pty) error {
|
||||
watcher := NewWatcher(ptmx)
|
||||
func mains() error {
|
||||
term, err := NewTerm()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer term.Close()
|
||||
|
||||
sh := ptmx.Command("cmd.exe")
|
||||
watcher := NewWatcher(term)
|
||||
|
||||
sh := term.Command("cmd.exe")
|
||||
if err := sh.Start(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
i := watcher.ExpectWithTimeout(time.Duration(10*time.Second), "100")
|
||||
// i := watcher.Expect("100")
|
||||
io.WriteString(ptmx, "exit\r")
|
||||
io.WriteString(term, "\x03exit\r")
|
||||
println(i)
|
||||
return sh.Wait()
|
||||
}
|
||||
|
||||
func mains() error {
|
||||
disableStdout, err := virtualterminal.EnableStdout()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer disableStdout()
|
||||
|
||||
disableStdin, err := virtualterminal.EnableStdin()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer disableStdin()
|
||||
|
||||
ptmx, err := pty.New()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer ptmx.Close()
|
||||
|
||||
width, height, err := term.GetSize(int(os.Stdout.Fd()))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ptmx.Resize(width, height)
|
||||
|
||||
oldState, err := term.MakeRaw(int(os.Stdin.Fd()))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer term.Restore(int(os.Stdin.Fd()), oldState)
|
||||
|
||||
return loop(ptmx)
|
||||
}
|
||||
|
||||
func main() {
|
||||
if err := mains(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err.Error())
|
||||
|
||||
Reference in New Issue
Block a user