WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 7895d84

Browse files
authored
Merge branch 'master' into fix/134
2 parents 3b3b96d + 7ccfd90 commit 7895d84

File tree

6 files changed

+42
-19
lines changed

6 files changed

+42
-19
lines changed

cmd/fyneterm/main.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"flag"
66
"image/color"
77
"os"
8+
"path/filepath"
89
"runtime"
910

1011
"fyne.io/fyne/v2/storage"
@@ -113,18 +114,27 @@ func newTerminalWindow(a fyne.App, debug bool) fyne.Window {
113114
img.FillMode = ff.BackgroundFill
114115
img.Refresh()
115116
}
116-
wd, err := os.Getwd()
117-
if err == nil {
118-
setDir(wd)
117+
118+
t := terminal.New()
119+
t.SetDebug(debug)
120+
if len(os.Args) >= 2 {
121+
s, err := filepath.Abs(os.Args[1])
122+
if err == nil {
123+
t.SetStartDir(s)
124+
setDir(s)
125+
}
126+
} else {
127+
wd, err := os.Getwd()
128+
if err == nil {
129+
setDir(wd)
130+
}
119131
}
120132

121133
a.Settings().AddListener(func(s fyne.Settings) {
122134
bg.FillColor = theme.Color(theme.ColorNameBackground)
123135
bg.Refresh()
124136
})
125137

126-
t := terminal.New()
127-
t.SetDebug(debug)
128138
setupListener(t, w)
129139
sizeOverride := container.NewThemeOverride(container.NewStack(bg, img, t), th)
130140
w.SetContent(sizeOverride)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/fyne-io/terminal
33
go 1.19
44

55
require (
6-
fyne.io/fyne/v2 v2.7.1-0.20251030181611-4bc1d5fd5b88
6+
fyne.io/fyne/v2 v2.7.1-0.20251105193630-e5ef0983771f
77
github.com/ActiveState/termtest/conpty v0.5.0
88
github.com/creack/pty v1.1.21
99
github.com/fyshos/fancyfs v0.0.0-20250930151016-696fe12cefc6

go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
fyne.io/fyne/v2 v2.7.1-0.20251030181611-4bc1d5fd5b88 h1:z/Egg/TPFUoTyB/peOdaEmgjcwQOqPy3Aju2UQvzwpA=
2-
fyne.io/fyne/v2 v2.7.1-0.20251030181611-4bc1d5fd5b88/go.mod h1:xClVlrhxl7D+LT+BWYmcrW4Nf+dJTvkhnPgji7spAwE=
1+
fyne.io/fyne/v2 v2.7.0 h1:GvZSpE3X0liU/fqstInVvRsaboIVpIWQ4/sfjDGIGGQ=
2+
fyne.io/fyne/v2 v2.7.0/go.mod h1:xClVlrhxl7D+LT+BWYmcrW4Nf+dJTvkhnPgji7spAwE=
3+
fyne.io/fyne/v2 v2.7.1-0.20251105193630-e5ef0983771f h1:auI30rQbwHL8s4tLhre/RwUWw/OT2+oTuhEp+GBl6LU=
4+
fyne.io/fyne/v2 v2.7.1-0.20251105193630-e5ef0983771f/go.mod h1:xo+SRRY+GLd0bNX/g8/FdXZ5Xlltobi1BA4VSNiEzpE=
35
fyne.io/systray v1.11.1-0.20250603113521-ca66a66d8b58 h1:eA5/u2XRd8OUkoMqEv3IBlFYSruNlXD8bRHDiqm0VNI=
46
fyne.io/systray v1.11.1-0.20250603113521-ca66a66d8b58/go.mod h1:RVwqP9nYMo7h5zViCBHri2FgjXF7H2cub7MAq4NSoLs=
57
github.com/ActiveState/termtest/conpty v0.5.0 h1:JLUe6YDs4Jw4xNPCU+8VwTpniYOGeKzQg4SM2YHQNA8=

input.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -192,28 +192,30 @@ func (t *Terminal) TypedShortcut(s fyne.Shortcut) {
192192
t.ShortcutHandler.TypedShortcut(s)
193193
} else {
194194
// we need to override the default ctrl-X/C/V/A for non-mac and do it ourselves
195-
196-
if ct, ok := s.(*fyne.ShortcutCut); ok {
197-
if ct.Secondary {
195+
switch sh := cts.(type) {
196+
case *fyne.ShortcutCut:
197+
if sh.Secondary {
198198
// shift+del - cut is no-op
199199
} else {
200200
_, _ = t.in.Write([]byte{0x18})
201201
}
202-
} else if cp, ok := s.(*fyne.ShortcutCopy); ok {
203-
if cp.Secondary {
202+
case *fyne.ShortcutCopy:
203+
if sh.Secondary {
204204
t.copySelectedText(fyne.CurrentApp().Clipboard()) // ctrl+ins
205205
} else {
206206
_, _ = t.in.Write([]byte{0x3})
207207
}
208-
} else if ps, ok := s.(*fyne.ShortcutPaste); ok {
209-
if ps.Secondary {
208+
case *fyne.ShortcutPaste:
209+
if sh.Secondary {
210210
t.pasteText(fyne.CurrentApp().Clipboard(), true) // shift+ins
211211
} else {
212212
_, _ = t.in.Write([]byte{0x16})
213213
}
214-
} else if _, ok := s.(*fyne.ShortcutUndo); ok {
214+
case *fyne.ShortcutUndo:
215215
_, _ = t.in.Write([]byte{0x1a})
216-
} else if _, ok := s.(*fyne.ShortcutSelectAll); ok {
216+
case *fyne.ShortcutRedo:
217+
_, _ = t.in.Write([]byte{0x19})
218+
case *fyne.ShortcutSelectAll:
217219
_, _ = t.in.Write([]byte{0x1})
218220
}
219221
}

term.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,11 @@ func (t *Terminal) run() {
404404

405405
// RunLocalShell starts the terminal by loading a shell and starting to process the input/output.
406406
func (t *Terminal) RunLocalShell() error {
407-
t.config.PWD, _ = os.Getwd()
407+
if t.startDir != "" {
408+
t.config.PWD = t.startDir
409+
} else {
410+
t.config.PWD, _ = os.Getwd()
411+
}
408412
for t.config.Columns == 0 { // don't load the TTY until our output is configured
409413
time.Sleep(time.Millisecond * 50)
410414
}
@@ -420,7 +424,11 @@ func (t *Terminal) RunLocalShell() error {
420424

421425
// RunWithConnection starts the terminal by connecting to an external resource like an SSH connection.
422426
func (t *Terminal) RunWithConnection(in io.WriteCloser, out io.Reader) error {
423-
t.config.PWD, _ = os.Getwd()
427+
if t.startDir != "" {
428+
t.config.PWD = t.startDir
429+
} else {
430+
t.config.PWD, _ = os.Getwd()
431+
}
424432
for t.config.Columns == 0 { // don't load the TTY until our output is configured
425433
time.Sleep(time.Millisecond * 50)
426434
}

term_unix.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func (t *Terminal) startPTY() (io.WriteCloser, io.Reader, io.Closer, error) {
4040
c.Dir = t.startingDir()
4141
c.Env = env
4242
t.cmd = c
43+
t.config.PWD = c.Dir
4344

4445
go func() {
4546
for {

0 commit comments

Comments
 (0)