Skip to content

Commit

Permalink
Update Fyne and correct our thread handling to work with the new `fyn…
Browse files Browse the repository at this point in the history
…e.Do` requirement
  • Loading branch information
andydotxyz committed Feb 9, 2025
1 parent fcf25a6 commit 07a3ba9
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 35 deletions.
32 changes: 14 additions & 18 deletions cmd/fyneterm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ func setupListener(t *terminal.Terminal, w fyne.Window) {
for {
config := <-listen

if config.Title == "" {
w.SetTitle(termTitle())
} else {
w.SetTitle(termTitle() + ": " + config.Title)
}
fyne.Do(func() {
if config.Title == "" {
w.SetTitle(termTitle())
} else {
w.SetTitle(termTitle() + ": " + config.Title)
}
})
}
}()
t.AddListener(listen)
Expand Down Expand Up @@ -74,18 +76,12 @@ func newTerminalWindow(a fyne.App, th fyne.Theme, debug bool) fyne.Window {
img.FillMode = canvas.ImageFillContain
over := canvas.NewRectangle(th.Color(termOverlay, a.Settings().ThemeVariant()))

ch := make(chan fyne.Settings)
go func() {
for {
<-ch

bg.FillColor = theme.Color(theme.ColorNameBackground)
bg.Refresh()
over.FillColor = th.Color(termOverlay, a.Settings().ThemeVariant())
over.Refresh()
}
}()
a.Settings().AddChangeListener(ch)
a.Settings().AddListener(func(s fyne.Settings) {
bg.FillColor = theme.Color(theme.ColorNameBackground)
bg.Refresh()
over.FillColor = th.Color(termOverlay, s.ThemeVariant())
over.Refresh()
})

t := terminal.New()
t.SetDebug(debug)
Expand Down Expand Up @@ -121,7 +117,7 @@ func newTerminalWindow(a fyne.App, th fyne.Theme, debug bool) fyne.Window {
if err != nil {
fyne.LogError("Failure in terminal", err)
}
w.Close()
fyne.Do(w.Close)
}()

return w
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/fyne-io/terminal
go 1.19

require (
fyne.io/fyne/v2 v2.5.3-rc7.0.20250120111557-621fc220edd7
fyne.io/fyne/v2 v2.5.5-0.20250208233333-9cdc38456780
github.com/ActiveState/termtest/conpty v0.5.0
github.com/creack/pty v1.1.21
github.com/stretchr/testify v1.10.0
Expand All @@ -27,6 +27,7 @@ require (
github.com/gopherjs/gopherjs v1.17.2 // indirect
github.com/jeandeaual/go-locale v0.0.0-20241217141322-fcc2cadd6f08 // indirect
github.com/jsummers/gobmp v0.0.0-20151104160322-e2ba15ffa76e // indirect
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
github.com/nicksnyder/go-i18n/v2 v2.4.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rymdport/portal v0.3.0 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
fyne.io/fyne/v2 v2.5.3-rc7.0.20250120111557-621fc220edd7 h1:6xIwnZtyOen//wxgOhAIounJsLZwdQQgtP8DJNAH5vU=
fyne.io/fyne/v2 v2.5.3-rc7.0.20250120111557-621fc220edd7/go.mod h1:0GOXKqyvNwk3DLmsFu9v0oYM0ZcD1ysGnlHCerKoAmo=
fyne.io/fyne/v2 v2.5.5-0.20250208233333-9cdc38456780 h1:jmgXLVGxO+qaz3DSyzXRMZhTIZciyTf1RP7j12Q6INU=
fyne.io/fyne/v2 v2.5.5-0.20250208233333-9cdc38456780/go.mod h1:6/uEYg4FEhspAcWgsokutm9wFMHDNSYuEHCKTYWSho8=
fyne.io/systray v1.11.0 h1:D9HISlxSkx+jHSniMBR6fCFOUjk1x/OOOJLa9lJYAKg=
fyne.io/systray v1.11.0/go.mod h1:RVwqP9nYMo7h5zViCBHri2FgjXF7H2cub7MAq4NSoLs=
github.com/ActiveState/termtest/conpty v0.5.0 h1:JLUe6YDs4Jw4xNPCU+8VwTpniYOGeKzQg4SM2YHQNA8=
Expand Down Expand Up @@ -232,6 +232,8 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86/go.mod h1:kHJEU3ofeGjhHklVoIGuVj85JJwZ6kWPaJwCIxgnFmo=
github.com/neelance/sourcemap v0.0.0-20200213170602-2833bce08e4c/go.mod h1:Qr6/a/Q4r9LP1IltGz7tA7iOK1WonHEYhu1HRBA7ZiM=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
github.com/nicksnyder/go-i18n/v2 v2.4.0 h1:3IcvPOAvnCKwNm0TB0dLDTuawWEj+ax/RERNC+diLMM=
github.com/nicksnyder/go-i18n/v2 v2.4.0/go.mod h1:nxYSZE9M0bf3Y70gPQjN9ha7XNHX7gMc814+6wVyEI4=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
Expand Down
4 changes: 3 additions & 1 deletion internal/widget/termgrid.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ func (t *TermGrid) runBlink() {
return
case <-ticker.C:
blinking = !blinking
t.refreshBlink(blinking)
fyne.Do(func() {
t.refreshBlink(blinking)
})
}
}
}()
Expand Down
14 changes: 8 additions & 6 deletions output.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"
"unicode/utf8"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/widget"
widget2 "github.com/fyne-io/terminal/internal/widget"
)
Expand Down Expand Up @@ -156,7 +157,6 @@ func (t *Terminal) handleOutput(buf []byte) []byte {
// check to see which charset to use
if t.useG1CharSet {
t.handleOutputChar(charSetMap[t.g1Charset](r))

} else {
t.handleOutputChar(charSetMap[t.g0Charset](r))
}
Expand Down Expand Up @@ -266,11 +266,13 @@ func (t *Terminal) handleOutputChar(r rune) {

func (t *Terminal) ringBell() {
t.bell = true
t.Refresh()
fyne.Do(t.Refresh)

time.Sleep(time.Millisecond * 300)
t.bell = false
t.Refresh()
go func() {
time.Sleep(time.Millisecond * 300)
t.bell = false
fyne.Do(t.Refresh)
}()
}

func (t *Terminal) scrollUp() {
Expand Down Expand Up @@ -305,7 +307,7 @@ func handleOutputBackspace(t *Terminal) {
}

func handleOutputBell(t *Terminal) {
go t.ringBell()
t.ringBell()
}

func handleOutputCarriageReturn(t *Terminal) {
Expand Down
16 changes: 9 additions & 7 deletions term.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func (t *Terminal) Resize(s fyne.Size) {
}
t.onConfigure()

go t.updatePTYSize()
t.updatePTYSize()
}

// SetDebug turns on output about terminal codes and other errors if the parameter is `true`.
Expand Down Expand Up @@ -362,8 +362,7 @@ func (t *Terminal) run() {
// wait for cmd (shell) to exit, populates ProcessState.ExitCode
t.cmd.Wait()
}
// this is the pre-go 1.13 way to check for the read failing (terminal closed)
if err.Error() == "EOF" {
if err == io.EOF || err.Error() == "EOF" {
break // term exit on macOS
} else if err, ok := err.(*os.PathError); ok && err.Err.Error() == "input/output error" {
break // broken pipe, terminal exit
Expand All @@ -378,10 +377,13 @@ func (t *Terminal) run() {
fullBuf = append(leftOver, buf[:num]...)
num += lenLeftOver
}
leftOver = t.handleOutput(fullBuf[:num])
if len(leftOver) == 0 {
t.Refresh()
}

fyne.DoAndWait(func() {
leftOver = t.handleOutput(fullBuf[:num])
if len(leftOver) == 0 {
t.Refresh()
}
})
}
}

Expand Down

0 comments on commit 07a3ba9

Please sign in to comment.