Skip to content

Commit

Permalink
Add zooming with +/- keys
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Aug 28, 2023
1 parent 287f9d4 commit d00cbc5
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 39 deletions.
25 changes: 21 additions & 4 deletions cmd/fyneterm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ import (

const termOverlay = fyne.ThemeColorName("termOver")

var localizer *i18n.Localizer
var (
localizer *i18n.Localizer
sizer *termTheme
)

func setupListener(t *terminal.Terminal, w fyne.Window) {
listen := make(chan terminal.Config)
Expand Down Expand Up @@ -70,9 +73,9 @@ func main() {

a := app.New()
a.SetIcon(data.Icon)
th := newTermTheme()
a.Settings().SetTheme(th)
w := newTerminalWindow(a, th, debug)
sizer = newTermTheme()
a.Settings().SetTheme(sizer)
w := newTerminalWindow(a, sizer, debug)
w.ShowAndRun()
}

Expand Down Expand Up @@ -112,6 +115,20 @@ func newTerminalWindow(a fyne.App, th fyne.Theme, debug bool) fyne.Window {
w := newTerminalWindow(a, th, debug)
w.Show()
})
t.AddShortcut(&desktop.CustomShortcut{KeyName: fyne.KeyEqual, Modifier: fyne.KeyModifierControl | fyne.KeyModifierShift},
func(_ fyne.Shortcut) {
sizer.fontSize++
a.Settings().SetTheme(sizer)
t.Refresh()
t.Resize(t.Size())
})
t.AddShortcut(&desktop.CustomShortcut{KeyName: fyne.KeyMinus, Modifier: fyne.KeyModifierControl},
func(_ fyne.Shortcut) {
sizer.fontSize--
a.Settings().SetTheme(sizer)
t.Refresh()
t.Resize(t.Size())
})
go func() {
err := t.RunLocalShell()
if err != nil {
Expand Down
8 changes: 5 additions & 3 deletions cmd/fyneterm/theme.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import (

type termTheme struct {
fyne.Theme

fontSize float32
}

func newTermTheme() fyne.Theme {
return &termTheme{fyne.CurrentApp().Settings().Theme()}
func newTermTheme() *termTheme {
return &termTheme{Theme: fyne.CurrentApp().Settings().Theme(), fontSize: 12}
}

// Color fixes a bug < 2.1 where theme.DarkTheme() would not override user preference.
Expand All @@ -32,7 +34,7 @@ func (t *termTheme) Color(n fyne.ThemeColorName, v fyne.ThemeVariant) color.Colo

func (t *termTheme) Size(n fyne.ThemeSizeName) float32 {
if n == theme.SizeNameText {
return 12
return t.fontSize
}

return t.Theme.Size(n)
Expand Down
20 changes: 10 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ module github.com/fyne-io/terminal
go 1.17

require (
fyne.io/fyne/v2 v2.3.6-0.20230704203313-e050d7994adc
fyne.io/fyne/v2 v2.4.0-rc1
github.com/ActiveState/termtest/conpty v0.5.0
github.com/creack/pty v1.1.11
github.com/nicksnyder/go-i18n/v2 v2.1.2
github.com/stretchr/testify v1.8.0
golang.org/x/text v0.9.0
github.com/stretchr/testify v1.8.4
golang.org/x/text v0.12.0
)

require (
fyne.io/systray v1.10.1-0.20230602210930-b6a2d6ca2a7b // indirect
fyne.io/systray v1.10.1-0.20230722100817-88df1e0ffa9a // indirect
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fredbi/uri v0.1.0 // indirect
github.com/fredbi/uri v1.0.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/fyne-io/gl-js v0.0.0-20220119005834-d2da28d9ccfe // indirect
github.com/fyne-io/glfw-js v0.0.0-20220120001248-ee7290d23504 // indirect
Expand All @@ -32,11 +32,11 @@ require (
github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c // indirect
github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef // indirect
github.com/tevino/abool v1.2.0 // indirect
github.com/yuin/goldmark v1.4.13 // indirect
golang.org/x/image v0.7.0 // indirect
golang.org/x/mobile v0.0.0-20230427221453-e8d11dd0ba41 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/sys v0.8.0 // indirect
github.com/yuin/goldmark v1.5.5 // indirect
golang.org/x/image v0.11.0 // indirect
golang.org/x/mobile v0.0.0-20230531173138-3c911d8e3eda // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/sys v0.11.0 // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
honnef.co/go/js/dom v0.0.0-20210725211120-f030747120f2 // indirect
Expand Down
Loading

0 comments on commit d00cbc5

Please sign in to comment.