Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ permissions:
jobs:
test:
runs-on: ubuntu-24.04
env:
GOFLAGS: -tags=gtk4
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ jobs:
go-version-file: go.mod
- name: Install WebKitGTK
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y libgtk-4-dev libwebkitgtk-6.0-dev
run: sudo apt-get update && sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.1-dev
- name: Build
run: |
go build -trimpath -ldflags "-s -w" -o margin-gui ./cmd/margin-gui
go build -tags gtk3 -trimpath -ldflags "-s -w" -o margin-gui ./cmd/margin-gui
tar czf margin-gui_${GITHUB_REF_NAME}_${{ matrix.name }}.tar.gz margin-gui LICENSE
- uses: actions/upload-artifact@v4
with:
Expand Down
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ you work, or use both: a review started in one goes on in the other.
| Start a review | `margin-tui pick` lists your repositories, worktrees, branches, commits and pull requests; or `margin-tui`, `margin-tui feature-x`, `margin-tui --pr 123` in a repository | pick a repository, worktree and branch, commit or pull request in the sidebar, or ctrl+k |
| Using it | keys; the mouse picks lines, blocks, links and stops | buttons, and the same keys |
| Needs | git, tmux, an agent CLI | git, an agent CLI, a WebKit webview (built into macOS; WebKitGTK on Linux) |
| Install | `go install github.com/redrick/margin/cmd/margin-tui@latest` | `go install github.com/redrick/margin/cmd/margin-gui@latest`, then `margin-gui --install` |
| Install | `go install github.com/redrick/margin/cmd/margin-tui@latest` | `go install -tags gtk3 github.com/redrick/margin/cmd/margin-gui@latest` (no tag on macOS), then `margin-gui --install` |
| Read the manual | [docs/tui.md](docs/tui.md) | [docs/gui.md](docs/gui.md) |

> Status: early, but the whole loop works.
Expand All @@ -31,15 +31,16 @@ Download a binary for your system from the [releases](https://github.com/redrick
or build with Go 1.21 or newer (Go fetches the toolchain the module needs by itself):

```sh
go install github.com/redrick/margin/cmd/margin-tui@latest # the terminal viewer
go install github.com/redrick/margin/cmd/margin-gui@latest # the desktop app
margin-gui --install # put the desktop app in your launcher
go install github.com/redrick/margin/cmd/margin-tui@latest # the terminal viewer
go install -tags gtk3 github.com/redrick/margin/cmd/margin-gui@latest # the desktop app (no tag on macOS)
margin-gui --install # put the desktop app in your launcher
```

`go install` puts the binaries in `$(go env GOPATH)/bin`; make sure that directory is on your `PATH`.
margin-gui needs a C compiler and, on Linux, the GTK 4 and WebKitGTK 6 development packages to
build; [docs/gui.md](docs/gui.md#install) lists them per distribution, and the `-tags gtk3` build
for systems with only WebKitGTK 4.1.
margin-gui needs a C compiler and, on Linux, the GTK 3 and WebKitGTK 4.1 development packages to
build; [docs/gui.md](docs/gui.md#install) lists them per distribution. On Linux the build needs a
toolkit tag: `-tags gtk3`, or `-tags gtk4` for GTK 4 and WebKitGTK 6, which can stall for seconds
while scrolling on X11 under load.

Each binary is complete on its own. Neither needs the other, nor a separate `margin` command: the
agent they start gets a `margin` link to the binary that started it.
Expand Down Expand Up @@ -148,10 +149,10 @@ skills/margin the agent skill, embedded in both binaries
```

```sh
go test ./... # needs the margin-gui build dependencies, see docs/gui.md
go test ./internal/... # everything but the desktop app
GOFLAGS=-tags=gtk3 go test ./... # needs the margin-gui build dependencies, see docs/gui.md
go test ./internal/... # everything but the desktop app
go build ./cmd/margin-tui
go build ./cmd/margin-gui # -tags gtk3 with WebKitGTK 4.1; GOFLAGS=-tags=gtk3 for go test/vet too
go build -tags gtk3 ./cmd/margin-gui # Linux: -tags gtk3 or -tags gtk4; no tag on macOS
```

One test builds and runs a small Go module to check the coverage script end to end (`-short` skips
Expand Down
8 changes: 8 additions & 0 deletions cmd/margin-gui/toolkit_guard_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:build linux && !gtk3 && !gtk4

package main

// On Linux the toolkit is picked at build time: -tags gtk3 (GTK 3, WebKitGTK 4.1; use this on X11,
// where the GTK 4 build stalls while scrolling under load) or -tags gtk4 (GTK 4, WebKitGTK 6).
// See docs/gui.md#install.
var _ = margin_gui_on_linux_needs_tags_gtk3_or_gtk4
37 changes: 29 additions & 8 deletions docs/gui.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,38 @@ prompt and can run shell commands.

Download `margin-gui` for your system from the
[releases](https://github.com/redrick/margin/releases), or build it with Go 1.21 or newer (Go fetches
the toolchain it needs by itself). Building needs a C compiler and, on Linux, the GTK 4 and
WebKitGTK 6 development packages:
the toolchain it needs by itself). Building needs a C compiler, and on Linux you pick the toolkit
with a build tag. A Linux build without `-tags gtk3` or `-tags gtk4` stops with
`undefined: margin_gui_on_linux_needs_tags_gtk3_or_gtk4`.

GTK 3 with WebKitGTK 4.1 is the one to use, and the one the Linux release binary is built with:

```sh
# Debian, Ubuntu: sudo apt install build-essential libgtk-3-dev libwebkit2gtk-4.1-dev
# Fedora: sudo dnf install gcc gtk3-devel webkit2gtk4.1-devel
# Arch: sudo pacman -S base-devel gtk3 webkit2gtk-4.1
go install -tags gtk3 github.com/redrick/margin/cmd/margin-gui@latest
```

GTK 4 with WebKitGTK 6 builds too, but avoid it on X11:

```sh
# Debian, Ubuntu 24.04+: sudo apt install build-essential libgtk-4-dev libwebkitgtk-6.0-dev
# Fedora: sudo dnf install gcc gtk4-devel webkitgtk6.0-devel
# Arch: sudo pacman -S base-devel gtk4 webkitgtk-6.0
# macOS: xcode-select --install
go install github.com/redrick/margin/cmd/margin-gui@latest
go install -tags gtk4 github.com/redrick/margin/cmd/margin-gui@latest
```

Systems that only have the older WebKitGTK 4.1 (GTK 3) build it with `-tags gtk3`:
Under X11 the GTK 4 build handles pointer input one event at a time. A TrackPoint sends a steady
stream of small scroll events, and probably so do touchpads and high-resolution wheels. On a busy
machine the window falls behind them: scrolling stutters, and the window can stop responding for
several seconds until it catches up. The GTK 3 build scrolls smoothly under the same load.

On macOS no tag is needed:

```sh
go install -tags gtk3 github.com/redrick/margin/cmd/margin-gui@latest
xcode-select --install
go install github.com/redrick/margin/cmd/margin-gui@latest
```

Then add it to your desktop's applications, so it starts from the launcher or the Dock like any
Expand Down Expand Up @@ -343,10 +360,14 @@ What differs is how you get around:
From a checkout:

```sh
go build -o margin-gui ./cmd/margin-gui # GTK 4 / WebKitGTK 6
go build -tags gtk3 -o margin-gui ./cmd/margin-gui # WebKitGTK 4.1
go build -tags gtk3 -o margin-gui ./cmd/margin-gui # Linux: GTK 3 / WebKitGTK 4.1
go build -tags gtk4 -o margin-gui ./cmd/margin-gui # Linux: GTK 4 / WebKitGTK 6
go build -o margin-gui ./cmd/margin-gui # macOS
```

On Linux, `go vet ./...` and `go test ./...` need the tag too (`GOFLAGS=-tags=gtk3`), and so does
your editor: for gopls, set `"build.buildFlags": ["-tags=gtk3"]`.

The window is plain HTML, CSS and JavaScript in [`cmd/margin-gui/assets`](../cmd/margin-gui/assets),
embedded in the binary, with [xterm.js](https://xtermjs.org) for the agent's terminal and
[CodeMirror](https://codemirror.net) with its vim mode for trying a change. Both are checked in, so
Expand Down
2 changes: 1 addition & 1 deletion docs/screenshots/shoot-gui.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mkdir -p "$out" "$work/home/.config/margin"
echo "theme: ${MARGIN_SHOOT_THEME:-dark}" >"$work/home/.config/margin/config.yaml"

chrome=$(command -v chromium || command -v google-chrome-stable || command -v google-chrome || command -v chromium-browser)
tags=shoot
tags="shoot gtk4"
pkg-config --exists webkitgtk-6.0 2>/dev/null || tags="shoot gtk3"
go test -c -tags "$tags" -o "$work/shoot.test" ./cmd/margin-gui
go build -o "$work/margin" ./cmd/margin-tui
Expand Down
Loading