Prevent changes in telnet breaking terminal display

asdf 3 years ago
parent 5e8cebaaaa
commit a8fc394a3d

@ -1,19 +1,32 @@
// Package telnet provides a function that starts a telnet session in a subprocess.
package telnet
import (
// StartSession starts a telnet session as a subprocess, connecting to the host
// and port specified. Telnet is run interactively as a subprocess until the
// process ends. It returns any errors from the telnet session.
func StartSession(host string, port string) (string, error) {
// Case for telnet links
c := exec.Command("telnet", host, port)
c.Stdin = os.Stdin
c.Stdout = os.Stdout
c.Stderr = os.Stderr
// Clear the screen and position the cursor at the top left
// Defer reset and reinit of the terminal to prevent any changes from
// telnet carrying over to the client (or beyond...)
defer func() {
err := c.Run()
if err != nil {
return "", fmt.Errorf("Telnet error response: %s", err.Error())
@ -21,4 +34,3 @@ func StartSession(host string, port string) (string, error) {
return "Telnet session terminated", nil