forked from fyne-io/terminal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathterm_unix.go
More file actions
63 lines (54 loc) · 1.21 KB
/
Copy pathterm_unix.go
File metadata and controls
63 lines (54 loc) · 1.21 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//go:build !windows
// +build !windows
package terminal
import (
"io"
"os"
"os/exec"
"strconv"
"time"
"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"
}
env := os.Environ()
env = append(env, "TERM=xterm-256color")
c := exec.Command(shell)
c.Dir = t.startingDir()
c.Env = env
t.cmd = c
t.config.PWD = c.Dir
go func() {
for {
time.Sleep(time.Millisecond * 250)
if time.Since(lastKeyTime).Seconds() > 0.5 {
continue
}
wd, _ := os.Readlink("/proc/" + strconv.Itoa(c.Process.Pid) + "/cwd")
if wd != t.config.PWD {
t.config.PWD = wd
fyne.Do(t.onConfigure)
}
}
}()
// Start the command with a pty.
f, err := pty.Start(c)
return f, f, f, err
}