summaryrefslogtreecommitdiff
path: root/linuxstatus/old/bash.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-01-15 17:22:51 -0600
committerJeff Carr <[email protected]>2024-01-15 17:22:51 -0600
commitdb86b09070f2ffd69dda9354aff7c9383739a8e0 (patch)
tree276c44f3d8d4f9673850c273d402375cac2d3d8e /linuxstatus/old/bash.go
parent0fcbdca8965cf97c0261b79a6e04e71b729f66b3 (diff)
move linuxstatus into separate repov0.12.3
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'linuxstatus/old/bash.go')
-rw-r--r--linuxstatus/old/bash.go61
1 files changed, 0 insertions, 61 deletions
diff --git a/linuxstatus/old/bash.go b/linuxstatus/old/bash.go
deleted file mode 100644
index 7143c1f..0000000
--- a/linuxstatus/old/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)
- }
-}