-
Notifications
You must be signed in to change notification settings - Fork 38
/
term_unix.go
45 lines (38 loc) · 915 Bytes
/
term_unix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//go:build !windows
// +build !windows
package terminal
import (
"io"
"os"
"os/exec"
"fyne.io/fyne/v2"
"github.com/creack/pty"
)
func (t *Terminal) updatePTYSize() {
if t.pty == nil { // SSH or other direct connection?
return
}
scale := float32(1.0)
c := fyne.CurrentApp().Driver().CanvasForObject(t)
if c != nil {
scale = c.Scale()
}
_ = pty.Setsize(t.pty.(*os.File), &pty.Winsize{
Rows: uint16(t.config.Rows), Cols: uint16(t.config.Columns),
X: uint16(t.Size().Width * scale), Y: uint16(t.Size().Height * scale)})
}
func (t *Terminal) startPTY() (io.WriteCloser, io.Reader, io.Closer, error) {
shell := os.Getenv("SHELL")
if shell == "" {
shell = "bash"
}
_ = os.Chdir(t.startingDir())
env := os.Environ()
env = append(env, "TERM=xterm-256color")
c := exec.Command(shell)
c.Env = env
t.cmd = c
// Start the command with a pty.
f, err := pty.Start(c)
return f, f, f, err
}