skip to content
szczecin 53.43N 14.55E ./start-project

go-fyne-pretty-view 2.8: your colors in a free Fyne widget

(go, fyne, open-source, release-notes) 23 min read by Bartosz Pachołek

go-fyne-pretty-view 2.8.0 lets a Fyne app color the formats our free widget cannot parse, draws indent guides in the editor and adds word-wise caret moves. We built a YAML editor with it and ran 2.7.0 and 2.8.0 side by side.

go-fyne-pretty-view is our free, open-source (BSD-3-Clause) Fyne widget for viewing and editing JSON, JSONC, XML, HTML and raw text. Version 2.8.0, released on 2 December 2026, lets the app that hosts it color text formats the widget has no parser for, draws indent guides in the editor as well as in the viewer, and makes Shift+Left/Right and word-wise caret moves work. All three came from an outside contributor, Leadaxe, who filed the issues and wrote the pull requests.

This is our first post on the library, so it also covers 2.7.0 from September, the first release without the -alpha suffix. We ran everything with Go 1.27.4 on Linux and Fyne 2.8.3 in every module: the same programs against v2.6.0-alpha, v2.7.0 and v2.8.0 from the Go module proxy, so only the widget differs. The images come from Fyne's software painter at 2x, the way the repo renders its own README screenshots, and we also opened the example app in a real window. The outputs are pasted as they came out.

GitHub release page of go-fyne-pretty-view v2.8.0: host colorizers for raw text, editor indent guides, word-wise caret moves, with the first Added entry

What the widget is

go-fyne-pretty-view draws a document the way an API client's response panel does: line numbers, folding with item counts, search with a match counter and soft wrap. Only the rows on screen exist as canvas objects. Everything else lives in a compact model, so multi-megabyte documents stay fast. It is the response viewer in Helena, our API client, and WithEditable() turns the same widget into an editor that colors the text while you type. Our older post on building Helena with Go and Fyne explains why we went native.

The exported API of the /v2 module is frozen: a test, TestExportedSurfaceGolden, pins every exported name and signature, additions ship as minor releases, and a breaking change would need a new module path, /v3. That matters for this release, because 2.8.0 is all additions and fixes.

WithColorizer: colors for formats the widget cannot parse

Up to 2.7, text the widget could not parse as JSON, JSONC, XML or HTML was FormatRaw, and raw text was monochrome in the viewer and the editor alike. Leadaxe's issue (#134) listed the cases: INI-style configs such as a WireGuard .conf, proxy share URIs and log lines. More built-in formats would not solve it, because, as the issue put it, "every host has its own grammar".

So 2.8.0 adds an extension point. From colorizer.go:

go
type Colorizer func(dst []ColorSpan, src []byte) []ColorSpan

func WithColorizer(c Colorizer) Option

The host's function gets the whole document (or edit buffer) as src and appends ColorSpan{Start, End, Role} values: byte ranges, not columns. Bytes that no span covers stay plain. The roles are the widget's existing color slots, now public: RolePlain, RoleKey, RoleString, RoleNumber, RoleBool, RoleNull, RolePunct, RoleTag, RoleAttr, RoleComment and RoleMuted. Each one resolves to a field of the widget's Theme, so a host grammar follows WithTheme and WithSyntaxColors overrides and the light and dark variants without extra work.

Where it applies, according to the release notes and the doc comments:

  • Whenever the effective format is FormatRaw: set explicitly, or FormatAuto when detection finds no JSON, XML or HTML. Structured formats keep their own parsers, and a structured document that fails to parse still falls back to plain raw lines.
  • In the read-only viewer, line by line, with tabs still expanded to WithTabWidth.
  • In the editor, on every keystroke, on the UI goroutine, for buffers up to the existing 2 MiB live-color budget. A line longer than 16 KiB stays uncolored, as with the built-in formats.

The widget does not trust the spans. It sorts them by Start, resolves overlaps first-wins, clamps them to the text, maps an unknown role to plain and changes color only at the start of a rune. A colorizer that panics leaves the text uncolored instead of taking the window down. And the append signature is there for speed: the editor hands the previous call's slice back as dst, so a colorizer that appends allocates nothing per keystroke once it has warmed up (#80). The price is one rule for hosts: return dst or a fresh slice, never a slice you keep, because the widget may sort it in place.

Proof of concept: a YAML editor in about 200 lines

The widget has no YAML parser, and YAML is both line-oriented and deeply indented, so a small YAML editor exercises the colorizer and the new editor guides at once. yamlview is one Go module with two source files and a sample. The top of its go.mod (go mod tidy adds the indirect requirements under it):

text
module example.com/yamlview

go 1.26.0

require (
	fyne.io/fyne/v2 v2.8.3
	github.com/ideaconnect/go-fyne-pretty-view/v2 v2.8.0
)

The grammar, yaml.go:

go
package main

import (
	"bytes"
	"strconv"

	pv "github.com/ideaconnect/go-fyne-pretty-view/v2"
)

// yamlColorizer is a line-oriented YAML grammar for WithColorizer: comments, "key:"
// pairs, list dashes, scalars by type and block scalars (| and >). It appends its
// spans to dst, so the widget can hand the same slice back on the next keystroke.
func yamlColorizer(dst []pv.ColorSpan, src []byte) []pv.ColorSpan {
	block := -1 // indent of the key that opened a | or > block, -1 when outside
	for start := 0; start < len(src); {
		end := bytes.IndexByte(src[start:], '\n')
		if end < 0 {
			end = len(src)
		} else {
			end += start
		}
		line := src[start:end]
		body := bytes.TrimLeft(line, " ")
		indent := len(line) - len(body)
		at := start + indent
		switch {
		case len(bytes.TrimSpace(body)) == 0:
		case block >= 0 && indent > block:
			dst = append(dst, sp(at, end, pv.RoleString))
		case body[0] == '#':
			block = -1
			dst = append(dst, sp(at, end, pv.RoleComment))
		default:
			block = -1
			for bytes.HasPrefix(src[at:end], []byte("- ")) {
				dst = append(dst, sp(at, at+1, pv.RolePunct))
				at += 2
			}
			rest := src[at:end]
			key := bytes.Index(rest, []byte(": "))
			if key < 0 && bytes.HasSuffix(rest, []byte(":")) {
				key = len(rest) - 1
			}
			if key > 0 && rest[0] != '"' && rest[0] != '\'' {
				dst = append(dst, sp(at, at+key, pv.RoleKey),
					sp(at+key, at+key+1, pv.RolePunct))
				at += key + 1
			}
			var opens bool
			dst, opens = yamlValue(dst, src, at, end)
			if opens {
				block = indent
			}
		}
		start = end + 1
	}
	return dst
}

// yamlValue colors the scalar in src[at:end] and a trailing "# comment". It reports
// whether the value opens a block scalar (| or >), whose lines follow indented.
func yamlValue(dst []pv.ColorSpan, src []byte, at, end int) ([]pv.ColorSpan, bool) {
	for at < end && src[at] == ' ' {
		at++
	}
	if c := bytes.Index(src[at:end], []byte(" #")); c >= 0 {
		dst = append(dst, sp(at+c+1, end, pv.RoleComment))
		end = at + c
	}
	v := string(bytes.TrimRight(src[at:end], " "))
	if v == "" {
		return dst, false
	}
	role := pv.RoleString
	switch {
	case v == "|" || v == ">" || v == "|-" || v == ">-":
		return append(dst, sp(at, at+len(v), pv.RolePunct)), true
	case v == "true" || v == "false":
		role = pv.RoleBool
	case v == "null" || v == "~":
		role = pv.RoleNull
	case v[0] == '&' || v[0] == '*':
		role = pv.RoleAttr
	default:
		if _, err := strconv.ParseFloat(v, 64); err == nil {
			role = pv.RoleNumber
		}
	}
	return append(dst, sp(at, at+len(v), role)), false
}

// sp is one span: the bytes [start, end) get role.
func sp(start, end int, role pv.ColorRole) pv.ColorSpan {
	return pv.ColorSpan{Start: start, End: end, Role: role}
}

It is a sketch, not a YAML parser. A # inside a quoted string would be taken for a comment, and a flow collection such as [main] is colored as one string. It does carry one piece of state from line to line, the indent of a key that opened a block scalar, so the lines under run: | come out as strings instead of keys. That works because the colorizer is given the whole document rather than one line at a time.

The app, main.go, opens a window by default. The two flags are there so we can show its output here: -spans prints what the colorizer reports, and -shot renders the same view to a PNG through Fyne's test driver, without a display:

go
// yamlview is a small YAML editor built on go-fyne-pretty-view 2.8. The widget has
// no YAML parser: yamlColorizer (yaml.go) supplies the colors through WithColorizer,
// and the editor draws the indent guides by itself.
//
//	go run .                    edit sample.yaml in a window
//	go run . -shot out.png      render the same view to a PNG, no display needed
//	go run . -spans 26:32       print the colorizer's spans for lines 26 to 32
package main

import (
	"flag"
	"fmt"
	"image"
	"image/color"
	"image/png"
	"os"

	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/driver/software"
	"fyne.io/fyne/v2/test"
	"fyne.io/fyne/v2/theme"
	pv "github.com/ideaconnect/go-fyne-pretty-view/v2"
	"github.com/ideaconnect/go-fyne-pretty-view/v2/fonttheme"
)

func main() {
	file := flag.String("file", "sample.yaml", "YAML file to open")
	shot := flag.String("shot", "", "write a PNG instead of opening a window")
	spans := flag.String("spans", "", "print the colorizer's spans for lines FROM:TO")
	flag.Parse()

	src, err := os.ReadFile(*file)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	if *spans != "" {
		var from, to int
		fmt.Sscanf(*spans, "%d:%d", &from, &to)
		printSpans(src, from, to)
		return
	}

	var a fyne.App
	if *shot != "" {
		a = test.NewApp()
	} else {
		a = app.New()
	}
	a.Settings().SetTheme(fonttheme.New(theme.DefaultTheme()))

	ed := pv.NewWithData(src, pv.FormatRaw, pv.WithEditable(), pv.WithLineNumbers(),
		pv.WithColorizer(yamlColorizer))
	bar := pv.NewToolbar(ed, pv.ToolbarConfig{ShowWrap: true, ShowSearch: true,
		IconColor: color.NRGBA{0x4f, 0xd6, 0xe6, 0xff}})
	content := container.NewBorder(bar, nil, nil, nil, ed)

	if *shot == "" {
		w := a.NewWindow("yamlview: " + *file)
		w.SetContent(content)
		w.Resize(fyne.NewSize(720, 810))
		w.Canvas().Focus(ed)
		w.ShowAndRun()
		return
	}
	w := test.NewWindow(content)
	w.Canvas().(software.WindowlessCanvas).SetScale(2)
	w.Resize(fyne.NewSize(720, 810))
	ed.FocusGained()
	ed.SetCaret(24, 21)
	ed.Refresh()
	writePNG(w.Canvas().Capture(), *shot)
}

// printSpans lists what yamlColorizer reports for lines from..to (1-based), in the
// order the colorizer appended them.
func printSpans(src []byte, from, to int) {
	names := map[pv.ColorRole]string{pv.RoleKey: "key", pv.RolePunct: "punct",
		pv.RoleString: "string", pv.RoleNumber: "number", pv.RoleBool: "bool",
		pv.RoleNull: "null", pv.RoleComment: "comment", pv.RoleAttr: "attr"}
	line, lineStart := 1, 0
	for _, s := range yamlColorizer(nil, src) {
		for i := lineStart; i < s.Start; i++ {
			if src[i] == '\n' {
				line, lineStart = line+1, i+1
			}
		}
		if line > to {
			return
		}
		if line >= from {
			fmt.Printf("line %d  %-7s %q\n", line, names[s.Role], src[s.Start:s.End])
		}
	}
}

func writePNG(img image.Image, path string) {
	f, err := os.Create(path)
	if err == nil {
		err = png.Encode(f, img)
		f.Close()
	}
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	b := img.Bounds()
	fmt.Printf("wrote %s (%dx%d px)\n", path, b.Dx(), b.Dy())
}

The toolbar uses IconColor, one of the two fields 2.7.0 added (more on that below). The sample is a CI workflow, sample.yaml:

yaml
# CI for a Fyne app: test on three systems, build on tags
name: ci
on:
  push:
    branches: [main]
    tags: ["v*"]
  pull_request: ~

env:
  GO_VERSION: "1.26.11"
  CGO_ENABLED: 1

jobs:
  test:
    runs-on: ${{ matrix.os }}
    timeout-minutes: 20
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-go@v5
        with:
          go-version: ${{ env.GO_VERSION }}
          cache: true # keyed on go.sum
      - name: Fyne's Linux dependencies
        if: runner.os == 'Linux'
        run: |
          sudo apt-get update
          sudo apt-get install -y libgl1-mesa-dev xorg-dev \
            libwayland-dev libxkbcommon-dev
      - run: go test -race ./...

What the colorizer reports for lines 26 to 32:

bash
go run . -spans 26:32
text
line 26  key     "cache"
line 26  punct   ":"
line 26  comment "# keyed on go.sum"
line 26  bool    "true"
line 27  punct   "-"
line 27  key     "name"
line 27  punct   ":"
line 27  string  "Fyne's Linux dependencies"
line 28  key     "if"
line 28  punct   ":"
line 28  string  "runner.os == 'Linux'"
line 29  key     "run"
line 29  punct   ":"
line 29  punct   "|"
line 30  string  "sudo apt-get update"
line 31  string  "sudo apt-get install -y libgl1-mesa-dev xorg-dev \\"
line 32  string  "libwayland-dev libxkbcommon-dev"

Line 26 shows the sanitizing at work: the colorizer appended the comment before the true that precedes it, and the widget sorts the spans, so nothing breaks. And the picture:

bash
go run . -shot ../out/yamlview.png
text
wrote ../out/yamlview.png (1440x1620 px)

yamlview, a YAML editor built on go-fyne-pretty-view 2.8: keys, strings, numbers, booleans and comments colored by a host colorizer, indent guides, cyan toolbar icons

Keys, strings, numbers, booleans, the ~ null and the comments all take their colors from the default dark theme, and the indent guides come from the widget itself, which is the next feature. go run . without flags opens the same editor in a window, where the widget calls yamlColorizer again on every keystroke.

Because main.go imports fyne.io/fyne/v2/app, every mode needs the usual Fyne build dependencies: a C compiler and, on Debian and Ubuntu, libgl1-mesa-dev xorg-dev libwayland-dev libxkbcommon-dev, as the library's README lists. Our Ubuntu machine had most of them but not the Xinerama and XF86VidMode development files, and the build stopped at X11/extensions/Xinerama.h: No such file or directory. We unpacked the two packages that carry them, libxinerama-dev and libxxf86vm-dev, into a local directory and pointed CGO_CFLAGS and CGO_LDFLAGS at it; installing them, or xorg-dev, which depends on both, does the same. We then started the window on a virtual X display, and the GLFW window looked the same as the 2x render above, at 1x. One catch there: since Fyne 2.8 a Linux build includes the Wayland backend too, and our session's WAYLAND_DISPLAY and XDG_SESSION_TYPE made GLFW try Wayland first, which failed on the X-only display. Unsetting both for that run was enough; the README's other option is to build with -tags x11.

Indent guides in the editor

The read-only viewer has always drawn a thin vertical guide per nesting level. The editor drew none, so a document looked flatter the moment it was opened for editing (Leadaxe's #132). The cause is structural. The editor shows each line as raw text with its indentation kept as literal whitespace, so that every rune on screen is one rune of the buffer, and that 1:1 mapping is what keeps the caret, the selection and hit testing aligned. The viewer's guides come from a line's nesting depth, which also indents the text, so they could not simply be switched on.

2.8.0 draws the editor's guides from each line's leading whitespace instead, on the indentation columns, so no text moves. The indent unit is detected from the buffer on every reprojection: the most frequent step of 1 to 8 columns between consecutive non-blank lines. Two-space, four-space and tab-indented buffers therefore all get one guide per level. Blank lines continue the guides of their block, a row shows at most 32 guides, and the continuation rows of a soft-wrapped line show none. There is no API change, and folding in the editor is not part of it.

To see it, we render three editors side by side, with the same file on 2.7.0 and on 2.8.0. One Go module per release, filled by a small script:

bash
#!/bin/sh
# Copy the shared example programs into one Go module per release, so the same file
# runs against each version of the widget (and the same Fyne, v2.8.3, in all three).
set -e
cd "$(dirname "$0")"
for v in v2.6.0-alpha v2.7.0 v2.8.0; do
	mkdir -p "$v"
	cat > "$v/go.mod" <<EOF
module example.com/pv-$v

go 1.26.0

require (
	fyne.io/fyne/v2 v2.8.3
	github.com/ideaconnect/go-fyne-pretty-view/v2 $v
)
EOF
	for p in keys guides toolbar; do
		mkdir -p "$v/$p"
		cp "src/$p/main.go" "$v/$p/main.go"
	done
	(cd "$v" && go mod tidy)
done

The program, guides/main.go:

go
// guides renders three editors (WithEditable) side by side to a PNG with Fyne's
// software painter: YAML indented by two spaces, JSON by four and Go by tabs.
//
//	go run ./guides guides.png
package main

import (
	"fmt"
	"image/png"
	"os"

	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/driver/software"
	"fyne.io/fyne/v2/test"
	"fyne.io/fyne/v2/theme"
	"fyne.io/fyne/v2/widget"
	pv "github.com/ideaconnect/go-fyne-pretty-view/v2"
	"github.com/ideaconnect/go-fyne-pretty-view/v2/fonttheme"
)

var buffers = []struct {
	title  string
	format pv.Format
	text   string
}{
	{"deploy.yaml, 2 spaces", pv.FormatRaw, `service:
  name: api
  replicas: 3
  ports:
    - name: http
      port: 8080

    - name: metrics
      port: 9090
  env:
    LOG_LEVEL: info`},
	{"user.json, 4 spaces", pv.FormatJSON, `{
    "id": 42,
    "name": "ada",
    "roles": [
        "admin",
        "dev"
    ],
    "prefs": {
        "theme": "dark",
        "wrap": true
    }
}`},
	{"main.go, tabs", pv.FormatRaw, "func main() {\n" +
		"\tfor _, f := range files {\n" +
		"\t\tif f.Size > max {\n" +
		"\t\t\tskip(f)\n" +
		"\t\t\tcontinue\n" +
		"\t\t}\n" +
		"\n" +
		"\t\tload(f)\n" +
		"\t}\n" +
		"}"},
}

func main() {
	a := test.NewApp()
	a.Settings().SetTheme(fonttheme.New(theme.DefaultTheme()))
	var cols []fyne.CanvasObject
	var eds []*pv.PrettyView
	for _, b := range buffers {
		ed := pv.New(pv.WithEditable(), pv.WithLineNumbers(),
			pv.WithInputConfig(pv.InputConfig{AutoFormat: pv.AutoFormatOff}))
		ed.SetData([]byte(b.text), b.format)
		eds = append(eds, ed)
		title := widget.NewLabelWithStyle(b.title, fyne.TextAlignLeading,
			fyne.TextStyle{Bold: true})
		cols = append(cols, container.NewBorder(title, nil, nil, nil, ed))
	}
	win := test.NewWindow(container.NewGridWithColumns(3, cols...))
	win.Canvas().(software.WindowlessCanvas).SetScale(2)
	win.Resize(fyne.NewSize(900, 330))
	for _, ed := range eds {
		ed.Refresh()
	}

	f, err := os.Create(os.Args[1])
	if err != nil {
		panic(err)
	}
	img := win.Canvas().Capture()
	if err := png.Encode(f, img); err != nil {
		panic(err)
	}
	f.Close()
	b := img.Bounds()
	fmt.Printf("wrote %s (%dx%d px)\n", os.Args[1], b.Dx(), b.Dy())
}
bash
for v in v2.7.0 v2.8.0; do (cd $v && go run ./guides ../out/guides-$v.png); done
text
wrote ../out/guides-v2.7.0.png (1800x660 px)
wrote ../out/guides-v2.8.0.png (1800x660 px)

The same three editors (YAML with 2 spaces, JSON with 4, Go with tabs) on v2.7.0 without indent guides and on v2.8.0 with one guide per indent level

The YAML gets a guide every two columns and the JSON one every four, each under the first character of the enclosing line. The blank line 7 in the YAML keeps the guides of its block. The Go panel shows how the editor treats tabs: each tab is one column, drawn as a small dot, because of the same 1:1 rule, and the guides sit on those columns.

Shift+Left/Right and moving by word

Leadaxe's first issue (#129), written against 2.7.0 on macOS, found two gaps. In the editor, Shift+Left and Shift+Right moved nothing and selected nothing, while Shift+Up, Shift+Down, Shift+Home and Shift+End worked. And there was no word-wise caret movement at all. Both are what anyone coming from Fyne's own widget.Entry expects.

In 2.8.0, in the viewer and the editor alike:

  • Shift+Left/Right grow or shrink the selection one rune at a time from the caret, crossing a line end into the next visible line, past a collapsed node's hidden lines and past every row of a soft-wrapped line.
  • Ctrl+Left/Right on Linux and Windows, and Option+Left/Right on macOS, the mapping widget.Entry uses, move the caret to the previous or next word boundary, with the same word classes a double-click selects. With Shift they extend the selection.
  • In the editor, a plain Left/Right with a selection collapses it onto its left or right end, as widget.Entry does, and a word step ends the current undo typing run like any other caret move.

This program sends the keys the way Fyne's desktop driver delivers them (a key-down for Shift followed by the arrow; Ctrl+arrow as a desktop.CustomShortcut, as the library's own tests do) and prints the selection and the caret. It runs on the headless test driver:

go
// keys sends Shift+Left/Right and the word-step shortcut to a raw-text viewer and to an
// editor, the way Fyne's desktop driver delivers them, and prints what happened.
// It runs on Fyne's headless test driver: no window opens, no display is needed.
package main

import (
	"fmt"

	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/driver/desktop"
	"fyne.io/fyne/v2/test"
	pv "github.com/ideaconnect/go-fyne-pretty-view/v2"
)

const text = "user.name = ada  # admin\nuser.id = 1"

// key presses an arrow n times (Shift counts if it is held down).
func key(v *pv.PrettyView, name fyne.KeyName, n int) {
	for i := 0; i < n; i++ {
		v.TypedKey(&fyne.KeyEvent{Name: name})
	}
}

// word sends Ctrl+arrow, the word step on Linux and Windows (macOS: KeyModifierAlt),
// with Shift when shift is true.
func word(v *pv.PrettyView, name fyne.KeyName, shift bool) {
	mod := fyne.KeyModifierControl
	if shift {
		mod |= fyne.KeyModifierShift
	}
	v.TypedShortcut(&desktop.CustomShortcut{KeyName: name, Modifier: mod})
}

func shift(v *pv.PrettyView, down bool) {
	if down {
		v.KeyDown(&fyne.KeyEvent{Name: desktop.KeyShiftLeft})
	} else {
		v.KeyUp(&fyne.KeyEvent{Name: desktop.KeyShiftLeft})
	}
}

func main() {
	test.NewApp()
	for _, mode := range []string{"viewer", "editor"} {
		opts := []pv.Option{}
		if mode == "editor" {
			opts = append(opts, pv.WithEditable())
		}
		v := pv.NewWithData([]byte(text), pv.FormatRaw, opts...)
		win := test.NewWindow(v)
		win.Resize(fyne.NewSize(600, 200))
		v.FocusGained()
		fmt.Println("==", mode)

		v.SetCaret(0, 0)
		shift(v, true)
		key(v, fyne.KeyRight, 4)
		fmt.Printf("Shift+Right x4 from (0,0):  selected %q\n", v.SelectedText())
		key(v, fyne.KeyLeft, 2)
		fmt.Printf("then Shift+Left x2:         selected %q\n", v.SelectedText())
		shift(v, false)

		v.SetCaret(0, 0)
		steps := ""
		for i := 0; i < 5; i++ {
			word(v, fyne.KeyRight, false)
			l, c := v.Caret()
			steps += fmt.Sprintf(" (%d,%d)", l, c)
		}
		fmt.Println("Ctrl+Right x5 from (0,0): " + steps)

		v.SetCaret(0, 24) // end of the first line
		word(v, fyne.KeyRight, false)
		l, c := v.Caret()
		fmt.Printf("Ctrl+Right at a line end:   caret (%d,%d)\n", l, c)

		v.SetCaret(0, 0)
		for i := 0; i < 3; i++ {
			word(v, fyne.KeyRight, true)
		}
		fmt.Printf("Ctrl+Shift+Right x3:        selected %q\n", v.SelectedText())

		key(v, fyne.KeyRight, 1) // Shift is up: a plain Right
		l, c = v.Caret()
		fmt.Printf("then a plain Right:         caret (%d,%d), selected %q\n",
			l, c, v.SelectedText())
		win.Close()
	}
}

On 2.7.0:

bash
cd v2.7.0 && go run ./keys
text
== viewer
Shift+Right x4 from (0,0):  selected ""
then Shift+Left x2:         selected ""
Ctrl+Right x5 from (0,0):  (0,0) (0,0) (0,0) (0,0) (0,0)
Ctrl+Right at a line end:   caret (0,24)
Ctrl+Shift+Right x3:        selected ""
then a plain Right:         caret (0,0), selected ""
== editor
Shift+Right x4 from (0,0):  selected ""
then Shift+Left x2:         selected ""
Ctrl+Right x5 from (0,0):  (0,0) (0,0) (0,0) (0,0) (0,0)
Ctrl+Right at a line end:   caret (0,24)
Ctrl+Shift+Right x3:        selected ""
then a plain Right:         caret (0,1), selected ""

Nothing selects and nothing moves by word. The one change in the editor's last line is the plain Right, which stepped one rune from (0,0) because there was no selection to collapse. On 2.8.0:

bash
cd v2.8.0 && go run ./keys
text
== viewer
Shift+Right x4 from (0,0):  selected "user"
then Shift+Left x2:         selected "us"
Ctrl+Right x5 from (0,0):  (0,4) (0,5) (0,9) (0,11) (0,15)
Ctrl+Right at a line end:   caret (1,0)
Ctrl+Shift+Right x3:        selected "user.name"
then a plain Right:         caret (0,9), selected "user.name"
== editor
Shift+Right x4 from (0,0):  selected "user"
then Shift+Left x2:         selected "us"
Ctrl+Right x5 from (0,0):  (0,4) (0,5) (0,9) (0,11) (0,15)
Ctrl+Right at a line end:   caret (1,0)
Ctrl+Shift+Right x3:        selected "user.name"
then a plain Right:         caret (0,9), selected ""

The word stops follow the double-click classes: user, then the . on its own, name, the =, then ada, with the whitespace skipped. At the end of the first line a word step goes to the start of the second. Three Ctrl+Shift+Right select user.name. The last line is where the two modes differ. The editor collapses the selection onto its right end, (0,9). In the viewer a plain arrow did not move the caret in either release (on 2.7.0 it stayed at (0,0) as well), so the selection stays.

2.7.0: the first release without -alpha

2.7.0 (12 September 2026) is the first tag on the /v2 line without an -alpha suffix. According to its changelog nothing in the API changed for that: the exported surface had been frozen since v2.0.0, and the suffix only marked maturity. It also added two fields to ToolbarConfig. IconColor sets the glyph color of every icon button NewToolbar builds, the cyan in the yamlview picture above, and ActiveIconColor sets the wrap toggle's glyph while wrapping is on. Both are nil by default, which means "follow the theme".

The bigger change in that release is behind them: the toolbar glyphs became theme.ThemedResources instead of SVGs with the theme's foreground baked in when the toolbar was built. So they follow a light/dark switch at runtime, and the wrap toggle stays readable while it is on. A widget.Button with high importance recolors a themed icon to the theme's foregroundOnPrimary, so a theme with a light primary and a light foreground no longer gets a light glyph on a light fill. We rendered exactly that case, a bright green primary with a light gray foreground, on 2.6.0-alpha and 2.7.0:

go
// toolbar renders the built-in toolbar, with soft wrap on, under a host theme whose
// primary color is a bright green and whose foreground is a light gray.
//
//	go run ./toolbar toolbar.png
package main

import (
	"fmt"
	"image/color"
	"image/png"
	"os"

	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/driver/software"
	"fyne.io/fyne/v2/test"
	"fyne.io/fyne/v2/theme"
	pv "github.com/ideaconnect/go-fyne-pretty-view/v2"
	"github.com/ideaconnect/go-fyne-pretty-view/v2/fonttheme"
)

// lime is the default dark theme with a light primary and a light foreground.
type lime struct{ fyne.Theme }

func (t lime) Color(n fyne.ThemeColorName, v fyne.ThemeVariant) color.Color {
	switch n {
	case theme.ColorNamePrimary:
		return color.NRGBA{0x9c, 0xe6, 0x3c, 0xff}
	case theme.ColorNameForeground:
		return color.NRGBA{0xdc, 0xdc, 0xdc, 0xff}
	case theme.ColorNameForegroundOnPrimary:
		return color.NRGBA{0x14, 0x24, 0x08, 0xff}
	}
	return t.Theme.Color(n, v)
}

func main() {
	a := test.NewApp()
	a.Settings().SetTheme(fonttheme.New(lime{theme.DefaultTheme()}))
	v := pv.NewWithData([]byte(`{"name":"ada","tags":["admin","dev"],"id":42}`),
		pv.FormatJSON, pv.WithWrap(pv.WrapWord), pv.WithLineNumbers())
	bar := pv.NewToolbar(v, pv.ToolbarConfig{ShowFormat: true,
		ShowExpandCollapse: true, ShowWrap: true, ShowSearch: true})
	win := test.NewWindow(container.NewBorder(bar, nil, nil, nil, v))
	win.Canvas().(software.WindowlessCanvas).SetScale(2)
	win.Resize(fyne.NewSize(640, 150))
	v.Refresh()

	f, err := os.Create(os.Args[1])
	if err != nil {
		panic(err)
	}
	img := win.Canvas().Capture()
	if err := png.Encode(f, img); err != nil {
		panic(err)
	}
	f.Close()
	b := img.Bounds()
	fmt.Printf("wrote %s (%dx%d px)\n", os.Args[1], b.Dx(), b.Dy())
}
bash
for v in v2.6.0-alpha v2.7.0; do (cd $v && go run ./toolbar ../out/toolbar-$v.png); done
text
wrote ../out/toolbar-v2.6.0-alpha.png (1280x300 px)
wrote ../out/toolbar-v2.7.0.png (1280x300 px)

The toolbar under a bright green primary color with wrap on: a light glyph on the green fill in v2.6.0-alpha, a dark readable glyph in v2.7.0

The changelog also lists a fix for the search glyph, which Fyne's rasterizer drew as a half-filled disc because Font Awesome's magnifying glass uses two exact 180-degree arcs. On Fyne 2.8.3, which all our modules use, 2.6.0-alpha already drew a clean ring, as the picture shows, so we cannot show that bug. The other items in 2.7.0:

  • Go 1.26 became the floor (go 1.26.0 in go.mod), because the golang.org/x releases it depends on require it.
  • Release notes now come from CHANGELOG.md: the release workflow fails before building anything when a tag has no section there.
  • The nightly fuzz job stopped dying. Each fuzz run used to create its own test app and window, and the changelog reports that workers now stay at about 160 MB, with throughput up from about 110 to about 850 executions per second.

Security: a newer pinned toolchain

2.8.0 also moves the repo's pinned toolchain from go1.26.8 to go1.26.11. govulncheck had reported 11 reachable standard-library advisories against go1.26.8, in net/http, net/textproto, crypto/tls and crypto/x509, fixed across go1.26.9 to go1.26.11, and the CI vulnerability gate failed. The module's go 1.26.0 floor did not change. This only affects the repo's own CI and release builds, because an app that uses the widget is built with its own toolchain. If yours is a go1.26 release older than go1.26.11, those advisories are worth a look on your side too. Dependabot also moved Fyne from 2.8.1 to 2.8.3 in this release.

Upgrading

bash
go get github.com/ideaconnect/go-fyne-pretty-view/[email protected]
  • Nothing to change in your code. 2.8.0 only adds names: WithColorizer, Colorizer, ColorSpan, ColorRole and the role constants.
  • It requires Fyne 2.8.3, so go get raises Fyne to 2.8.3 if your module is on an older 2.8 release.
  • Keyboard behavior changes: Shift+Left/Right now select, Ctrl+Left/Right (Option on macOS) now move by word, and in the editor a plain Left/Right with a selection collapses it instead of stepping one rune.
  • Coming from 2.6.0-alpha or older: Go 1.26 is required since 2.7.0, and a toolbar no longer needs rebuilding after a theme change.

Thanks, and where to get it

Thank you, Leadaxe: issues #129, #132 and #134 and pull requests #131, #133 and #135, your first contributions to the project, are this whole release apart from the toolchain and dependency updates.