Background
Developing
How the code is laid out, the rules it keeps to, and how to check a change.
archr is one Go package, main, at the root of the repository.
Tools
- Go 1.27 or later.
- just runs every task below.
- golangci-lint and gopls, for
just check. - git lfs, which holds the pictures and recordings in these pages. Without it they are checked out as pointers, and the site cannot bake them.
| Task | Does |
|---|---|
just run [args] |
Run archr from source |
just fmt |
Format Go, and tabs in Markdown to spaces |
just check |
vet, golangci-lint and gopls with its hints |
just test |
The checks, then the tests |
just install |
Build into $GOBIN and write the agent skill |
just deps |
Update every dependency |
just quire |
Move to the latest Quire release, and nothing else |
just shots |
Retake the screenshots in these pages |
Tag a commit, as git tag v0.1.0, to mark a release.
Files
| File | Holds |
|---|---|
main.go |
Arguments, opening the project, starting the interface |
agent.go |
The agent commands and their guide |
store.go |
Annotations and comments on disk, and their upgrades |
tree.go |
The project, its file tree and project search |
config.go |
Settings |
diff.go |
Git diffs, commit messages, git show |
tui.go |
The model, the tree pane and the status bar |
reader.go |
The view: a stack of files |
review.go |
Reviews, marks, the picker, diff display |
edit.go |
The popup for writing |
thread.go |
The list of notes and one's thread |
tour.go |
Tours and the drawer |
help.go |
The ? keys |
highlight.go |
A file's lines, their styles and tab stops |
A command gets its own folder only when the repository builds more than one binary.
How the code is shaped
One view model. The view is a stack of files. A single file is a stack of one, and a folder's changes are a stack with a header above each file.
Handlers take a pointer.
Handlers take *model and return a tea.Cmd.
Only Update returns the model, and only drawing takes model by value.
Nothing looks at the disk while drawing. Lists of notes and counts are worked out once and kept until a store changes. The watcher watches every folder git does not ignore, and the notes. A change drops the file from the cache, and the tree, with a review of the working tree, is read again in the background.
One way in to files, git and searches.
A file is read to be shown only by lines, which keeps it until the file changes.
Every git command goes through git, and every search of files not yet read through grep.
Highlighting never holds a key. A file is shown plain at once and highlighted from the top only as far as the screen needs. What takes more than a few milliseconds is finished in the background and drawn when it arrives.
A file is held once, and let go. A file is its text, four bytes a line for where the line starts, and two bytes a token: how long it is, and its kind. A file over 4 MB is not read, wherever it comes from. The files read are kept up to a budget, and past it those shown longest ago are let go and read again when next shown. Lines drawn with nothing on them are kept in one small cache for every file, as only a screen of them is ever in sight. A reader keeps how it was left, its cursor and the folds opened, apart from what it works out from the file, which goes with the file. Line text and tokens are read through the reader's and the line's own methods, never from the fields.
Languages
Highlighting is Lexis, a package in Quire that imports only Go's standard library.
It turns source text into tokens, each with a kind such as comment, keyword or string, and archr gives each kind a colour in highlight.go.
A file in a language Lexis has no lexer for is shown plain.
archr takes every language Lexis comes with, at the top of highlight.go:
var set lexis.Languages
langs.Add(&set)
next := set.File("main.go", text)
Lexis's languages are listed and shown in Quire's documentation, which also says how to add one. A language is added there, and archr has it when it next takes a release of Quire.
To work on Lexis and archr together, a go.work at the root of this repository names a copy of Quire beside it, and archr builds against that.
The file is not committed.
go 1.27.4
use (
.
../quire
)
A kind Lexis gains is drawn plain until it has a style in the table in highlight.go.
Screenshots
The pictures in these pages are photographs of archr running, taken by shots/shots.sh.
It stages archr's own source at a pinned commit as a repository with a review in progress, and has vhs run archr on it for each view, type its keys and photograph it.
It needs vhs, ttyd and FiraCode Nerd Font.
In shots/ |
Holds |
|---|---|
shots.sh |
The script, with the pinned commit, the terminal's colours and each view's size and keys |
scene/change.patch |
The uncommitted change under review |
scene/annotations/ |
The annotations, committed with the staged source |
scene/review/ |
The review's comments and their replies |
scene/tours/ |
The tour |
The scene's line numbers are those of the pinned commit with the patch applied, so the pictures do not move as archr's code does.
To move the pin, change it in shots.sh, stage the scene with shots.sh --stage DIR to look at it, and bring the scene's lines up to date.
just shots retakes them all into www/docs/shots/, and just shots reader one.
A view marked film is a recording: a .webm, with the still it starts on as its poster.
Checking a change
Run just check and just test.
Then test in a real terminal, in a throwaway repository such as one under .state/, which git ignores.
archr writes notes into the repository it is browsing, so never test in a project you care about.
Tests use fixtures or files they make themselves. There is one test file, and a test earns its place by catching an edge case or a bug that has happened.