Skip to content

Instantly share code, notes, and snippets.

@ishuah
Created March 10, 2021 05:40
Show Gist options
  • Save ishuah/e54a5445cf5ec0352915a508f1955bbd to your computer and use it in GitHub Desktop.
Save ishuah/e54a5445cf5ec0352915a508f1955bbd to your computer and use it in GitHub Desktop.
package main
import (
"os"
"os/exec"
"time"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/widget"
"github.com/creack/pty"
)
func main() {
a := app.New()
w := a.NewWindow("germ")
ui := widget.NewTextGrid() // Create a new TextGrid
ui.SetText("I'm on a terminal!") // Set text to display
c := exec.Command("/bin/bash")
p, err := pty.Start(c)
if err != nil {
fyne.LogError("Failed to open pty", err)
os.Exit(1)
}
defer c.Process.Kill()
p.Write([]byte("ls\r"))
time.Sleep(1 * time.Second)
b := make([]byte, 1024)
_, err = p.Read(b)
if err != nil {
fyne.LogError("Failed to read pty", err)
}
// s := fmt.Sprintf("read bytes from pty.\nContent:%s", string(b))
ui.SetText(string(b))
// Create a new container with a wrapped layout
// set the layout width to 420, height to 200
w.SetContent(
fyne.NewContainerWithLayout(
layout.NewGridWrapLayout(fyne.NewSize(420, 200)),
ui,
),
)
w.ShowAndRun()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment