I have a TUI (text user interface) program that I would like to serve over a network connection. A sample from the login page (which doesn't do much right now), is posted below. I am using tui-go for my TUI library.
program.go
package main
import (
"log"
"github.com/marcusolsson/tui-go"
)
var logo string = "My Logo"
func main() {
Login()
}
func Login() {
inUser := tui.NewEntry()
inUser.SetFocused(true)
inPass := tui.NewEntry()
inPass.SetEchoMode(tui.EchoModePassword)
form := tui.NewGrid(0, 0)
form.AppendRow(tui.NewLabel("Username"), tui.NewLabel("Password"))
form.AppendRow(inUser, inPass)
// TODO: create OnActivated function
btnLogin := tui.NewButton("[Login]")
// TODO: create OnActivated function
btnRegister := tui.NewButton("[Register]")
buttons := tui.NewHBox(
tui.NewSpacer(),
tui.NewPadder(1, 0, btnLogin),
tui.NewPadder(1, 0, btnRegister),
)
window := tui.NewVBox(
tui.NewPadder(1, 1, form),
buttons,
)
window.SetBorder(true)
root := tui.NewVBox(
tui.NewSpacer(),
window,
tui.NewSpacer(),
)
tui.DefaultFocusChain.Set(inUser, inPass, btnLogin, btnRegister)
ui, err := tui.New(root)
if err != nil {
log.Fatal(err)
}
ui.SetKeybinding("Esc", func() { ui.Quit() })
if err := ui.Run(); err != nil {
log.Fatal(err)
}
}
I then have another program to execute the binary of program.go in a pty, and send it over a socket. Ideally, I would like the user to connect using a plethora of methods, such as telnet, ssh, or netcat. The problem is, when I send the pty over the socket, it does not behave the same way as it would when I'm simply running the binary of program.go from my shell. Below is a copy of my server program. I am using pty library to create the *os.File that gets sent over the socket.
server.go
package main
import (
"net"
"log"
"io"
"os/exec"
"github.com/kr/pty"
)
func main() {
ln, err := net.Listen("tcp", ":2323")
if err != nil {
log.Fatal(err)
}
defer ln.Close()
for {
conn, err := ln.Accept()
if err != nil {
log.Fatal(err)
}
go startProg(conn)
}
}
func startProg(conn net.Conn) {
defer conn.Close()
term, err := pty.StartWithSize(
exec.Command("./program"),
&pty.Winsize{Cols: 100, Rows: 30},
)
if err != nil {
log.Fatal(err)
}
defer term.Close()
go io.Copy(term, conn)
io.Copy(conn, term)
}
Is there anyway to have the TUI work as though it would normally work running from a shell? Also, how would I read in data that the user inputs into the TUI? Because when trying to read from both the connection, and the *os.File returned by pty, I can't seem to get any data at all.
Any help is much appreciated!