summaryrefslogtreecommitdiff
path: root/bash.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-01-06 17:51:41 -0600
committerJeff Carr <[email protected]>2024-01-06 17:51:41 -0600
commit1191d1548470a7ed1049f1d78de6f17b77e0d36d (patch)
treeb79d2773e77909b00b12c9250ea074a89df2b558 /bash.go
parenta385734bc948b6cae6c5dd9a5fc48abaca4a040f (diff)
purge years of old test code
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'bash.go')
-rw-r--r--bash.go61
1 files changed, 0 insertions, 61 deletions
diff --git a/bash.go b/bash.go
deleted file mode 100644
index 7143c1f..0000000
--- a/bash.go
+++ /dev/null
@@ -1,61 +0,0 @@
-package main
-
-import (
- "io"
- "os"
- "os/exec"
- "os/signal"
- "syscall"
-
- "github.com/creack/pty"
- "golang.org/x/term"
-
- "go.wit.com/log"
-)
-
-func test() error {
- // Create arbitrary command.
- c := exec.Command("bash")
-
- // Start the command with a pty.
- ptmx, err := pty.Start(c)
- if err != nil {
- return err
- }
- // Make sure to close the pty at the end.
- defer func() { _ = ptmx.Close() }() // Best effort.
-
- // Handle pty size.
- ch := make(chan os.Signal, 1)
- signal.Notify(ch, syscall.SIGWINCH)
- go func() {
- for range ch {
- if err := pty.InheritSize(os.Stdin, ptmx); err != nil {
- log.Println("error resizing pty: %s", err)
- }
- }
- }()
- ch <- syscall.SIGWINCH // Initial resize.
- defer func() { signal.Stop(ch); close(ch) }() // Cleanup signals when done.
-
- // Set stdin in raw mode.
- oldState, err := term.MakeRaw(int(os.Stdin.Fd()))
- if err != nil {
- panic(err)
- }
- defer func() { _ = term.Restore(int(os.Stdin.Fd()), oldState) }() // Best effort.
-
- // Copy stdin to the pty and the pty to stdout.
- // NOTE: The goroutine will keep reading until the next keystroke before returning.
- go func() { _, _ = io.Copy(ptmx, os.Stdin) }()
- _, _ = io.Copy(os.Stdout, ptmx)
-
- return nil
-}
-
-func mainBash() {
- if err := test(); err != nil {
- log.Error(err, "exit in mainBash()")
- log.Exit(err)
- }
-}