diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-06 19:06:32 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-22 10:03:15 -0300 |
| commit | 046979b877f02a91cf52cc86b84c5619cb9363d3 (patch) | |
| tree | b0a4696329949029aef88be34e242a45b1babfc4 | |
| parent | d65ec3394ff619118d9208718477469c673a5598 (diff) | |
| download | pardes-046979b877f02a91cf52cc86b84c5619cb9363d3.tar.gz pardes-046979b877f02a91cf52cc86b84c5619cb9363d3.zip | |
Def and Refs in a language-served file's tag, a diff viewer's tinted word edits, context rows that hold still under a scroll, and the pardes skill
Def and Refs (gd, gr, Ctrl-click; chorded 2-1 at the selection) for a file
a language server speaks for; hunks.zig stacks a unified diff as a diff
viewer does, its changed words on a tinted ground as delta's do; the
tree-sitter context rows stay put while the body glides under a scroll;
.agents/skills gains the pardes skill beside pardes-9p.
40 files changed, 1625 insertions, 207 deletions
diff --git a/.agents/skills/pardes-9p/SKILL.md b/.agents/skills/pardes-9p/SKILL.md index 06edbdf2..2b80c975 100644 --- a/.agents/skills/pardes-9p/SKILL.md +++ b/.agents/skills/pardes-9p/SKILL.md @@ -1,54 +1,104 @@ --- name: pardes-9p -description: Inspect and drive a running Pardes editor through its virtual filesystem (served over 9P), or exercise its panes, builtins, terminal input and rendered output in an isolated session. Use for Pardes interaction, plugin development and end-to-end debugging. +description: Script and drive a running pardes session through its virtual filesystem (served over 9P), or exercise its panes, builtins, terminals, events and rendered screen in an isolated session. Use for reading or editing panes, opening files at places, running commands and reading their output, event helpers and tag words, plugin development and end-to-end debugging. For what pardes is and its keys, use the pardes skill. --- -# Pardes over 9P +# pardes over 9P -Pardes is files: `cat`, `echo >`, `ls` and shell scripts are the whole -interface. The recipes are in the Scripting chapter -([docs/typ/scripting.typ](../../../docs/typ/scripting.typ)), every file's -semantics in the Reference chapter -([docs/typ/reference.typ](../../../docs/typ/reference.typ)), and a running -session serves a summary at `$m/README`. Paths are relative to the -repository root. +pardes is files: `cat`, `echo >`, `ls` and shell scripts are the whole +interface. The recipes and traps are the Scripting chapter +(`docs/typ/scripting.typ`), every file's semantics, refusals and limits the +Reference chapter (`docs/typ/reference.typ`; its "The tree" lists every +file), and a running session serves a one-screen summary at `$m/README`. +Paths are relative to the pardes source tree, the repository this skill +lives in (`readlink -f` this skill's directory if it is reached through a +symlink). ## Find the session +First check that you run inside a live session (the pardes skill's "Am I +in a pardes session?"); a session merely listed under `$NINE_MOUNT/pardes/` +is someone's, not yours to script. + ```sh m=${PARDES_MOUNT:-} [ -n "$m" ] || echo 'no mount: use 9p -a "unix!$PARDES_9P" read index' -cat "$m/index" +cat "$m/index" # serial kind(text|term|cmd|pdf|image) dirty name column ``` Under `9ns --mntgen` every pane gets `$PARDES_MOUNT`, its session as a -directory (also in a `Tty9p` shell). `$PARDES_9P` is the session socket of -the pane you run in, `$PARDES_PANE` that pane's serial. A dead session's -entry answers `Input/output error`: name the session, never glob. Without a -mount, plan9port's `9p -a "unix!$PARDES_9P"` works, and `test/ninep.py` in the source tree (Reference, "Other ways in"). +directory (also in a `Tty9p` shell). `$PARDES_9P` is the session socket, +`$PARDES_PANE` the serial of the pane the shell runs in, `$winid` the pane +a command was clicked in. Without a mount, `cat $m/x` is +`9p -a "unix!$PARDES_9P" read x` (its `write` truncates: on `body` it +replaces the text), and `test/ninep.py` is a Python client for holding a +fid open (Reference, "Other ways in"). A dead session's registry entry +answers `Input/output error`: name the session, never glob. + +## Recipes + +Work through a pane of your own, its own `look` and `exec`: + +```sh +n=$(cat $m/pane/new); p=$m/pane/$n # read pane/new once: each open makes a pane +exec 3<>$p/look; echo "$PWD/main.zig:120" >&3; cat <&3; exec 3<&- # open at a place; read: its pane +printf 'hello\n' > $p/body; echo "$PWD/x.txt" > $p/name; echo Save > $p/ctl +echo 'Msg hello' > $p/exec # a builtin, or else a shell line +echo 'Edit ,x/foo/c/bar/' > $p/ctl # sam's Edit, one undo step +echo /old/ > $p/addr && printf new > $p/data # replace the next match +t=$(awk '$2=="term"{print $1; exit}' $m/index) # a shell (bash or fish) +exec 3<>$m/pane/$t/pty/run; echo make >&3; cat <&3; exec 3<&- # exit N, then output +exec 3<>$m/log; echo 'follow new' >&3; timeout 30 cat <&3; exec 3<&- +rmdir $p # close it +``` + +The Scripting chapter has the rest: a command pane's output, typing into +a terminal, the language server, a tag word on `PATH` (`Fmt`), and event +helpers that own clicks through `pane/<n>/event`. ## Traps - A refused write says only `Invalid argument` or `Input/output error`; `grep '^err' $m/log | tail -1` says why. Not the log's last line: after - a refused Del, Exit or Restore that may be `+Unsaved`'s `new`. -- Work through a pane of your own (`n=$(cat $m/pane/new)`) and its own - `look` and `exec`: the root's act at the pane with the keyboard, which another - client, an idle shell or an event helper may own. -- `head` on `index`, `layout`, `log` or `recent` through 9ns says `Illegal - seek`: use `sed -n 1p`. In `index`, `term` is a shell, `cmd` a command's - pane. + a refused Del, Exit or Restore that may be `+Unsaved`'s `new`. A write + that succeeds logs nothing. +- The root `look` and `exec` act at the pane with the keyboard, which + another client, an idle shell or an event helper may own: use a pane's. +- Read `look`, `exec` or `pager` on the open you wrote (`exec 3<>…`): a + fresh open reads the session's last answer, from whichever client. +- A command pane your `exec` open was answered is yours while that open + stays open: read its `body` before you close it. - `addr` is the pane's and moves on: each `/re/` searches from the last address, and a `data` write leaves it just past the text. Write `addr` before each replacement; a failed address leaves none. - An Edit `x` that matches nothing succeeds: check the text afterwards. -- Each open of `pane/new` makes a pane: read it once. -- Through a mount, `printf 'a\nb\n' > ctl` arrives one write per line: send - a block as one write (`cat block > $p/ctl`), ending in a newline. +- Through a mount, `printf 'a\nb\n' > ctl` arrives one write per line: + send a block as one write, ending in a newline (a last line without one + runs after the close, its failure only in the log). +- Read `event` on a descriptor your shell owns (`exec 3<>$p/event`), + never `cat $p/event | while read`: the `cat` outlives the loop and + swallows the next click. +- The session has 64 open records shared by every client (held reads, + write opens of command files, snapshots): close what you open. +- `head` on `index`, `layout`, `log` or `recent` through 9ns says `Illegal + seek`: use `sed -n 1p`. - Pane words (`Save`, `Undo`, `Del`) go to `pane/<n>/ctl`, settings and - session words to `$m/ctl`. -- `Exit`, `Restore`, `Del` and `get` refuse once over unsaved text. -- Never experiment on a session someone is using: strip every `PARDES_*` - variable and start your own (Scripting, "An isolated session"); build - with `-Dplatform=tty`, since a bare `zig build` installs over - `~/.local/bin`. + session words to `$m/ctl`. `Exit`, `Restore`, `Del` and `get` refuse once + over unsaved text; the same word again discards. + +## An isolated session + +Never experiment on a session someone is using. Under `9ns --mntgen`: + +```sh +env -i PATH="$PATH" HOME="$(mktemp -d)" XDG_RUNTIME_DIR="$XDG_RUNTIME_DIR" SHELL=/usr/bin/bash pardes --detach=try & +m=$NINE_MOUNT/pardes/try; cat $m/index +echo Exit > $m/exec +``` + +Keep `SHELL` (bash or fish): without it the terminals run `/bin/sh`, +which gets no OSC 133 prompt marks, and `pty/run` answers `error no +prompt marks`. + +To test a change, build with `-Dplatform=tty` (it installs into +`zig-out`): a bare `zig build` installs over `~/.local/bin`. diff --git a/.agents/skills/pardes/SKILL.md b/.agents/skills/pardes/SKILL.md new file mode 100644 index 00000000..d49f8e50 --- /dev/null +++ b/.agents/skills/pardes/SKILL.md @@ -0,0 +1,131 @@ +--- +name: pardes +description: What the pardes editor is and how to use it, with a small cheatsheet (mouse, modes, keys, Look addresses, tags, sessions, config) and a map of its book. Use whenever the user mentions pardes, asks how to do something in it, wants a file opened or text paged in the editor, and to check whether you are running inside a pardes session ($PARDES_PID, $PARDES_9P, $PARDES_PANE, $PARDES_MOUNT) before acting on the user's editor. For scripting or driving a session through its 9P files, use pardes-9p. +--- + +# pardes + +pardes is acme's idea (text is the interface: any word can be looked at or +run) with helix's modal keys, VT terminals and PDFs in panes. Two builtins +carry it: Look (right-click, B3, or Enter in normal mode) opens what the +text names (a file, `file:line`, a directory, a URL), else finds the word's +next place; Exec (middle-click, B2, or Tab) runs the builtin a word names, +else runs it as a shell line. Every session is also a virtual filesystem +served over 9P, so any program that opens files can script it (pardes-9p). + +Paths below are relative to the pardes source tree, the repository this +skill lives in (`readlink -f` this skill's directory if it is reached +through a symlink). + +## Am I in a pardes session? + +Check this first: it decides whether "open it", "show me" or "run it" +can mean the user's editor. Every shell and command pane pardes starts +gets these, and every program started from it (an agent too) inherits them: + +| Variable | | +|---|---| +| `PARDES_PID` | the session's pid (what `status` says) | +| `PARDES_9P` | the session's 9P socket | +| `PARDES_PANE` | the serial of the pane this shell runs in | +| `PARDES_MOUNT` | the session as a directory, only under `9ns --mntgen` or in a `Tty9p` shell | +| `winid` | the pane a command was clicked in (command panes only) | + +A variable can outlive its session (a `--detach` session quit, a shell +moved under tmux), so check that it is live, not just set: + +```sh +if [ -n "${PARDES_9P:-}" ] && [ -S "$PARDES_9P" ] && kill -0 "${PARDES_PID:-}" 2>/dev/null; then + echo "in pardes: session $PARDES_PID, pane $PARDES_PANE, mount ${PARDES_MOUNT:-none}" +else + echo "not in pardes" +fi +``` + +With a mount, `sed -n 1p "$PARDES_MOUNT/status"` answers `pid +$PARDES_PID`. Sessions listed under `$NINE_MOUNT/pardes/` are not proof: +that lists every running session, the user's included, whether or not you +run inside one. Not in a session: say so, and touch no session you merely +found there. + +## Words + +- **tag**: the editable line of words above the workspace, each column and + each pane. A pane's starts with its path. Any word runs from any tag. +- **serial**: a pane's number, never reused (`@p3:12`, `pane/3/`). +- **command pane**: a terminal running one command line; its tag ends in + `running`, then `exit N`. +- **`+` names**: panes pardes makes: `+New` (scratch), `+Search`, `+Pager`, + `+Errors`, `+Unsaved`, `+Diff`. +- **active column**: where the next new pane goes. + +## Cheatsheet + +| Mouse | | +|---|---| +| B1 | select; give the pane the keyboard | +| B2 | Exec the word or sweep | +| B3 | Look at the word or sweep | +| B1+B2 / B1+B3 / B1+B2+B3 | cut / paste / copy (chords) | +| B2+B1 | Exec with the B1 selection as argument | +| Alt-click / Super-click | B2 / B3 for one button | + +| Modes (the box left of a tag) | | +|---|---| +| ` ` normal | helix keys: motions select, edits act on the selection | +| `^` insert | `i a o`…; Esc back to normal | +| `$` raw, terminals | keys go to the program; Ctrl-b toggles raw/normal | +| Esc in normal | back to the previous pane (unlike helix) | + +| Keys pardes adds or changes | | +|---|---| +| `SPC ?` | Help: every builtin, its leader path and keys | +| `:` | to the pane's tag and back | +| `Ctrl-w h/j/k/l` | focus a neighbour | +| `Ctrl-o` / `Ctrl-i` | jump list back / forward | +| `Alt-n` / `Alt-c` | new terminal below / pane to a new column | +| `SPC f s`, `SPC d`, `SPC q` | Save, Del, Exit | +| `SPC f f`, `SPC f g`, `SPC f r` | Find, Grep, Recent | +| `12G`, `n` in a command pane | line 12; next `file:line` error | + +| Look addresses (B3 or Enter) | | +|---|---| +| `file:12`, `file:12:5` | line, byte column | +| `file:/re/`, `file:0/re/` | next match, first match | +| `:40` | line 40 of the pane looked from | +| `@p3:12` | pane 3 by serial | +| `src/` | a directory pane | + +Addresses are sam's (`#n /re/ ?re? $ a,b`). + +| Common words | | +|---|---| +| `Save` `Del` `Get` `Undo` `Edit` | pane; Del/Exit/Restore refuse once over unsaved text, again discards | +| `New` `Tty` `Tty+bash` `Newcol` `Delcol` | panes and columns | +| `Find name` `Grep text` `Recent` | listings in a `+Search` | +| `Kill make` `Repl python` `Filter` `Mode` | terminals and commands | +| `Dump` `Restore` `Config` `DumpConfig` `Theme x` | workspace and settings | + +## From a shell inside pardes + +```sh +pardes notes.txt # open it in this session, return at once +pardes --wait notes.txt # return when its pane closes (EDITOR='pardes --wait') +git log | pardes - # page text into a +Pager +pardes --detach=work & # a session with no screen; --attach=work shows it +``` + +These act on the user's session: do them when asked. Anything more (read +panes, run commands, react to clicks) is the pardes-9p skill. Config is +`~/.config/pardes/init`, a builtin a line; keys are compiled in +(`src/config.zig`). `$NINE_MOUNT/agents`, where present, is cloud9's +read-only view of running coding agents. + +## The book + +`docs/typ/` holds it, one file a chapter, in reading order: `guide.typ` +(day to day), `setup.typ` (9ns, EDITOR, pager, language servers), +`cheatsheet.typ`, `scripting.typ`, `reference.typ` (every 9P file), +`themes.typ`, `building.typ`. `docs/typ/README` says how they build into +the A4 cheatsheet, the book and the website. In the editor: `Help` +(`SPC ?`) and `Tutor` (`SPC h t`). diff --git a/docs/typ/builtins-gui.json b/docs/typ/builtins-gui.json index b42f9c72..83a410dc 100644 --- a/docs/typ/builtins-gui.json +++ b/docs/typ/builtins-gui.json @@ -20,12 +20,15 @@ {"name": "Crt", "leader": "SPC t r", "also": [], "arg": true, "scope": "root", "setting": true, "choices": "on, off, 0-3", "doc": "The bundled CRT post pass over the window, on or off."}, {"name": "CursorBlink", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "on, off", "doc": "The cursor blinks, solid while typing, on or off."}, {"name": "Debug", "leader": "SPC t d", "also": ["topbar"], "arg": true, "scope": "root", "setting": true, "choices": "on, off", "doc": "A small box of frame statistics at the top right, on or off."}, + {"name": "Def", "leader": null, "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Go to the definition of the symbol under the cursor; with an argument (a 2-1 chord's selection), of that symbol, where it is nearest."}, {"name": "Del", "leader": "SPC d", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Close the pane."}, {"name": "DelAbove", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Close the pane, giving its rows to the pane above it."}, {"name": "DelBelow", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Close the pane, giving its rows to the pane below it."}, {"name": "Delcol", "leader": "SPC c d", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Close this column and its panes, refusing once over unsaved text."}, {"name": "Detach", "leader": "SPC s D", "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Detach this pardes from its terminal, leaving the session running."}, {"name": "Diagnostics", "leader": "SPC l d", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "List the file's diagnostics from the language server."}, + {"name": "Diff", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Stack a diff's hunks as a diff viewer shows them, each under its place and the declarations around it, in a +Diff; on a +Diff, show the diff itself as text."}, + {"name": "DiffLook", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "hunks, text", "doc": "A .diff or .patch looked at: hunks, a +Diff stacking its hunks, or text, the file itself; Diff goes from one to the other."}, {"name": "DirLook", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "pane, terminal", "doc": "A directory looked at: pane, a pane listing it as acme's directory window, or terminal, ls in a terminal there."}, {"name": "Down", "leader": "SPC w j", "also": ["C-w j", "C-w down"], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Move the keyboard to the pane below, off a tag onto the pane under it."}, {"name": "Dump", "leader": "SPC s d", "also": ["topbar"], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Write the session's panes and layout to a dump file, for Restore."}, @@ -36,7 +39,7 @@ {"name": "EffectCode", "leader": null, "also": [], "arg": true, "scope": "root", "setting": false, "choices": null, "doc": "Open the source of a panel transition or post shader, by name."}, {"name": "Exec", "leader": null, "also": ["tab", "middle-click"], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Execute its argument as a middle click on it would, a builtin or a shell command."}, {"name": "Exit", "leader": "SPC q", "also": ["topbar"], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Quit the editor, refusing once while a pane holds unsaved text: an Exit with nothing edited since discards it."}, - {"name": "Filter", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Recolour a terminal's program colours to the theme, or show them as sent, flipping between them."}, + {"name": "Filter", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Recolour a terminal's or a +Pager's program colours to the theme, or show them as sent, flipping between them."}, {"name": "Find", "leader": "SPC f f", "also": ["topbar"], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "List the files below this pane's directory whose names hold its argument, in a +Search."}, {"name": "FocusTint", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "on, off", "doc": "The focused pane's and column's tags are tinted, on or off."}, {"name": "Font", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": null, "doc": "The body font, by name or path, and its size."}, @@ -103,6 +106,7 @@ {"name": "Putall", "leader": null, "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "acme's Putall: every pane holding unsaved edits to a file is saved, each as its own Save; one that is refused (changed on disk since, a write that fails) says so and the rest are saved all the same."}, {"name": "Recent", "leader": "SPC f r", "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "List the files opened lately, closed ones too, each a place to open again."}, {"name": "Redo", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Redo the last undone edit."}, + {"name": "Refs", "leader": null, "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "List the references to the symbol under the cursor; with an argument (a 2-1 chord's selection), to that symbol, where it is nearest."}, {"name": "Rename", "leader": "SPC l r", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Rename the symbol under the cursor everywhere, to its argument."}, {"name": "Repl", "leader": null, "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Binds this terminal as a language's REPL, so an exec on that language's files is typed into it instead of run."}, {"name": "Restore", "leader": "SPC s r", "also": [], "arg": true, "scope": "root", "setting": false, "choices": null, "doc": "Replace every pane with those of a dump file, the last one Dump wrote when bare."}, diff --git a/docs/typ/builtins-tty.json b/docs/typ/builtins-tty.json index 53bcf033..35e12875 100644 --- a/docs/typ/builtins-tty.json +++ b/docs/typ/builtins-tty.json @@ -17,12 +17,15 @@ {"name": "Colors", "leader": "SPC t c", "also": [], "arg": true, "scope": "root", "setting": true, "choices": "on, off", "doc": "Syntax colours in text panes, on or off."}, {"name": "Config", "leader": "SPC f c", "also": ["topbar"], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Open the startup file, `init`, in a pane: its pane when it is open, else the file, else a pane of that name for Save to make it and its directory."}, {"name": "Debug", "leader": "SPC t d", "also": ["topbar"], "arg": true, "scope": "root", "setting": true, "choices": "on, off", "doc": "A small box of frame statistics at the top right, on or off."}, + {"name": "Def", "leader": null, "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Go to the definition of the symbol under the cursor; with an argument (a 2-1 chord's selection), of that symbol, where it is nearest."}, {"name": "Del", "leader": "SPC d", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Close the pane."}, {"name": "DelAbove", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Close the pane, giving its rows to the pane above it."}, {"name": "DelBelow", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Close the pane, giving its rows to the pane below it."}, {"name": "Delcol", "leader": "SPC c d", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Close this column and its panes, refusing once over unsaved text."}, {"name": "Detach", "leader": "SPC s D", "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Detach this pardes from its terminal, leaving the session running."}, {"name": "Diagnostics", "leader": "SPC l d", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "List the file's diagnostics from the language server."}, + {"name": "Diff", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Stack a diff's hunks as a diff viewer shows them, each under its place and the declarations around it, in a +Diff; on a +Diff, show the diff itself as text."}, + {"name": "DiffLook", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "hunks, text", "doc": "A .diff or .patch looked at: hunks, a +Diff stacking its hunks, or text, the file itself; Diff goes from one to the other."}, {"name": "DirLook", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "pane, terminal", "doc": "A directory looked at: pane, a pane listing it as acme's directory window, or terminal, ls in a terminal there."}, {"name": "Down", "leader": "SPC w j", "also": ["C-w j", "C-w down"], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Move the keyboard to the pane below, off a tag onto the pane under it."}, {"name": "Dump", "leader": "SPC s d", "also": ["topbar"], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Write the session's panes and layout to a dump file, for Restore."}, @@ -33,7 +36,7 @@ {"name": "EffectCode", "leader": null, "also": [], "arg": true, "scope": "root", "setting": false, "choices": null, "doc": "Open the source of a panel transition or post shader, by name."}, {"name": "Exec", "leader": null, "also": ["tab", "middle-click"], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Execute its argument as a middle click on it would, a builtin or a shell command."}, {"name": "Exit", "leader": "SPC q", "also": ["topbar"], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Quit the editor, refusing once while a pane holds unsaved text: an Exit with nothing edited since discards it."}, - {"name": "Filter", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Recolour a terminal's program colours to the theme, or show them as sent, flipping between them."}, + {"name": "Filter", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Recolour a terminal's or a +Pager's program colours to the theme, or show them as sent, flipping between them."}, {"name": "Find", "leader": "SPC f f", "also": ["topbar"], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "List the files below this pane's directory whose names hold its argument, in a +Search."}, {"name": "FocusTint", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "on, off", "doc": "The focused pane's and column's tags are tinted, on or off."}, {"name": "Forward", "leader": "SPC j i", "also": ["C-i"], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Ctrl-i: one step forward again, up to wherever Back started."}, @@ -90,6 +93,7 @@ {"name": "Putall", "leader": null, "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "acme's Putall: every pane holding unsaved edits to a file is saved, each as its own Save; one that is refused (changed on disk since, a write that fails) says so and the rest are saved all the same."}, {"name": "Recent", "leader": "SPC f r", "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "List the files opened lately, closed ones too, each a place to open again."}, {"name": "Redo", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Redo the last undone edit."}, + {"name": "Refs", "leader": null, "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "List the references to the symbol under the cursor; with an argument (a 2-1 chord's selection), to that symbol, where it is nearest."}, {"name": "Rename", "leader": "SPC l r", "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Rename the symbol under the cursor everywhere, to its argument."}, {"name": "Repl", "leader": null, "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Binds this terminal as a language's REPL, so an exec on that language's files is typed into it instead of run."}, {"name": "Restore", "leader": "SPC s r", "also": [], "arg": true, "scope": "root", "setting": false, "choices": null, "doc": "Replace every pane with those of a dump file, the last one Dump wrote when bare."}, diff --git a/docs/typ/guide.typ b/docs/typ/guide.typ index 90e72303..89323766 100644 --- a/docs/typ/guide.typ +++ b/docs/typ/guide.typ @@ -202,8 +202,8 @@ takes the rows: #key("k") above, #key("j") below. = Reviewing diffs <reviewing-diffs> -`git diff` run as a command, or a `.diff` or `.patch` opened, is drawn as -a diff, each hunk in its file's language. #btn("B3") on: +`git diff` run as a command, or a `.diff` or `.patch` shown as text (below), +is drawn as a diff, each hunk in its file's language. #btn("B3") on: #pairs( [`diff --git`, `---`, `+++`], [the file], @@ -211,6 +211,17 @@ a diff, each hunk in its file's language. #btn("B3") on: [a line's `+`, `-` or space], [that line in the new file], ) +A `.diff` or `.patch` looked at, and a diff paged (`git show`), opens as +a `+Diff`, stacked as delta shows one: each hunk under its `path:line` +(`n`/`N` step through them, #btn("B3") opens it) and the declarations +around it, a `+`/`-` before each line, the words a changed line changed +tinted and a line added or removed whole faintly. A mailed patch keeps its +message and diffstat above. The files are found from the diff's directory +or one above it. #word("Diff") on a `+Diff` shows the diff itself as +text (a paged one's `+Pager` is folded under it), and on the text stacks +it again; #word("DiffLook") `text` in the startup file opens the text +first. + = `pardes FILE` and `--wait` <editor> In a pane's shell: diff --git a/docs/typ/reference.typ b/docs/typ/reference.typ index ed88905a..909c1e1a 100644 --- a/docs/typ/reference.typ +++ b/docs/typ/reference.typ @@ -22,7 +22,7 @@ index a line per pane: serial kind dirty name column @ru status pid, version, panes @other-files look write a line: a #word("Look") at the pane with the keyboard; read: the serials touched @look-and-exec exec write a line: an #word("Exec") there; read: the serials touched @look-and-exec -pager write a directory: its one +Pager, made or emptied; read: its serial @pardes-stdin +pager write a directory: a new +Pager there; read: its serial @pardes-stdin log the event log; write follow to wait for more @log screen the rendered screen as JSON @on-screen listeners dial addresses @other-files @@ -252,7 +252,9 @@ A line written to #file("exec") is #word("Exec"): silently, here and in every ctl. - The language server's words ask about a file pane's text at its cursor (set it with #file("addr") and `dot=addr` first): #word("Hover") fills - `+Hover`; #word("Rename") `new` renames the symbol in the file and says how many + `+Hover`; #word("Def") and #word("Refs"), in the tag of a file a server + speaks for, are `gd` and `gr`, and given a symbol (a 2-1 chord's + selection) ask at its occurrence nearest the cursor; #word("Rename") `new` renames the symbol in the file and says how many ranges it changed (on the message row, and so in the log) without listing them, and fails when there is nothing to rename. One that reaches other files applies nothing: it opens a `+Search` preview of the edits, which @@ -457,7 +459,7 @@ may lower the contrast of text, the selection or a focus indicator. build embeds them. Resting the pointer on text for about 32 ms (`look_preview_delay_frames`, -2 frames, in `src/config.zig`; `null` turns it off) tints what #word("Look") would take, with no other effect. A terminal's +2 frames, in `src/config.zig`; `null` turns it off) tints what #word("Look") would take, with no other effect. A terminal's or a `+Pager`'s #word("Filter") keeps each foreground at least `tty_filter_min_contrast` (WCAG 1.5, `src/config.zig`) against its background. @@ -889,10 +891,10 @@ at 200, ending in `…`. Control characters become spaces. line is the session's; one not there is refused ENOENT, a relative one EINVAL, one you may not write `permission denied`, a regular file `not a directory`, ENOTDIR), one line; what follows that line, on the same open, is the text to - page, escapes and all. A read of that open answers the serial of the - directory's one `+Pager`, made or emptied for it, once the text is in. This is what - `pardes -` uses; from a directory you may not write, it pages into the - session's `+Pager`. + page, escapes and all. A read of that open answers the serial of a new + `+Pager` in the directory, once the text is in. This is what + `pardes -` uses; from a directory you may not write, it pages into a + `+Pager` of the session's. - #file("/listeners"): the session's dial addresses, a line each (#doc("building", section: "listeners")). - #file("/os/"): existing regular files take read, write and truncation to @@ -993,12 +995,13 @@ it was. = pardes - <pardes-stdin> -`pardes -` reads stdin to its end and shows it in the directory's one -`+Pager` pane, made or emptied for it and left clean, opening at its top; -the next paged text refills it. The session parses the text with +`pardes -` reads stdin to its end and shows it in a new `+Pager` pane of +the directory, left clean, opening at its top, with no line numbers; a +`+Pager` already there keeps its page. The session parses the text with ghostty-vt: SGR colours become the `+Pager`'s own display, never part of -its body or any read (#word("PagerColor") `off` pages plain), and every other -escape is dropped; a carriage return keeps a progress line's last state, +its body or any read (#word("PagerColor") `off` pages plain), mapped +through the theme as a terminal's are until its #word("Filter") shows them +as sent; every other escape is dropped; a carriage return keeps a progress line's last state, and CRLF becomes LF. Empty stdin shows nothing. Inside a pardes pane it returns at once; a text the session cannot take is printed to stderr with why, and the exit is 1. From a directory whose name holds a newline or control byte, the pane is the session diff --git a/docs/typ/setup.typ b/docs/typ/setup.typ index df99a45f..f49c9075 100644 --- a/docs/typ/setup.typ +++ b/docs/typ/setup.typ @@ -59,7 +59,7 @@ fi = A pager <pager> -#cmd("ls --color=always | pardes - # into the directory's +Pager, colours kept") +#cmd("ls --color=always | pardes - # into a new +Pager there, colours kept") With #word("Pager") `pardes` (the default) a terminal's shell gets `PAGER`, `GIT_PAGER` and `SYSTEMD_PAGER` set to it (and diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md index 6be39c7a..ce2cedc8 100644 --- a/src/CHANGELOG.md +++ b/src/CHANGELOG.md @@ -2,6 +2,12 @@ ## 0.23 +- A file a language server speaks for (by its extension) has `Def` and + `Refs` in its tag: the definition and the references of the symbol at + the cursor, which `gd`, `gr` and a Ctrl-click run too. Chorded 2-1, they + ask at the selected symbol instead, its occurrence nearest the cursor. +- A scroll in the window never moves the tree-sitter context rows: the + body glides under them. - A look at a directory opens a pane listing it, as acme's directory window does: its entries in columns, a directory's marked `/`. A look at an entry opens it from there, and `Get` or a look at it again reads it diff --git a/src/File.zig b/src/File.zig index 875d0f46..31392ebd 100644 --- a/src/File.zig +++ b/src/File.zig @@ -154,8 +154,11 @@ pub const State = struct { /// Its file was deleted on disk: said once (`deleted`) until it is /// written or found again. disk_gone: bool = false, - /// A +Pager pane (`pardes -`) whose text is a diff (`git diff`, `show`, - /// `log -p`): drawn and looked at as a diff (Pane.colorAlgo). + /// A +Pager pane (`pardes -`): no line numbers, its program's colours + /// through Filter until it is toggled off. + pager: bool = false, + /// A +Pager whose text is a diff (`git diff`, `show`, `log -p`): drawn + /// and looked at as a diff (Pane.colorAlgo). pager_diff: bool = false, /// A +Pager's colours, as its program printed them (pager.zig): drawn /// over its text by recolorSyntax, never read over 9P. ponytail: any @@ -562,6 +565,10 @@ pub fn byteAtRowDisplay(pane: *const Pane, row: i32, from_raw: i32, display_col: pub fn gutterWidth(pane: *const Pane) u16 { if (pane.file == null) return 0; const file = &pane.file.?; + // A +Pager, and a +Diff (hunks.zig), show no line numbers, as a + // pager and delta show none. + if (file.pager) return 0; + if (file.output) |o| if (std.meta.eql(o.from, Output.Origin{ .cmd = .Diff })) return 0; var lines = if (file.line_starts.len > 0) file.line_starts.len else lineCount(file.content); var digits: u16 = 1; while (lines >= 10) : (lines /= 10) digits += 1; @@ -1164,7 +1171,7 @@ pub fn setContentSpan(p: *Pardes, f: *State, new: []u8, span_in: ?Span) void { f.highlights = &.{}; f.highlight_start = 0; f.syntax_dirty = true; - if (std.mem.endsWith(u8, f.path, "/+Pager")) f.pager_diff = looksLikeDiff(new[0..@min(new.len, 64 * 1024)]); + if (f.pager) f.pager_diff = looksLikeDiff(new[0..@min(new.len, 64 * 1024)]); for (twins[0..ntwins], 0..) |id, i| { const t = p.panes[id].?; const tf = &t.file.?; @@ -1434,6 +1441,7 @@ test "a +Pager pane holding a diff is drawn and looked at as one; holding other const f = &pane.file.?; p.gpa.free(f.path); f.path = try p.gpa.dupe(u8, "/tmp/+Pager"); + f.pager = true; setContent(p, f, try p.gpa.dupe(u8, "commit abc\n\ndiff --git a/x b/x\n--- a/x\n+++ b/x\n@@ -1 +1 @@\n-a\n+b\n")); try std.testing.expect(pane.colorAlgo() == .diff); try std.testing.expect(pardes.look.diffLines(p, pane) != null); @@ -1715,7 +1723,7 @@ fn fillBody(dst: ?[]u8, pane: *Pane, f: *State, width: usize, record_wrap: bool) var lbuf: [@max(config.PREFIX_W, 32)]u8 = undefined; const prefix = lbuf[0..prefix_width]; @memset(prefix, ' '); - if (at == 0) { + if (at == 0 and prefix.len > 0) { var lineno = row + 1; var digit: usize = prefix.len - 1; while (true) { @@ -1790,6 +1798,12 @@ const SynStyle = struct { fg: [3]u8, bold: bool }; pub const DiffTints = struct { added_bg: [3]u8, removed_bg: [3]u8, + /// The words a changed line changed (hunks.zig), on a stronger ground. + added_emph_bg: [3]u8, + removed_emph_bg: [3]u8, + /// A +Diff line added or removed whole: a faint ground. + added_line_bg: [3]u8, + removed_line_bg: [3]u8, added_fg: [3]u8, removed_fg: [3]u8, @@ -1804,6 +1818,10 @@ pub const DiffTints = struct { return .{ .added_bg = added_bg, .removed_bg = removed_bg, + .added_emph_bg = Colors.mixOklab(page, green, 0.28), + .removed_emph_bg = Colors.mixOklab(page, red, 0.28), + .added_line_bg = Colors.mixOklab(page, green, 0.07), + .removed_line_bg = Colors.mixOklab(page, red, 0.07), .added_fg = legible(green, ink, added_bg), .removed_fg = legible(red, ink, removed_bg), }; @@ -1818,9 +1836,9 @@ pub const DiffTints = struct { /// The row ground and prefix ink for a line's style byte, if it is an /// added or removed line. - pub fn forStyle(t: *const DiffTints, style: u8) ?struct { bg: [3]u8, fg: [3]u8 } { - if (style & syntax.diff_added != 0) return .{ .bg = t.added_bg, .fg = t.added_fg }; - if (style & syntax.diff_removed != 0) return .{ .bg = t.removed_bg, .fg = t.removed_fg }; + pub fn forStyle(t: *const DiffTints, style: u8) ?struct { bg: [3]u8, fg: [3]u8, emph_bg: [3]u8, line_bg: [3]u8 } { + if (style & syntax.diff_added != 0) return .{ .bg = t.added_bg, .fg = t.added_fg, .emph_bg = t.added_emph_bg, .line_bg = t.added_line_bg }; + if (style & syntax.diff_removed != 0) return .{ .bg = t.removed_bg, .fg = t.removed_fg, .emph_bg = t.removed_emph_bg, .line_bg = t.removed_line_bg }; return null; } }; @@ -1855,7 +1873,17 @@ pub fn recolorSyntax(p: *Pardes, s: *Surface, pane: *Pane, f: *State, r: pardes. const prefix_width = gutterWidth(pane); const tz_recolor = tracy.zone(@src(), "synRecolor"); defer tz_recolor.end(); - const tints: ?DiffTints = if (pane.colorAlgo() == .diff and highlights.len > 0) DiffTints.of(p) else null; + // A diff's rows, and a +Diff's (hunks.zig): their markers coloured. + // A diff's whole row is tinted; a +Diff tints only the words a + // changed line changed. + const algo = pane.colorAlgo(); + const tints: ?DiffTints = if ((algo == .diff or algo == .locations) and highlights.len > 0) DiffTints.of(p) else null; + const row_tint = algo == .diff; + var filtered_storage: terminal.FilteredColors = undefined; + const filtered: ?*terminal.FilteredColors = if (comptime terminal.enabled) (if (pane.tty_filter and spans.len > 0) blk: { + filtered_storage = .init(p, null); + break :blk &filtered_storage; + } else null) else null; // indexed start, same as bodyText — an empty tail simply paints nothing var flines = std.mem.splitScalar(u8, f.content[lineStart(p.gpa, f, f.scroll)..], '\n'); const total = nlines(p.gpa, f); @@ -1893,7 +1921,11 @@ pub fn recolorSyntax(p: *Pardes, s: *Surface, pane: *Pane, f: *State, r: pardes. t.forStyle(highlights[base - highlight_start]) else null else null; - if (tint) |t| if (prefix_width < tw) tintRow(s, tx + @as(u16, @intCast(prefix_width)), body_y + vr, tx + tw, t.bg); + if (tint) |t| if (prefix_width < tw) { + // A +Diff line added or removed whole: faintly (hunks.zig). + const whole = highlights[base - highlight_start] & syntax.diff_whole != 0; + if (row_tint or whole) tintRow(s, tx + @as(u16, @intCast(prefix_width)), body_y + vr, tx + tw, if (row_tint) t.bg else t.line_bg); + }; // A +Pager's own colours (pager.zig) on every row but one the diff // look tints: an added or removed line is drawn as pardes draws a // diff, and git's red and green on it would only fight the tint. @@ -1924,6 +1956,11 @@ pub fn recolorSyntax(p: *Pardes, s: *Surface, pane: *Pane, f: *State, r: pardes. cell.style.bold = ss.bold; } } + if (tint) |t| if (highlights[hidx] & syntax.diff_emph != 0) { + var fill: usize = 0; + while (fill < cells and prefix_width + screen_c + fill < tw) : (fill += 1) + s.at(tx + @as(u16, @intCast(prefix_width + screen_c + fill)), body_y + vr).style.bg = .{ .rgb = t.emph_bg }; + }; } } // Results keep their exact live text. Only the location, @@ -1945,10 +1982,16 @@ pub fn recolorSyntax(p: *Pardes, s: *Surface, pane: *Pane, f: *State, r: pardes. while (fill < cells and prefix_width + screen_c + fill < tw) : (fill += 1) { const cell = s.at(tx + @as(u16, @intCast(prefix_width + screen_c + fill)), body_y + vr); if (cell.default) continue; - // A palette colour through the theme's sixteen, as a - // terminal pane's cell; truecolor as it is. - if (st.fg != .default) cell.style.fg = if (st.fg == .index) terminal.palColor(p, st.fg.index) else st.fg; - if (st.bg != .default) cell.style.bg = if (st.bg == .index) terminal.palColor(p, st.bg.index) else st.bg; + // As a terminal pane's cell: through Filter, or a + // palette colour through the theme's sixteen and + // truecolor as it is. + if (filtered) |colors| { + if (st.fg != .default) cell.style.fg = colors.spanColor(st.fg, false); + if (st.bg != .default) cell.style.bg = colors.spanColor(st.bg, true); + } else { + if (st.fg != .default) cell.style.fg = if (st.fg == .index) terminal.palColor(p, st.fg.index) else st.fg; + if (st.bg != .default) cell.style.bg = if (st.bg == .index) terminal.palColor(p, st.bg.index) else st.bg; + } cell.style.bold = cell.style.bold or st.bold; cell.style.dim = st.dim; cell.style.italic = st.italic; diff --git a/src/Output.zig b/src/Output.zig index 3bae9ecf..9e194615 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -15,6 +15,8 @@ const build_options = @import("pardes_config"); const lsp = @import("lsp/lsp.zig"); const look = @import("look.zig"); const locations = @import("locations.zig"); +const layout = @import("layout.zig"); +const hunks = @import("hunks.zig"); const Pane = panes.Pane; const File = panes.File; @@ -538,6 +540,17 @@ pub fn fillResults(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: [] result_rows = formatted.rows; anchor = formatted.anchor; } + _ = try fillRows(p, id, dir, from, arg, result_content, result_rows, anchor); +} + +/// Rows already laid out (`content`, `rows` its metadata, both taken +/// when it succeeds, the caller's still when it fails) into the pane they +/// belong in: the one a run of `from` with `arg` in `dir` showed last, +/// refilled, else a new one placed by pane `id`. Its id. +pub fn fillRows(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: []const u8, result_content: []u8, result_rows: []locations.Row, anchor: ?usize) !usize { + const pane = p.panes[id] orelse return error.MissingPane; + if (arg.len > max_arg) return error.ArgumentTooLong; + const by_arg = std.meta.activeTag(from) != .query; for (p.panes, 0..) |slot, i| { const rp = slot orelse continue; const rf = if (rp.file) |*f| f else continue; @@ -578,7 +591,7 @@ pub fn fillResults(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: [] pane.search_row = anchor; look.armLookWalk(p, i); } - return; + return i; } const free = p.freeSlot() orelse return error.NoPaneSlots; const np = try open(p, free, dir, from, arg, result_content); @@ -590,6 +603,57 @@ pub fn fillResults(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: [] pane.search_row = anchor; look.armLookWalk(p, free); } + return free; +} + +/// Diff: `content`, the diff at `path` (a file, a +Pager), stacked as a +/// diff viewer shows it (hunks.zig), in a +Diff where its files are found +/// (hunks.sourceRoot), placed by pane `id`, refilled when it is there. Its +/// arg names the diff (its base name, or its whole path when the +Diff +/// stands elsewhere), for Diff to go back to it. The +Diff's id; +/// NoHunks when there is none in it. +pub fn openDiff(p: *Pardes, id: usize, path: []const u8, content: []const u8) !usize { + const dir = std.fs.path.dirname(path) orelse p.sessionDir(); + const root = hunks.sourceRoot(p, dir, content); + const result = try hunks.format(p, root, content); + errdefer { + p.gpa.free(result.content); + locations.freeRows(p.gpa, result.rows); + } + var has_hunk = false; + for (result.rows) |row| has_hunk = has_hunk or row.kind == .match; + if (!has_hunk) return error.NoHunks; + const arg = if (std.mem.eql(u8, root, dir) or path.len > max_arg) std.fs.path.basename(path) else path; + return fillRows(p, id, root, .{ .cmd = .Diff }, arg, result.content, result.rows, null); +} + +/// Diff on a +Diff: the diff it stacks, as text. A pane holding it +/// already (the newest: a +Pager folded under its +Diff unfolds) is +/// shown; else the file is opened as text, whatever DiffLook says. +pub fn showDiffText(p: *Pardes, id: usize, source: []const u8) void { + var newest: ?usize = null; + for (p.panes, 0..) |slot, i| { + const f = (slot orelse continue).file orelse continue; + if (!std.mem.eql(u8, f.path, source)) continue; + if (newest == null or p.panes[newest.?].?.serial < slot.?.serial) newest = i; + } + if (newest) |i| { + if (p.panes[i].?.collapsed) layout.toggleCollapse(p, i); + p.active = i; + return; + } + p.look_text = true; + defer p.look_text = false; + look.lookAt(p, id, source); +} + +/// The diff a +Diff stacks (openDiff's arg): its path. +pub fn diffSource(p: *Pardes, f: *const File.State) ?[]const u8 { + const o = f.output orelse return null; + if (!std.meta.eql(o.from, Origin{ .cmd = .Diff })) return null; + const arg = o.arg(); + if (arg.len > 0 and arg[0] == '/') return arg; + return std.fs.path.join(p.scratch.allocator(), &.{ std.fs.path.dirname(f.path) orelse "", arg }) catch null; } pub fn openJumps(p: *Pardes, id: usize) !void { @@ -685,25 +749,15 @@ pub fn openUnsaved(p: *Pardes, id: usize, content: []u8) void { p.active = id; } -/// `pardes -`'s pane: the one `<dir>/+Pager`, emptied for the next paged -/// text when it is there (a directory's paged commands refill it, as its -/// command pane is reused), else made, named so before it is announced, -/// and placed wherever there is room without taking the keyboard. `dir` -/// empty (or not absolute): the session's directory. Its id; NoPaneRoom -/// or NoPaneSlots when it has no room at all. +/// `pardes -`'s pane: a new `<dir>/+Pager` for each paged text, as each +/// run of a pager is its own (one already there keeps its page), named so +/// before it is announced, its colours through Filter, and placed wherever +/// there is room without taking the keyboard. `dir` empty (or not +/// absolute): the session's directory. Its id; NoPaneRoom or NoPaneSlots +/// when it has no room at all. pub fn openPager(p: *Pardes, from: usize, dir_arg: []const u8) !usize { const dir = if (dir_arg.len > 0 and dir_arg[0] == '/') dir_arg else p.sessionDir(); const path = try std.fs.path.join(p.gpa, &.{ dir, "+Pager" }); - for (p.panes, 0..) |slot, i| { - const pane = slot orelse continue; - const f = if (pane.file) |*file| file else continue; - if (!std.mem.eql(u8, f.path, path)) continue; - p.gpa.free(path); - File.setContent(p, f, try p.gpa.alloc(u8, 0)); - resetBody(p, pane); - f.saved_revision = f.revision; - return i; - } const free = p.freeSlot() orelse { p.gpa.free(path); return error.NoPaneSlots; @@ -719,6 +773,8 @@ pub fn openPager(p: *Pardes, from: usize, dir_arg: []const u8) !usize { // The pane owns the name from here. p.gpa.free(pane.file.?.path); pane.file.?.path = path; + pane.file.?.pager = true; + pane.tty_filter = true; const keyboard = p.active; exec.placeNew(p, from, null, free, .fs); if (p.unplaced.isSet(free)) return error.NoPaneRoom; diff --git a/src/builtins.zig b/src/builtins.zig index 77e1169d..c1424b2f 100644 --- a/src/builtins.zig +++ b/src/builtins.zig @@ -46,6 +46,10 @@ pub const PaneKind = enum { /// An image pane, or a terminal, whose program's kitty graphics are /// pictures too. picture, + /// A terminal, or a +Pager: a program's colours. + program_colors, + /// A text pane showing a diff: a .diff, a .patch, a +Pager holding one. + diff, pub fn has(kind: PaneKind, pane: *const panes.Pane) bool { return switch (kind) { @@ -53,6 +57,9 @@ pub const PaneKind = enum { .pdf => pane.hasPdf(), .image => pane.image != null, .picture => pane.image != null or pane.isTerminal(), + .program_colors => pane.isTerminal() or (pane.file != null and pane.file.?.pager), + .diff => if (pane.file) |f| pane.colorAlgo() == .diff or + (f.output != null and std.meta.eql(f.output.?.from, panes.Output.Origin{ .cmd = .Diff })) else false, }; } @@ -62,6 +69,8 @@ pub const PaneKind = enum { .pdf => "a PDF", .image => "an image", .picture => "an image or a terminal", + .program_colors => "a terminal or a +Pager", + .diff => "a diff or a +Diff", }; } }; @@ -1336,14 +1345,28 @@ pub const Del = struct { } }; -/// Recolour a terminal's program colours to the theme, or show them as sent, flipping between them. +/// Recolour a terminal's or a +Pager's program colours to the theme, or show them as sent, flipping between them. pub const Filter = struct { - pub const needs: PaneKind = .terminal; + pub const needs: PaneKind = .program_colors; pub fn run(c: Ctx) void { c.pane.tty_filter = !c.pane.tty_filter; } }; +/// Stack a diff's hunks as a diff viewer shows them, each under its place and the declarations around it, in a +Diff; on a +Diff, show the diff itself as text. +pub const Diff = struct { + pub const needs: PaneKind = .diff; + pub const output: OutputTraits = .{ .name = config.diff_buffer, .steps = true, .locations = true }; + pub fn run(c: Ctx) void { + const f = &c.pane.file.?; + if (panes.Output.diffSource(c.p, f)) |source| return panes.Output.showDiffText(c.p, c.id, source); + _ = panes.Output.openDiff(c.p, c.id, f.path, f.content) catch |err| switch (err) { + error.NoHunks => c.p.reportFailure(c.id, "Diff: no hunk in it"), + else => c.p.reportError(c.id, "hunks", err), + }; + } +}; + /// Cycle the pane's input modes: terminals add raw tty mode to normal/insert. pub const Mode = struct { pub fn run(c: Ctx) void { @@ -1851,6 +1874,28 @@ pub const Jumplist = struct { // ---- the language group ---- +/// Go to the definition of the symbol under the cursor; with an argument +/// (a 2-1 chord's selection), of that symbol, where it is nearest. +pub const Def = struct { + pub const takes_arg = true; + /// Its answer says what it found, a jump or a list or why not; its + /// name would only stack above it, as gd never did. + pub const quiet = true; + pub fn run(c: Ctx) void { + c.p.lspRequest(c.id, .definition, std.mem.trim(u8, c.arg orelse "", " \t\r\n")); + } +}; + +/// List the references to the symbol under the cursor; with an argument +/// (a 2-1 chord's selection), to that symbol, where it is nearest. +pub const Refs = struct { + pub const takes_arg = true; + pub const quiet = true; // as Def + pub fn run(c: Ctx) void { + c.p.lspRequest(c.id, .references, std.mem.trim(u8, c.arg orelse "", " \t\r\n")); + } +}; + /// Ask the language server about the symbol under the cursor. pub const Hover = struct { pub fn run(c: Ctx) void { diff --git a/src/config.zig b/src/config.zig index d6ea7358..c2f51b36 100644 --- a/src/config.zig +++ b/src/config.zig @@ -32,6 +32,8 @@ pub const leader_path = paths: { var table = std.EnumArray(Builtin, ?[]const u8).initDefault(@as(?[]const u8, undecided), .{ .Help = &[_]u8{leader_help}, .Hover = "lk", + .Def = null, // gd + .Refs = null, // gr .Rename = "lr", .CodeAction = "la", .SelectRefs = "lh", @@ -49,6 +51,7 @@ pub const leader_path = paths: { .DelAbove = null, .DelBelow = null, .Filter = null, + .Diff = null, .Mode = null, .Togglettymode = null, .Collapse = null, @@ -87,6 +90,7 @@ pub const leader_path = paths: { .BootShell = null, .LookWord = null, .DirLook = null, + .DiffLook = null, .Pager = null, .PagerColor = null, .TermImages = null, @@ -301,6 +305,16 @@ pub const topbar_str = "Newcol Joincol Find Grep Help Changelog Tutor Dump Theme pub const pane_builtins_str = "Tty Collapse Del"; pub const pdf_pane_builtins_str = "Tty PdfSections PdfTint Collapse Del"; pub const file_pane_builtins_str = "Save Tty Collapse Del"; +/// After a file's, on one a language server speaks for. +pub const lsp_pane_builtins_str = "Def Refs"; +/// A diff's (a .diff, a .patch, a +Pager holding one): Diff. +pub const diff_pane_builtins_str = "Save Tty Diff Collapse Del"; +/// A +Pager's (`pardes -`): Filter, as a terminal's. +pub const pager_pane_builtins_str = "Save Tty Filter Collapse Del"; +/// A +Pager holding a diff (`git show`): Diff too. +pub const pager_diff_pane_builtins_str = "Save Tty Filter Diff Collapse Del"; +/// A +Diff's: Diff again, the diff it stacks as text. +pub const diff_view_builtins_str = "Save Tty Diff Collapse Del"; pub const terminal_pane_builtins_str = "Tty Save Mode Filter Collapse Del"; pub const command_pane_builtins_str = "Kill Save Collapse Del"; /// A directory pane's (Dir.zig): Get reads it again, as acme's does. @@ -500,6 +514,7 @@ pub const unsaved_buffer = "+Unsaved"; pub const themes_buffer = "+Themes"; pub const fonts_buffer = "+Fonts"; pub const pdf_sections_buffer = "+PdfSections"; +pub const diff_buffer = "+Diff"; pub const pdf_links_buffer = "+Links"; pub const hover_buffer = "+Hover"; pub const lsp_buffer = "+Lsp"; @@ -794,6 +809,10 @@ pub const Runtime = struct { /// A directory looked at: `pane`, acme's, a pane listing it (Dir.zig); /// `terminal`, what pardes did before, `ls` in a terminal there. dir_look: DirLook = .pane, + /// A .diff or .patch looked at (a look, `pardes FILE`, `--wait`): + /// `hunks`, a +Diff stacking its hunks (hunks.zig); `text`, the file + /// itself, as pardes showed it before. Diff goes from one to the other. + diff_look: DiffLook = .hunks, /// What a terminal's shell pages through (host_io.ChildEnv): `pardes`, /// PAGER and GIT_PAGER set to `pardes -`, a +Pager pane, where the /// user's environment set neither; `off`, the environment as it is. @@ -818,11 +837,12 @@ pub const Runtime = struct { pub const BootShell = enum { keep, replace }; pub const LookWord = enum { search, list }; pub const DirLook = enum { pane, terminal }; + pub const DiffLook = enum { hunks, text }; pub const Pager = enum { pardes, off }; pub const TermImages = enum { real, petscii }; pub const JumpScope = enum { file, all }; /// A setting that is one of a few words, each an enum field of Runtime. - pub const Choice = enum { placement, boot_shell, look_word, dir_look, pager, term_images, jump_scope }; + pub const Choice = enum { placement, boot_shell, look_word, dir_look, diff_look, pager, term_images, jump_scope }; /// shadow: a soft drop shadow. rim: a light hairline along the top of /// the focused pane's tag rows. auto: a shadow on a light page; on a @@ -1088,6 +1108,7 @@ pub const Runtime = struct { .{ .word = "Placement", .action = .{ .choice = .placement }, .doc = "Where a new pane goes: acme, as makenewwindow does, or pardes, the older rules." }, .{ .word = "BootShell", .action = .{ .choice = .boot_shell }, .doc = "A document dropped where a lone untouched shell stands: keep the shell, or replace it." }, .{ .word = "LookWord", .action = .{ .choice = .look_word }, .doc = "A plain word looked at: search selects its next place in the pane, list lists every place in a +Search." }, + .{ .word = "DiffLook", .action = .{ .choice = .diff_look }, .doc = "A .diff or .patch looked at: hunks, a +Diff stacking its hunks, or text, the file itself; Diff goes from one to the other." }, .{ .word = "DirLook", .action = .{ .choice = .dir_look }, .doc = "A directory looked at: pane, a pane listing it as acme's directory window, or terminal, ls in a terminal there." }, .{ .word = "Pager", .action = .{ .choice = .pager }, .doc = "What a terminal's commands page through: pardes, a +Pager pane (pardes -), or off, the environment's own; for terminals started after it." }, .{ .word = "PagerColor", .action = .{ .toggle = .pager_color }, .doc = "A +Pager keeps its program's colours, on or off; for the next text paged." }, @@ -1787,6 +1808,7 @@ pub const Runtime = struct { .boot_shell => "replace", .look_word => "list", .dir_look => "terminal", + .diff_look => "text", .pager => "off", .term_images => "petscii", .jump_scope => "all", @@ -1862,6 +1884,7 @@ pub const Runtime = struct { .boot_shell => "BootShell replace\n", .look_word => "LookWord list\n", .dir_look => "DirLook terminal\n", + .diff_look => "DiffLook text\n", .pager => "Pager off\n", .term_images => "TermImages petscii\n", .jump_scope => "JumpScope all\n", @@ -2235,7 +2258,7 @@ const doc_typ = struct { if (w.end > 0) w.writeByte(' ') catch return false; w.writeAll(x[0 .. std.mem.indexOfScalar(u8, x, '+') orelse x.len]) catch return false; } - const tags = [_][]const u8{ topbar_str, @import("tagline.zig").column_tag_default, pane_builtins_str, pdf_pane_builtins_str, file_pane_builtins_str, terminal_pane_builtins_str, command_pane_builtins_str, dir_pane_builtins_str }; + const tags = [_][]const u8{ topbar_str, @import("tagline.zig").column_tag_default, pane_builtins_str, pdf_pane_builtins_str, file_pane_builtins_str, diff_pane_builtins_str, pager_pane_builtins_str, pager_diff_pane_builtins_str, diff_view_builtins_str, terminal_pane_builtins_str, command_pane_builtins_str, dir_pane_builtins_str }; for (tags) |d| if (std.mem.eql(u8, d, w.buffered())) return true; return false; } diff --git a/src/edit_cmd.zig b/src/edit_cmd.zig index ebeae223..d3377e09 100644 --- a/src/edit_cmd.zig +++ b/src/edit_cmd.zig @@ -97,7 +97,9 @@ const World = struct { // A look opens it, or finds it open, where a look would; the // keyboard stays where the Edit ran. const was = p.active; + p.look_text = true; look.lookAt(p, w.from, path); + p.look_text = false; if (p.panes[was] != null) p.active = was; for (p.panes, 0..) |slot, id| { const pane = slot orelse continue; diff --git a/src/gui/gui.zig b/src/gui/gui.zig index 65b3f926..5a026664 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -1873,6 +1873,7 @@ const Gui = struct { scroll_rect: pardes.Rect = .{ .x = 0, .y = 0, .w = 0, .h = 0 }, scroll_body_y: u16 = 0, // that rect's first BODY row (Tagbottom moves it) scroll_body_h: u16 = 0, // and its BODY rows, which a taller tag leaves fewer of + scroll_held_px: f32 = 0, // its tree-sitter context band, which never moves scroll_col: u16 = 0, // where the wheel turned: crossed rows are delivered scroll_row: u16 = 0, // THERE, not wherever the pointer has drifted to since scroll_delta: f32 = 0, // finite raw distance waiting for the render batch @@ -5367,7 +5368,7 @@ fn stepGlide(g: *Gui, core: *pardes.Pardes, gpa: std.mem.Allocator) void { /// The glide's picture: the pane's body rows moved by the offset, and in /// the gap it opens the rows that left, as `emitScrollRows` draws a /// touchpad's fraction. -fn emitGlideRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *pardes.Surface, layout: CellLayout, win_w: f32, win_h: f32, page: Ground) u32 { +fn emitGlideRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *pardes.Surface, layout: CellLayout, win_w: f32, win_h: f32, page: Ground, held: u16) u32 { const glide = &g.glide; for (surface.panelTracks()) |track| if (track.active() and track.pane == glide.pane) return 0; @@ -5383,10 +5384,12 @@ fn emitGlideRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *parde g.scroll_body_h = bh; var shifted = layout; shifted.y_off -= glide.offset * layout.h; + const kept = holdContext(g, surface, glide.pane, held, bh, layout); + shifted.y_off += kept.lift; const cursor_idx: u32 = if (surface.cursor) |cu| @as(u32, cu.y) * surface.cols + cu.x else std.math.maxInt(u32); const cursor_bar = if (surface.cursor) |cu| cu.bar else false; var n: u32 = 0; - var row = y0; + var row = y0 + kept.rows; while (row < y0 + bh) : (row += 1) { const line = surface.cells[@as(usize, row) * surface.cols ..][0..surface.cols]; const row_cursor: ?usize = if (surface.cursor) |cu| if (cu.y == row) cu.x else null else null; @@ -5400,9 +5403,9 @@ fn emitGlideRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *parde // The gap: rows past the top while the picture lags a move down, past // the bottom for one up; as many as it opens. const gap: u16 = @intFromFloat(@min(@ceil(@abs(glide.offset)), @as(f32, @floatFromInt(bh)))); - const kept = if (glide.offset < 0) glide.nabove else glide.nbelow; + const nkept = if (glide.offset < 0) glide.nabove else glide.nbelow; const rows = if (glide.offset < 0) glide.above else glide.below; - for (0..@min(gap, kept)) |i| { + for (0..@min(gap, nkept)) |i| { const cells = rows[i * bw ..][0..bw]; // Row -1 - i above the body, or bh + i below it, in grid rows. const at_row: i32 = if (glide.offset < 0) @as(i32, y0) - 1 - @as(i32, @intCast(i)) else @as(i32, y0) + bh + @as(i32, @intCast(i)); @@ -5560,8 +5563,9 @@ fn stepScroll(g: *Gui, core: *pardes.Pardes, gpa: std.mem.Allocator) void { if (g.scroll_lag == 0) resetScroll(g); } -fn emitScrollRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *pardes.Surface, layout: CellLayout, win_w: f32, win_h: f32, page: Ground) u32 { - if (g.glide.offset != 0) return emitGlideRows(g, instances, base, surface, layout, win_w, win_h, page); +fn emitScrollRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *pardes.Surface, layout: CellLayout, win_w: f32, win_h: f32, page: Ground, held: u16) u32 { + g.scroll_held_px = 0; + if (g.glide.offset != 0) return emitGlideRows(g, instances, base, surface, layout, win_w, win_h, page, held); const scroll_pane = g.scroll_pane orelse return 0; if (g.scroll_lag == 0) return 0; for (surface.panelTracks()) |track| @@ -5575,10 +5579,12 @@ fn emitScrollRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *pard if (x0 + bw > surface.cols or y0 + bh > surface.rows) return 0; // resized under us var shifted = layout; shifted.y_off -= g.scroll_lag * layout.h; + const kept = holdContext(g, surface, scroll_pane, held, bh, layout); + shifted.y_off += kept.lift; const cursor_idx: u32 = if (surface.cursor) |cu| @as(u32, cu.y) * surface.cols + cu.x else std.math.maxInt(u32); const cursor_bar = if (surface.cursor) |cu| cu.bar else false; var n: u32 = 0; - var row = y0; + var row = y0 + kept.rows; while (row < y0 + bh) : (row += 1) { const line = surface.cells[@as(usize, row) * surface.cols ..][0..surface.cols]; const row_cursor: ?usize = if (surface.cursor) |cu| if (cu.y == row) cu.x else null else null; @@ -5600,12 +5606,52 @@ fn emitScrollRows(g: *Gui, instances: [*]CellInstance, base: u32, surface: *pard return n; } +/// A scrolling body's tree-sitter context rows hold still: the shifted +/// rows start under them and are clipped below their band, and where a +/// body layer stacks them at the tagline's height (TreeContextTagStyle) +/// the rows under them are drawn up to meet them, where the layer has them. +fn holdContext(g: *Gui, surface: *const pardes.Surface, id: usize, held: u16, bh: u16, layout: CellLayout) struct { rows: u16, lift: f32 } { + const rows = @min(held, bh); + const layered = id < surface.body_layers.len and surface.body_layers[id].rows != 0 and surface.body_layers[id].context_rows != 0; + const row_px = if (layered) std.math.clamp(@as(f32, @floatFromInt(g.tagline_height)), 1, @max(1, layout.h)) else layout.h; + g.scroll_held_px = @as(f32, @floatFromInt(rows)) * row_px; + return .{ .rows = rows, .lift = @as(f32, @floatFromInt(rows)) * (row_px - layout.h) }; +} + +test "a scroll's shifted rows start under the context rows, and its scissor below their band" { + var surface: pardes.Surface = .{}; + var g: Gui = undefined; + g.tagline_height = 12; + g.scroll_rect = .{ .x = 0, .y = 0, .w = 40, .h = 20 }; + g.scroll_body_y = 1; + g.scroll_body_h = 19; + const layout: CellLayout = .{ .w = 10, .h = 20, .x_off = 0, .y_off = 0 }; + // On the grid, three body-high rows are held, and nothing moves up. + const grid = holdContext(&g, &surface, 0, 3, 19, layout); + try std.testing.expectEqual(@as(u16, 3), grid.rows); + try std.testing.expectEqual(@as(f32, 0), grid.lift); + const clip = scrollScissor(&g, layout, 400, 400); + try std.testing.expectEqual(@as(c_int, 20 + 3 * 20), clip.y); + try std.testing.expectEqual(@as(c_int, 16 * 20), clip.h); + // In a body layer they are tagline-high: the rows under them move up + // by what each is shorter, to where the layer draws them. + surface.body_layers[0].rows = 30; + surface.body_layers[0].context_rows = 3; + const layered = holdContext(&g, &surface, 0, 3, 19, layout); + try std.testing.expectEqual(@as(f32, 3 * (12 - 20)), layered.lift); + try std.testing.expectEqual(@as(c_int, 20 + 3 * 12), scrollScissor(&g, layout, 400, 400).y); + // None held: the whole body moves. + surface.body_layers[0].rows = 0; + try std.testing.expectEqual(@as(u16, 0), holdContext(&g, &surface, 0, 0, 19, layout).rows); + try std.testing.expectEqual(@as(c_int, 20), scrollScissor(&g, layout, 400, 400).y); +} + fn scrollScissor(g: *const Gui, layout: CellLayout, sw: u32, sh: u32) c.SDL_Rect { const r = g.scroll_rect; const px = layout.x_off + @as(f32, @floatFromInt(r.x + config.GUTTER)) * layout.w; - const py = layout.y_off + @as(f32, @floatFromInt(g.scroll_body_y)) * layout.h; + const py = layout.y_off + @as(f32, @floatFromInt(g.scroll_body_y)) * layout.h + g.scroll_held_px; const pw = @as(f32, @floatFromInt(r.w - config.GUTTER)) * layout.w; - const ph = @as(f32, @floatFromInt(g.scroll_body_h)) * layout.h; + const ph = @max(0, @as(f32, @floatFromInt(g.scroll_body_h)) * layout.h - g.scroll_held_px); const x0 = std.math.clamp(@as(i32, @intFromFloat(@floor(px))), 0, @as(i32, @intCast(sw))); const y0 = std.math.clamp(@as(i32, @intFromFloat(@floor(py))), 0, @as(i32, @intCast(sh))); const x1 = std.math.clamp(@as(i32, @intFromFloat(@ceil(px + pw))), x0, @as(i32, @intCast(sw))); @@ -6426,7 +6472,10 @@ fn renderFrame( } for (groups.items[0..groups.len], 0..) |group, index| std.debug.assert(cell_next[index] == group.cell_start + group.cell_count); - shifted = emitScrollRows(g, instances, cell_total, surface, layout, win_w, win_h, page); + // The body's context rows, which its scroll leaves where they are. + const scrolling: ?usize = if (g.glide.offset != 0) g.glide.pane else g.scroll_pane; + const held: u16 = if (core) |p| if (scrolling) |id| if (p.panes[id]) |pane| pane.context_rows else 0 else 0 else 0; + shifted = emitScrollRows(g, instances, cell_total, surface, layout, win_w, win_h, page, held); // Over a theme's plaques a see-through cell with no ink blends to // the plaque under it, so it draws nothing: its quad goes, and the // cells are drawn unblended (a third of the GPU's frame at 4K) diff --git a/src/hunks.zig b/src/hunks.zig new file mode 100644 index 00000000..73c0654a --- /dev/null +++ b/src/hunks.zig @@ -0,0 +1,808 @@ +//! A unified diff (`.diff`, `.patch`, a paged `git show`) stacked as a +//! diff viewer shows it (Diff): each hunk under its `path:line`, the +//! declarations around it from tree-sitter as a result's context +//! (locations.zig), its lines behind their `+`/`-` markers drawn red and +//! green, coloured as their file, and the words a changed line changed on +//! a tinted ground as delta emphasises them (its edits.rs and align.rs, here as `inferEdits` +//! and `Alignment`). +const std = @import("std"); +const pardes = @import("pardes.zig"); +const diff = @import("diff.zig"); +const syntax = @import("syntax.zig"); +const locations = @import("locations.zig"); + +const Pardes = pardes.Pardes; +const Row = locations.Row; + +/// The rows `content`, a diff, stacks to, for a pane in `dir`, with each +/// row's metadata (Output.fillRows). Text and rows are `p.gpa`'s; all else +/// is the step's scratch. +pub fn format(p: *Pardes, dir: []const u8, content: []const u8) !locations.Result { + const arena = p.scratch.allocator(); + const styles = try syntax.highlightDiff(arena, content, 0, content.len); + var out: Out = .{ .p = p, .text = .init(p.gpa) }; + errdefer out.deinit(); + var walk: diff.Walk = .{}; + var hunk: Hunk = .{}; + var source: SourceMemo = .{}; + var at: usize = 0; + // The empty text after a last newline is no line. + while (at < content.len) { + const nl = std.mem.indexOfScalarPos(u8, content, at, '\n') orelse content.len; + const raw = content[at..nl]; + const got = walk.step(raw); + const line = std.mem.trimEnd(u8, raw, "\r"); + switch (got.kind) { + .context, .added, .removed => { + const skip = @intFromBool(line.len > 0 and std.mem.indexOfScalar(u8, " +-", line[0]) != null); + try hunk.lines.append(arena, .{ + .kind = got.kind, + .code = line[skip..], + .styles = styles[at + skip ..][0 .. line.len - skip], + .old = got.old, + .new = got.new, + }); + }, + // A `\ No newline` belongs to the line above, as delta shows it. + .no_newline => {}, + else => { + try flush(&out, &hunk, &source, dir); + switch (got.kind) { + .hunk => hunk = .{ + .path = walk.path(), + .deleted = walk.deleted(), + .old_start = got.old, + .new_start = got.new, + .header = gitContext(line), + }, + // What is said around the hunks, a mailed patch's + // headers, message and diffstat, as it was written. + .other => try out.row(line, "", .{ .kind = .context, .at = .{} }), + // A section's own words (a new file's mode, a rename, + // `Binary files ... differ`), muted; its `diff` and + // `index` lines say nothing the labels do not. + .meta => if (!std.mem.startsWith(u8, line, "diff ") and !std.mem.startsWith(u8, line, "index ")) + try out.row(line, "", .{ .kind = .context, .declaration = true, .at = .{} }), + else => {}, + } + }, + } + at = nl + 1; + } + try flush(&out, &hunk, &source, dir); + const rows = try out.rows.toOwnedSlice(p.gpa); + errdefer locations.freeRows(p.gpa, rows); + return .{ .content = try out.text.toOwnedSlice(), .rows = rows, .anchor = null }; +} + +const HunkLine = struct { + kind: diff.Kind, + code: []const u8, + /// Its code's style bytes, as the diff pane paints them (syntax.zig + /// highlightDiff), the emphasis bit added by `inferEdits`. + styles: []u8, + old: usize, + new: usize, + /// Paired with a line it changed (inferEdits): its words show that; + /// unpaired, the whole line was added or removed. + paired: bool = false, +}; + +const Hunk = struct { + path: []const u8 = "", + deleted: bool = false, + old_start: usize = 0, + new_start: usize = 0, + /// What git wrote after the `@@`'s second marker (its function line). + header: []const u8 = "", + lines: std.ArrayList(HunkLine) = .empty, +}; + +/// `@@ -a,b +c,d @@ fn foo()`: `fn foo()`. +fn gitContext(line: []const u8) []const u8 { + const close = std.mem.indexOfPos(u8, line, 2, "@@") orelse return ""; + return std.mem.trim(u8, line[close + 2 ..], " \t"); +} + +const Out = struct { + p: *Pardes, + text: std.Io.Writer.Allocating, + rows: std.ArrayList(Row) = .empty, + + fn deinit(out: *Out) void { + out.text.deinit(); + for (out.rows.items) |r| { + out.p.gpa.free(r.path); + out.p.gpa.free(r.colors); + } + out.rows.deinit(out.p.gpa); + } + + const Meta = struct { + kind: @FieldType(Row, "kind"), + declaration: bool = false, + at: @FieldType(Row, "at"), + location_end: usize = 0, + code_start: usize = 0, + colors: []const u8 = &.{}, + }; + + /// One row: its text, a newline, and its metadata. + fn row(out: *Out, text: []const u8, path: []const u8, meta: Meta) !void { + const gpa = out.p.gpa; + try out.text.writer.writeAll(text); + try out.text.writer.writeByte('\n'); + const owned_path = try gpa.dupe(u8, path); + errdefer gpa.free(owned_path); + const colors = try gpa.dupe(u8, meta.colors); + errdefer gpa.free(colors); + try out.rows.append(gpa, .{ + .kind = meta.kind, + .declaration = meta.declaration, + .path = owned_path, + .at = meta.at, + .location_end = meta.location_end, + .code_start = meta.code_start, + .colors = colors, + }); + } +}; + +/// The file a diff section names, as found from the pane's directory or +/// one above it (a patch kept in a subdirectory of its repository). +const SourceMemo = struct { + path: []const u8 = "", + /// The name a look from the pane's directory resolves; null when the + /// file is nowhere to be found. + shown: ?[]const u8 = null, + lines: []const []const u8 = &.{}, + declarations: []const syntax.ContextDeclaration = &.{}, +}; + +/// Where a +Diff of `content`, a diff in `dir`, stands: the directory its +/// first file is found from (`dir` or one above it, as `findSource` looks), +/// so its rows name their files as the diff does; `dir` when none is found. +pub fn sourceRoot(p: *Pardes, dir: []const u8, content: []const u8) []const u8 { + var walk: diff.Walk = .{}; + var lines = std.mem.splitScalar(u8, content, '\n'); + const path = while (lines.next()) |line| { + if (walk.step(line).kind == .hunk and walk.path().len > 0) break walk.path(); + } else return dir; + var base: []const u8 = dir; + for (0..8) |_| { + if (locations.sourceText(p, p.scratch.allocator(), base, path) != null) return base; + base = std.fs.path.dirname(base) orelse return dir; + } + return dir; +} + +fn findSource(p: *Pardes, memo: *SourceMemo, dir: []const u8, path: []const u8) !void { + if (std.mem.eql(u8, memo.path, path)) return; + const arena = p.scratch.allocator(); + memo.* = .{ .path = path }; + // ponytail: eight directories up; a repository deeper than that under + // its patch is looked for from the patch's own directory only. + var base: []const u8 = dir; + for (0..8) |_| { + if (locations.sourceText(p, arena, base, path)) |text| { + memo.shown = if (base.ptr == dir.ptr) path else try std.fs.path.relativePosix(arena, "/", dir, text.path); + var lines: std.ArrayList([]const u8) = .empty; + var split = std.mem.splitScalar(u8, text.bytes, '\n'); + while (split.next()) |line| try lines.append(arena, std.mem.trimEnd(u8, line, "\r")); + memo.lines = lines.items; + var hit = p.locations_cache.get(p.tree_sitter_gpa, text.path, text.bytes, true, false) catch + locations.Cache.Hit{ .analysis = syntax.analyzeSource(arena, text.path, text.bytes, true, false) catch .{} }; + defer hit.deinit(p.tree_sitter_gpa); + // The cache's may go at its next use: kept for the section. + memo.declarations = try arena.dupe(syntax.ContextDeclaration, hit.analysis.declarations); + return; + } + base = std.fs.path.dirname(base) orelse return; + } +} + +/// Which side of the hunk the file on disk holds, the new one (the patch +/// applied) or the old one, and how far the file has moved it from where +/// the hunk says (`shift`, lines), as patch finds a hunk in a file edited +/// since. A file edited inside the hunk too still holds most of its lines: +/// the place holding the most of them wins (the nearer on a tie) if it +/// holds at least half. Only some, at the nearest place, could be a sibling +/// with the same lines (two functions with one signature's tail). The rows +/// are counted on that side, so moved. +const Side = enum { new, old, neither }; +const OnDisk = struct { side: Side, shift: i64 = 0 }; + +/// ponytail: a hunk moved more than this many lines is not looked for; +/// each try compares the hunk's lines, so a wider search costs that more. +const max_shift = 200; + +fn sideOnDisk(memo: *const SourceMemo, hunk: *const Hunk) OnDisk { + if (memo.shown == null) return .{ .side = .neither }; + var best: OnDisk = .{ .side = .neither }; + var best_held: usize = 0; + var best_of: usize = 1; + var shift: i64 = 0; + while (shift <= max_shift) : (shift += 1) { + for ([2]i64{ shift, -shift }) |by| { + inline for (.{ Side.new, Side.old }) |side| { + const start: i64 = @as(i64, @intCast((if (side == .new) hunk.new_start else hunk.old_start) -| 1)) + by; + if (start >= 0) { + const got = heldAt(memo, hunk, side, @intCast(start)); + if (got.held == got.of) return .{ .side = side, .shift = by }; + // A larger share only: the nearer keeps a tie. + if (got.held * best_of > best_held * got.of) { + best = .{ .side = side, .shift = by }; + best_held = got.held; + best_of = got.of; + } + } + } + if (shift == 0) break; + } + } + return if (best_held > 0 and best_held * 2 >= best_of) best else .{ .side = .neither }; +} + +/// How many of the hunk's `side` lines the file holds from row `start` on, +/// of how many: blank lines, which match anywhere, count for neither. +fn heldAt(memo: *const SourceMemo, hunk: *const Hunk, comptime side: Side, start: usize) struct { held: usize, of: usize } { + var row = start; + var held: usize = 0; + var of: usize = 0; + for (hunk.lines.items) |line| { + const skipped = if (side == .new) line.kind == .removed else line.kind == .added; + if (skipped) continue; + defer row += 1; + if (std.mem.trim(u8, line.code, " \t").len == 0) continue; + of += 1; + if (row < memo.lines.len and std.mem.eql(u8, memo.lines[row], line.code)) held += 1; + } + return .{ .held = held, .of = @max(of, 1) }; +} + +fn flush(out: *Out, hunk: *Hunk, memo: *SourceMemo, dir: []const u8) !void { + defer hunk.* = .{}; + if (hunk.path.len == 0 or hunk.lines.items.len == 0) return; + const p = out.p; + const arena = p.scratch.allocator(); + try findSource(p, memo, dir, hunk.path); + const disk = sideOnDisk(memo, hunk); + const side = disk.side; + // A line number of the hunk's, where the file has it now. + const moved = struct { + fn by(n: usize, shift: i64) usize { + return @intCast(@max(0, @as(i64, @intCast(n)) + shift)); + } + }.by; + const shown = if (side == .neither) hunk.path else memo.shown.?; + const lines = hunk.lines.items; + + // Where the hunk changes something, on the side its rows count: the + // place its label opens. + const first_change = for (lines) |line| { + if (line.kind != .context) break line; + } else lines[0]; + const on_old = side == .old or (side == .neither and hunk.deleted); + const start_row = moved(if (on_old) hunk.old_start else hunk.new_start, disk.shift) -| 1; + const change_row = moved(if (on_old) first_change.old else first_change.new, disk.shift) -| 1; + + // The declarations it stands in, outermost first, as a result's + // tree-sitter context: each one's header rows above the hunk. + var depth: usize = 0; + if (side != .neither) for (memo.declarations) |declaration| { + if (declaration.start_line >= start_row) break; + if (declaration.end_line < change_row) continue; + depth += 1; + var row = declaration.start_line; + while (row <= declaration.header_end_line and row < start_row) : (row += 1) { + const at: @FieldType(Row, "at") = .{ .line = row + 1 }; + if (row == declaration.start_line and p.locations_config.tslocations) { + const label = try std.fmt.allocPrint(arena, "{s}:{d}", .{ shown, row + 1 }); + try out.row(label, shown, .{ .kind = .context, .declaration = true, .at = at, .location_end = label.len, .code_start = label.len }); + } + // A blank where a hunk line has its marker: the code aligns. + try out.row(try std.fmt.allocPrint(arena, " {s}", .{memo.lines[row]}), shown, .{ .kind = .context, .declaration = true, .at = at }); + } + }; + + // The hunk's label: a step for n and N, and a look's place. + const line_no = change_row + 1; + var label: std.Io.Writer.Allocating = .init(arena); + try label.writer.print("{s}:{d}", .{ shown, line_no }); + const location_end = label.written().len; + if (depth > 0) { + try label.writer.writeByte(' '); + try label.writer.splatByteAll('*', depth); + } + try out.row(label.written(), shown, .{ .kind = .match, .at = .{ .line = line_no }, .location_end = location_end, .code_start = label.written().len }); + // No file to read declarations from: git's own function line, muted + // the same way. With one, git's guess (the last line before the hunk + // that looked like a function) would only contradict it. + if (side == .neither and hunk.header.len > 0) + try out.row(try std.fmt.allocPrint(arena, " {s}", .{hunk.header}), shown, .{ .kind = .context, .declaration = true, .at = .{ .line = line_no } }); + + // Each run of removed lines and the added lines after it: the words + // they changed. + var i: usize = 0; + while (i < lines.len) { + if (lines[i].kind == .context) { + i += 1; + continue; + } + const minus_start = i; + while (i < lines.len and lines[i].kind == .removed) i += 1; + const plus_start = i; + while (i < lines.len and lines[i].kind == .added) i += 1; + try inferEdits(arena, lines[minus_start..plus_start], lines[plus_start..i]); + } + + // Each line behind its marker, `+`, `-` or a blank, as the diff + // has it: the marker coloured, the line as its file's. + for (lines) |line| { + const flag: u8 = switch (line.kind) { + .added => syntax.diff_added, + .removed => syntax.diff_removed, + else => 0, + } | @as(u8, if (line.kind != .context and !line.paired) syntax.diff_whole else 0); + const text = try std.fmt.allocPrint(arena, "{c}{s}", .{ @as(u8, switch (line.kind) { + .added => '+', + .removed => '-', + else => ' ', + }), line.code }); + const colors = try arena.alloc(u8, text.len); + colors[0] = flag; + @memcpy(colors[1..], line.styles); + const on = moved(if (on_old) line.old else line.new, disk.shift); + try out.row(text, shown, .{ .kind = .preview, .at = .{ .line = @max(1, on) }, .colors = colors }); + } +} + +// ---- the words a changed line changed (delta's edits.rs) ---- + +/// delta's `max-line-distance`: a removed and an added line further apart +/// than this are not one line changed, and neither is emphasised. +const max_line_distance = 0.6; + +/// ponytail: a run of more removed or added lines than this, or a pair +/// whose token table is bigger than `max_cells`, is shown unemphasised +/// rather than aligned at a quadratic cost (delta aligns them all). +const max_run = 256; +const max_cells = 1 << 16; + +/// Pair each removed line with the first added line after the last one +/// paired that is near enough to it, in order, and emphasise in both the +/// tokens one has and the other has not. +fn inferEdits(arena: std.mem.Allocator, minus: []HunkLine, plus: []HunkLine) !void { + if (minus.len == 0 or plus.len == 0 or minus.len > max_run or plus.len > max_run) return; + var plus_index: usize = 0; + for (minus) |*m| { + const m_tokens = try tokenize(arena, m.code); + var j = plus_index; + while (j < plus.len) : (j += 1) { + const p_tokens = try tokenize(arena, plus[j].code); + if ((m_tokens.len + 1) * (p_tokens.len + 1) > max_cells) continue; + var alignment = try Alignment.init(arena, m_tokens, p_tokens); + const marks = try annotate(arena, &alignment, m.code, plus[j].code); + if (marks.distance > max_line_distance) continue; + for (marks.minus) |r| for (m.styles[r[0]..r[1]]) |*b| { + b.* |= syntax.diff_emph; + }; + for (marks.plus) |r| for (plus[j].styles[r[0]..r[1]]) |*b| { + b.* |= syntax.diff_emph; + }; + m.paired = true; + plus[j].paired = true; + plus_index = j + 1; + break; + } + } +} + +/// delta's tokenize with its default `\w+`: a leading empty token, each +/// run of word characters one token, and every other character one. A +/// line starting with no word gets a second empty token, as delta's does. +/// ponytail: any byte past ASCII counts as a word character, close to +/// Unicode `\w` for letters; a non-ASCII punctuation mark joins a word. +fn tokenize(arena: std.mem.Allocator, line: []const u8) ![]const []const u8 { + var tokens: std.ArrayList([]const u8) = .empty; + try tokens.append(arena, ""); + if (line.len > 0 and !isWord(line[0])) try tokens.append(arena, ""); + var at: usize = 0; + while (at < line.len) { + var end = at + 1; + // A byte past ASCII is a word's, so what is left is one byte. + if (isWord(line[at])) while (end < line.len and isWord(line[end])) { + end += 1; + }; + try tokens.append(arena, line[at..end]); + at = end; + } + return tokens.items; +} + +fn isWord(c: u8) bool { + return std.ascii.isAlphanumeric(c) or c == '_' or c >= 0x80; +} + +const Op = enum(u2) { noop, deletion, insertion }; + +/// delta's align.rs: a Needleman-Wunsch table over two token lists, a +/// change costing more where it starts a new run, so changes group. +const Alignment = struct { + x: []const []const u8, + y: []const []const u8, + cells: []Cell, + width: usize, + + const Cell = struct { parent: u32, op: Op, cost: u32 }; + const deletion_cost = 2; + const insertion_cost = 2; + const initial_mismatch_penalty = 1; + const never = std.math.maxInt(u32); + + fn init(arena: std.mem.Allocator, x: []const []const u8, y: []const []const u8) !Alignment { + const width = x.len + 1; + const cells = try arena.alloc(Cell, width * (y.len + 1)); + @memset(cells, .{ .parent = 0, .op = .noop, .cost = 0 }); + var a: Alignment = .{ .x = x, .y = y, .cells = cells, .width = width }; + for (1..width) |i| cells[i] = .{ .parent = 0, .op = .deletion, .cost = @intCast(i * deletion_cost + initial_mismatch_penalty) }; + for (1..y.len + 1) |j| cells[j * width] = .{ .parent = 0, .op = .insertion, .cost = @intCast(j * insertion_cost + initial_mismatch_penalty) }; + for (x, 0..) |x_i, i| for (y, 0..) |y_j, j| { + const left = a.index(i, j + 1); + const diag = a.index(i, j); + const up = a.index(i + 1, j); + // Ties go to the first: an insertion, then a deletion, then a + // match, so a moved token reads as removed then added. + const candidates = [3]Cell{ + .{ .parent = @intCast(up), .op = .insertion, .cost = a.mismatchCost(up, insertion_cost) }, + .{ .parent = @intCast(left), .op = .deletion, .cost = a.mismatchCost(left, deletion_cost) }, + .{ .parent = @intCast(diag), .op = .noop, .cost = if (std.mem.eql(u8, x_i, y_j)) cells[diag].cost else never }, + }; + var best = candidates[0]; + for (candidates[1..]) |c| if (c.cost < best.cost) { + best = c; + }; + cells[a.index(i + 1, j + 1)] = best; + }; + return a; + } + + fn mismatchCost(a: *const Alignment, parent: usize, basic: u32) u32 { + const cell = a.cells[parent]; + return cell.cost +| basic +| @as(u32, if (cell.op == .noop) initial_mismatch_penalty else 0); + } + + fn index(a: *const Alignment, i: usize, j: usize) usize { + return j * a.width + i; + } + + /// The operations read back from the table's far corner, in order, + /// each run as one (op, count). + fn coalesced(a: *const Alignment, arena: std.mem.Allocator) ![]const struct { Op, usize } { + var ops: std.ArrayList(Op) = .empty; + var cell = a.cells[a.index(a.x.len, a.y.len)]; + while (true) { + try ops.append(arena, cell.op); + if (cell.parent == 0) break; + cell = a.cells[cell.parent]; + } + std.mem.reverse(Op, ops.items); + var runs: std.ArrayList(struct { Op, usize }) = .empty; + for (ops.items) |op| { + if (runs.items.len > 0 and runs.items[runs.items.len - 1][0] == op) { + runs.items[runs.items.len - 1][1] += 1; + } else try runs.append(arena, .{ op, 1 }); + } + return runs.items; + } +}; + +const Marks = struct { + /// Byte ranges of the removed and the added line to emphasise. + minus: []const [2]usize, + plus: []const [2]usize, + distance: f64, +}; + +/// delta's annotate: walk the alignment's runs over both lines, marking +/// what each deleted and inserted, and a run of blanks between two changes +/// with them; the distance is the changed width over the whole width (a +/// kept section counting on both lines). +fn annotate(arena: std.mem.Allocator, a: *const Alignment, minus_line: []const u8, plus_line: []const u8) !Marks { + var minus: std.ArrayList([2]usize) = .empty; + var plus: std.ArrayList([2]usize) = .empty; + var x_off: usize = 0; + var y_off: usize = 0; + var m_byte: usize = 0; + var p_byte: usize = 0; + var numer: usize = 0; + var denom: usize = 0; + var minus_prev: Op = .noop; + var plus_prev: Op = .noop; + const Take = struct { + fn section(tokens: []const []const u8, off: *usize, byte: *usize, n: usize, line: []const u8) [2]usize { + const start = byte.*; + const end_tok = @min(tokens.len, off.* + n); + for (tokens[@min(off.*, end_tok)..end_tok]) |t| byte.* += t.len; + off.* = end_tok; + byte.* = @min(byte.*, line.len); + return .{ start, byte.* }; + } + }; + for (try a.coalesced(arena)) |run| { + const op, const n = run; + switch (op) { + .deletion => { + const r = Take.section(a.x, &x_off, &m_byte, n, minus_line); + const w = trimmedWidth(minus_line[r[0]..r[1]]); + numer += w; + denom += w; + try minus.append(arena, r); + minus_prev = .deletion; + }, + .noop => { + const r = Take.section(a.x, &x_off, &m_byte, n, minus_line); + const section = minus_line[r[0]..r[1]]; + denom += 2 * trimmedWidth(section); + const is_space = std.mem.trim(u8, section, " \t").len == 0; + const coalesce = is_space and + ((minus_prev == .deletion and plus_prev == .insertion and + (x_off < a.x.len -| 1 or y_off < a.y.len -| 1)) or + (minus_prev == .noop and plus_prev == .noop)); + if (coalesce and minus_prev == .deletion) try minus.append(arena, r); + const pr = Take.section(a.y, &y_off, &p_byte, n, plus_line); + if (coalesce and plus_prev == .insertion) try plus.append(arena, pr); + minus_prev = .noop; + plus_prev = .noop; + }, + .insertion => { + const r = Take.section(a.y, &y_off, &p_byte, n, plus_line); + const w = trimmedWidth(plus_line[r[0]..r[1]]); + numer += w; + denom += w; + try plus.append(arena, r); + plus_prev = .insertion; + }, + } + } + const distance: f64 = if (denom > 0) @as(f64, @floatFromInt(numer)) / @as(f64, @floatFromInt(denom)) else 0; + return .{ .minus = minus.items, .plus = plus.items, .distance = distance }; +} + +fn trimmedWidth(section: []const u8) usize { + return pardes.panes.File.displayWidth(std.mem.trim(u8, section, " \t")); +} + +// ---- tests ---- + +const testing = std.testing; + +fn emphasised(line: HunkLine) ![]const u8 { + var out: std.ArrayList(u8) = .empty; + for (line.code, line.styles) |c, s| try out.append(testing.allocator, if (s & syntax.diff_emph != 0) c else '.'); + return out.toOwnedSlice(testing.allocator); +} + +fn expectEmphasis(minus: []const u8, plus: []const u8, want_minus: []const u8, want_plus: []const u8) !void { + var arena_state: std.heap.ArenaAllocator = .init(testing.allocator); + defer arena_state.deinit(); + const arena = arena_state.allocator(); + var m = [_]HunkLine{.{ .kind = .removed, .code = minus, .styles = try arena.alloc(u8, minus.len), .old = 1, .new = 1 }}; + var p = [_]HunkLine{.{ .kind = .added, .code = plus, .styles = try arena.alloc(u8, plus.len), .old = 2, .new = 1 }}; + @memset(m[0].styles, 0); + @memset(p[0].styles, 0); + try inferEdits(arena, &m, &p); + const got_minus = try emphasised(m[0]); + defer testing.allocator.free(got_minus); + const got_plus = try emphasised(p[0]); + defer testing.allocator.free(got_plus); + try testing.expectEqualStrings(want_minus, got_minus); + try testing.expectEqualStrings(want_plus, got_plus); +} + +test "delta's emphasis: the word a line changed, in both lines" { + try expectEmphasis(" let x = foo(1);", " let x = bar(1);", "............foo....", "............bar...."); + try expectEmphasis("a b c", "a x c", "..b..", "..x.."); +} + +test "delta's emphasis: lines too far apart are no change of one another" { + try expectEmphasis("completely different text", "nothing alike here at all", ".........................", "........................."); +} + +test "delta's emphasis: a word added keeps the rest plain" { + try expectEmphasis("fn run(a: u32)", "fn run(a: u32, b: u32)", "..............", "............., b: u32."); +} + +test "delta's alignment: kitten to sitting, as align.rs has it" { + var arena_state: std.heap.ArenaAllocator = .init(testing.allocator); + defer arena_state.deinit(); + const arena = arena_state.allocator(); + // One token a letter, as delta's test splits them, behind the empty one. + const x = [_][]const u8{ "", "k", "i", "t", "t", "e", "n" }; + const y = [_][]const u8{ "", "s", "i", "t", "t", "i", "n", "g" }; + const a = try Alignment.init(arena, &x, &y); + var ops: std.ArrayList(Op) = .empty; + for (try a.coalesced(arena)) |run| for (0..run[1]) |_| try ops.append(arena, run[0]); + try testing.expectEqualSlices(Op, &.{ .noop, .deletion, .insertion, .noop, .noop, .noop, .deletion, .insertion, .noop, .insertion }, ops.items); +} + +test "a diff stacks to a label a hunk and its lines, markers gone, tinted and stepped" { + const p = try Pardes.init(testing.allocator, .{ .tty_only = true }); + defer p.deinit(); + const patch = + \\diff --git a/nowhere/x.txt b/nowhere/x.txt + \\--- a/nowhere/x.txt + \\+++ b/nowhere/x.txt + \\@@ -1,3 +1,3 @@ section one + \\ keep + \\-old value + \\+new value + \\ tail + \\ + ; + const result = try format(p, "/pardes-surely-missing-dir", patch); + defer p.gpa.free(result.content); + defer locations.freeRows(p.gpa, result.rows); + try testing.expectEqualStrings("nowhere/x.txt:2\n section one\n keep\n-old value\n+new value\n tail\n", result.content); + try testing.expectEqual(@as(usize, 6), result.rows.len); + try testing.expectEqual(.match, result.rows[0].kind); + try testing.expectEqual(@as(usize, "nowhere/x.txt:2".len), result.rows[0].location_end); + try testing.expect(result.rows[1].declaration); + const removed = result.rows[3]; + try testing.expect(removed.colors[0] & syntax.diff_removed != 0); + // Paired with the line it changed: no whole-line tint. + try testing.expect(removed.colors[0] & syntax.diff_whole == 0); + try testing.expect(removed.colors[1] & syntax.diff_emph != 0); + try testing.expect(removed.colors[5] & syntax.diff_emph == 0); + try testing.expect(result.rows[4].colors[0] & syntax.diff_added != 0); + try testing.expect(result.rows[2].colors[0] & (syntax.diff_added | syntax.diff_removed) == 0); +} + +test "a hunk the file has moved since is found where it went, inside its declaration" { + if (!syntax.supportsPath("a.zig")) return error.SkipZigTest; + const p = try Pardes.init(testing.allocator, .{ .tty_only = true }); + defer p.deinit(); + var tmp = testing.tmpDir(.{}); + defer tmp.cleanup(); + // Two lines more above it than the patch knows of. + try tmp.dir.writeFile(testing.io, .{ .sub_path = "a.zig", .data = "// one\n// two\nconst S = struct {\n fn f() void {\n a();\n b();\n }\n};\n" }); + var buf: [std.fs.max_path_bytes]u8 = undefined; + const dir = buf[0..try tmp.dir.realPath(testing.io, &buf)]; + const patch = + \\--- a.zig + \\+++ a.zig + \\@@ -3,3 +3,3 @@ git's guess + \\ fn f() void { + \\- c(); + \\+ a(); + \\ b(); + \\ + ; + const result = try format(p, dir, patch); + defer p.gpa.free(result.content); + defer locations.freeRows(p.gpa, result.rows); + try testing.expect(std.mem.indexOf(u8, result.content, "a.zig:3\n const S = struct {\na.zig:5 *\n") != null); + try testing.expect(std.mem.indexOf(u8, result.content, "git's guess") == null); +} + +test "a mailed patch keeps its headers, message and diffstat above its hunks" { + const p = try Pardes.init(testing.allocator, .{ .tty_only = true }); + defer p.deinit(); + const patch = + \\From 0123 Mon Sep 17 00:00:00 2001 + \\Subject: [PATCH] change x + \\ + \\Why it changed. + \\--- + \\ x.txt | 2 +- + \\ + \\diff --git a/x.txt b/x.txt + \\index 1..2 100644 + \\--- a/x.txt + \\+++ b/x.txt + \\@@ -1 +1 @@ + \\-a + \\+b + \\ + ; + const result = try format(p, "/pardes-surely-missing-dir", patch); + defer p.gpa.free(result.content); + defer locations.freeRows(p.gpa, result.rows); + try testing.expectEqualStrings("From 0123 Mon Sep 17 00:00:00 2001\nSubject: [PATCH] change x\n\nWhy it changed.\n---\n x.txt | 2 +-\n\nx.txt:1\n-a\n+b\n", result.content); +} + +test "DiffLook hunks: a .patch looked at opens its +Diff; Diff goes to the text and back; DiffLook text opens the text" { + const p = try Pardes.init(testing.allocator, .{ .tty_only = true }); + defer p.deinit(); + var tmp = testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(testing.io, .{ .sub_path = "x.txt", .data = "b\n" }); + try tmp.dir.writeFile(testing.io, .{ .sub_path = "c.patch", .data = "--- x.txt\n+++ x.txt\n@@ -1 +1 @@\n-a\n+b\n" }); + var buf: [std.fs.max_path_bytes]u8 = undefined; + const dir = buf[0..try tmp.dir.realPath(testing.io, &buf)]; + const patch = try std.fs.path.join(testing.allocator, &.{ dir, "c.patch" }); + defer testing.allocator.free(patch); + const hunks_path = try std.fs.path.join(testing.allocator, &.{ dir, "+Diff" }); + defer testing.allocator.free(hunks_path); + const Count = struct { + fn of(pp: *Pardes, path: []const u8) usize { + var n: usize = 0; + for (pp.panes) |slot| if (slot) |pane| if (pane.file) |f| { + n += @intFromBool(std.mem.eql(u8, f.path, path)); + }; + return n; + } + }; + try testing.expectEqual(pardes.config.Runtime.DiffLook.hunks, p.settings.diff_look); + pardes.look.lookAt(p, 0, patch); + try testing.expectEqual(@as(usize, 1), Count.of(p, hunks_path)); + try testing.expectEqual(@as(usize, 0), Count.of(p, patch)); + const hid = p.active; + try testing.expectEqualStrings(hunks_path, p.panes[hid].?.file.?.path); + try testing.expectEqualStrings("x.txt:1\n-a\n+b\n", p.panes[hid].?.file.?.content); + // Diff on it: the patch as text. + try testing.expect(p.executeBuiltinLine(hid, "Diff")); + try testing.expectEqual(@as(usize, 1), Count.of(p, patch)); + const raw = p.active; + try testing.expectEqualStrings(patch, p.panes[raw].?.file.?.path); + // Diff on the text: the +Diff again, refilled, not another. + try testing.expect(p.executeBuiltinLine(raw, "Diff")); + try testing.expectEqual(@as(usize, 1), Count.of(p, hunks_path)); + // DiffLook text: a look opens the text (here the pane already open). + try testing.expect(p.executeBuiltinLine(0, "DiffLook text")); + try p.removePane(raw, null); + pardes.look.lookAt(p, 0, patch); + try testing.expectEqual(@as(usize, 1), Count.of(p, patch)); +} + +test "a hunk edited since, beside siblings with its signature's tail, is found in its own function" { + if (!syntax.supportsPath("a.rs")) return error.SkipZigTest; + const p = try Pardes.init(testing.allocator, .{ .tty_only = true }); + defer p.deinit(); + var tmp = testing.tmpDir(.{}); + defer tmp.cleanup(); + // Three functions ending in one signature's tail; the patch is for the + // third, which has moved down a line and had a line inside it edited. + try tmp.dir.writeFile(testing.io, .{ .sub_path = "a.rs", .data = + \\// moved + \\fn one( + \\ limit: usize, + \\) -> u32 { + \\ 1 + \\} + \\fn two( + \\ limit: usize, + \\) -> u32 { + \\ 2 + \\} + \\fn three( + \\ limit: usize, + \\) -> u32 { + \\ let guard = enter(); + \\ let a = 3; + \\ let b = a + 1; + \\ let c = b * 2; // edited since + \\ c + \\} + \\ + }); + var buf: [std.fs.max_path_bytes]u8 = undefined; + const dir = buf[0..try tmp.dir.realPath(testing.io, &buf)]; + const patch = + \\--- a.rs + \\+++ a.rs + \\@@ -12,7 +12,8 @@ git's guess + \\ limit: usize, + \\ ) -> u32 { + \\+ let guard = enter(); + \\ let a = 3; + \\ let b = a + 1; + \\ let c = b * 2; + \\ c + \\ + ; + const result = try format(p, dir, patch); + defer p.gpa.free(result.content); + defer locations.freeRows(p.gpa, result.rows); + try testing.expect(std.mem.indexOf(u8, result.content, "a.rs:12\n fn three(\na.rs:15 *\n") != null); +} diff --git a/src/locations.zig b/src/locations.zig index 6a604907..7755f6fd 100644 --- a/src/locations.zig +++ b/src/locations.zig @@ -159,7 +159,9 @@ const Pending = struct { const Source = struct { path: []const u8, bytes: []const u8 }; -fn sourceText(p: *pardes.Pardes, arena: std.mem.Allocator, dir: []const u8, path: []const u8) ?Source { +/// A file's text as a look from `dir` finds it: an open pane's, unsaved +/// edits and all, else the disk's. Null for a PDF or one not there. +pub fn sourceText(p: *pardes.Pardes, arena: std.mem.Allocator, dir: []const u8, path: []const u8) ?Source { if (std.ascii.eqlIgnoreCase(std.fs.path.extension(path), ".pdf")) return null; const lexical = std.fs.path.resolvePosix(arena, &.{ dir, path }) catch return null; var pathbuf: [4096]u8 = undefined; diff --git a/src/look.zig b/src/look.zig index 41cfdc0c..6ba6a8d0 100644 --- a/src/look.zig +++ b/src/look.zig @@ -1869,6 +1869,18 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void { const before = p.active; var opened: ?usize = null; if (!focusPaneByPath(p, target.path, target.at)) { + // A .diff or .patch looked at bare: its hunks stacked in a + // +Diff (DiffLook hunks), which takes the keyboard as the + // file would; one with none in it opens as text. + if (p.settings.diff_look == .hunks and !p.look_text and target.at.line == 0 and + (std.mem.endsWith(u8, target.path, ".diff") or std.mem.endsWith(u8, target.path, ".patch"))) + if (filesystem.read(p, target.path)) |bytes| { + defer p.gpa.free(bytes); + if (panes.Output.openDiff(p, id, target.path, bytes)) |hid| { + p.active = hid; + return; + } else |_| {} + } else |_| {}; const free = p.freeSlot() orelse return p.reportError(id, "look", error.NoPaneSlots); const nt = panes.File.open(p, free, target.path, target.at.line) catch |err| return lookOpenFailed(p, id, target.path, err); diff --git a/src/main.zig b/src/main.zig index ed70b624..26259b43 100644 --- a/src/main.zig +++ b/src/main.zig @@ -102,7 +102,7 @@ const help_text = ; /// `pardes -` inside a session: `text`, stdin as it came, escapes and all, -/// into the directory's one +Pager (/pager, refilled when it is there): +/// into a new +Pager of the directory (/pager): /// written after the directory on that one open, the session parses it /// (pager.zig) and puts it in as one undo step, left clean. A text the /// session would not take is never lost: it goes to stderr, a terminal, diff --git a/src/mouse.zig b/src/mouse.zig index 8020fda8..733479dd 100644 --- a/src/mouse.zig +++ b/src/mouse.zig @@ -1288,7 +1288,7 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void { pane.sel[sel_slot].state = .none; pane.body.vsel = .{ .active = true, .row = @intCast(a.row), .col = @intCast(a.col), .explicit = true }; }; - if (s.ctrl) p.lspRequest(s.id, .definition, ""); + if (s.ctrl) exec.runBuiltin(p, .Def, s.id, "", null); } } else { const clk = pane.sel[b]; diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index c9ce41e1..e6e738a5 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -682,7 +682,7 @@ pub fn readRoot(p: *Pardes, req: Req) Reply { } /// /pager, `pardes -`'s: the directory written (empty, or not absolute: the -/// session's) gets its one +Pager, made or emptied; the serial is what a +/// session's) gets a new +Pager; the serial is what a /// read of this same open answers, never another client's. What the open /// writes after that line is the text, held by tree.zig for `fillPager`. pub fn writePager(p: *Pardes, req: Req) Reply { @@ -742,6 +742,16 @@ pub fn fillPager(p: *Pardes, serial: u32, held: *std.ArrayList(u8)) error{OutOfM panes.File.setContent(p, f, page.text); f.pager_spans = page.spans; f.saved_revision = f.revision; + // A diff paged (`git show`, difftui's patches): its hunks stacked in a + // +Diff (DiffLook hunks), the +Pager folded to its tag under it for + // Diff to bring back. The keyboard stays where it was, as a page's. + if (f.pager_diff and p.settings.diff_look == .hunks) { + const keyboard = p.active; + if (panes.Output.openDiff(p, id, f.path, f.content)) |_| { + if (!pane.collapsed) pardes.layout.toggleCollapse(p, id); + } else |_| {} + if (p.panes[keyboard] != null) p.active = keyboard; + } } /// The editor's step: the text of /pager opens closed unread goes in. @@ -2258,7 +2268,8 @@ test "a builtin for one kind of pane is refused on another, and still acts on it .{ "Petscii\n", "Petscii: only an image or a terminal pane takes it" }, .{ "Palette\n", "Palette: only an image pane takes it" }, .{ "Ascii\n", "Ascii: only an image pane takes it" }, - .{ "Filter\n", "Filter: only a terminal pane takes it" }, + .{ "Filter\n", "Filter: only a terminal or a +Pager pane takes it" }, + .{ "Diff\n", "Diff: only a diff or a +Diff pane takes it" }, .{ "Togglettymode\n", "Togglettymode: only a terminal pane takes it" }, }; for (cases) |case| { @@ -4607,10 +4618,15 @@ test "pager answers its +Pager on the open that asked, whatever another client e try testing.expectEqual(E.INVAL, call(p, .{ .tag = 8, .op = .write, .node = pager, .handle = refused, .data = "relative\n" }).errno()); try testing.expectEqualStrings("", call(p, .{ .tag = 9, .op = .read, .node = pager, .handle = refused, .size = 64 }).bytes); _ = call(p, .{ .tag = 10, .op = .release, .node = pager, .handle = refused, .opened = true }); - // Resolved: `/tmp/../tmp/.` is /tmp's +Pager, the one made above. + // Resolved: `/tmp/../tmp/.` is /tmp, a +Pager of its own beside the + // one made above, which keeps its page. const resolved = call(p, .{ .tag = 11, .op = .open, .node = pager, .omode = 2 }).reply.handle; try testing.expectEqual(Status.ok, call(p, .{ .tag = 12, .op = .write, .node = pager, .handle = resolved, .data = "/tmp/../tmp/.\n" }).reply.status); - try testing.expectEqualStrings(want, call(p, .{ .tag = 13, .op = .read, .node = pager, .handle = resolved, .size = 64 }).bytes); + const second = call(p, .{ .tag = 13, .op = .read, .node = pager, .handle = resolved, .size = 64 }).bytes; + try testing.expect(!std.mem.eql(u8, want, second)); + const second_pane = p.panes[p.paneBySerial(try std.fmt.parseInt(u32, std.mem.trim(u8, second, "\n"), 10)).?].?; + try testing.expectEqualStrings("/tmp/+Pager", second_pane.file.?.path); + try testing.expect(p.paneBySerial(paged) != null); _ = call(p, .{ .tag = 14, .op = .release, .node = pager, .handle = resolved, .opened = true }); // One that may not be written is refused, permission denied. try testing.expectEqual(E.PERM, wr(p, pager, "/proc/1\n").errno()); @@ -4667,15 +4683,24 @@ test "what a /pager open writes after its directory is the text: plain in the bo // PagerColor off, and an open closed with no read: the same text, plain, // in at the editor's next step (a close through a mount never waits). p.settings.pager_color = false; + const kept = try testing.allocator.dupe(u8, f.content); + defer testing.allocator.free(kept); const shut = call(p, .{ .tag = 7, .op = .open, .node = pager, .omode = 1 }).reply.handle; try testing.expectEqual(Status.ok, call(p, .{ .tag = 8, .op = .write, .node = pager, .handle = shut, .data = "/tmp\n" }).reply.status); try testing.expectEqual(Status.ok, call(p, .{ .tag = 9, .op = .write, .node = pager, .handle = shut, .data = "\x1b[1;32mgreen\x1b[m\n" }).reply.status); _ = call(p, .{ .tag = 10, .op = .release, .node = pager, .handle = shut, .opened = true }); - try testing.expectEqualStrings("", f.content); + // A new +Pager: the first keeps its page. + try testing.expectEqualStrings(kept, f.content); + const next = for (p.panes) |slot| { + const other = slot orelse continue; + if (other == pn) continue; + if (other.file) |*of| if (std.mem.eql(u8, of.path, "/tmp/+Pager")) break of; + } else return error.NoPager; + try testing.expectEqualStrings("", next.content); fillClosedPagers(p); - try testing.expectEqualStrings("green\n", f.content); - try testing.expectEqual(@as(usize, 0), f.pager_spans.len); - try testing.expectEqual(f.revision, f.saved_revision); + try testing.expectEqualStrings("green\n", next.content); + try testing.expectEqual(@as(usize, 0), next.pager_spans.len); + try testing.expectEqual(next.revision, next.saved_revision); } test "a command pane an exec open was answered is leased to it while it stays open: another client's command gets a pane of its own" { diff --git a/src/ninep/tree.zig b/src/ninep/tree.zig index c78a1aa2..eedab43b 100644 --- a/src/ninep/tree.zig +++ b/src/ninep/tree.zig @@ -258,7 +258,7 @@ pub const TopFile = enum(u5) { /// The files opened lately, closed ones too, a line each: /// `open|closed <path>`, most recent first. recent, - /// `pardes -`'s: a directory written, its +Pager made or emptied; a + /// `pardes -`'s: a directory written, a new +Pager made there; a /// read of the same open answers its serial. pager, diff --git a/src/normal.zig b/src/normal.zig index 93487e88..aec6b983 100644 --- a/src/normal.zig +++ b/src/normal.zig @@ -743,14 +743,15 @@ fn executeNormalAction(p: *Pardes, t: *Text, semantic: modal.Normal.Action) void .undo => return edit.doUndo(p, t), .redo => return edit.doRedo(p, t), }, - .lsp => |request| return p.lspRequest(p.active, switch (request) { - .definition => .definition, - .declaration => .declaration, - .type_definition => .type_definition, - .implementation => .implementation, - .references => .references, - .format => .format, - }, ""), + // gd and gr are the Def and Refs a tag shows, run as a click runs them. + .lsp => |request| return switch (request) { + .definition => exec.runBuiltin(p, .Def, p.active, "", null), + .references => exec.runBuiltin(p, .Refs, p.active, "", null), + .declaration => p.lspRequest(p.active, .declaration, ""), + .type_definition => p.lspRequest(p.active, .type_definition, ""), + .implementation => p.lspRequest(p.active, .implementation, ""), + .format => p.lspRequest(p.active, .format, ""), + }, .adjust_number => |delta| return edit.normalAdjustNumber(p, t, delta), .leader => if (p.macro.replaying == 0) { p.leader_on = true; diff --git a/src/pardes.zig b/src/pardes.zig index 2a74e441..29192c33 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -480,6 +480,7 @@ pub const Loc = struct { test { _ = @import("tagline.zig"); + _ = @import("hunks.zig"); _ = @import("builtins_json.zig"); _ = @import("exec.zig"); _ = @import("look.zig"); @@ -864,7 +865,7 @@ test "TreeContext command and custom tag survive a workspace round trip" { p.gpa.free(pane.file.?.path); pane.file.?.path = path; if (!panes.File.supportsContext(pane)) return error.SkipZigTest; - try std.testing.expectEqualStrings(tagline.context_pane_tail, tagline.curTail(pane)); + try std.testing.expectEqualStrings(if (lsp.speaks("/test.zig")) tagline.lsp_context_pane_tail else tagline.context_pane_tail, tagline.curTail(pane)); try std.testing.expect(!pane.file.?.tree_context); try std.testing.expect(p.executeBuiltinLine(0, "TreeContext on")); try std.testing.expect(pane.file.?.tree_context); @@ -920,7 +921,7 @@ test "Togglettymode builtin and keyboard chord share mode transitions including try std.testing.expectEqualStrings("unchanged\n", file.file.?.content); } -test "Filter is ordered after Del and toggles only its terminal pane" { +test "Filter is ordered after Del and toggles only its terminal or +Pager pane" { const testing = std.testing; const del = std.meta.stringToEnum(Builtin, "Del") orelse return error.MissingDelBuiltin; const filter = std.meta.stringToEnum(Builtin, "Filter") orelse return error.MissingFilterBuiltin; @@ -954,6 +955,17 @@ test "Filter is ordered after Del and toggles only its terminal pane" { try testing.expect(p.executeBuiltinLine(0, "Filter")); try testing.expect(first.tty_filter); try testing.expect(!second.tty_filter); + + // A +Pager opens filtered, with Filter on its tag and no line numbers; + // a second is a pane of its own. + const pager_id = try panes.Output.openPager(p, 0, "/tmp"); + const pager_pane = p.panes[pager_id].?; + try testing.expect(pager_pane.tty_filter); + try testing.expectEqualStrings(tagline.pager_pane_tail, tagline.curTail(pager_pane)); + try testing.expectEqual(@as(u16, 0), panes.File.gutterWidth(pager_pane)); + try testing.expect(p.executeBuiltinLine(pager_id, "Filter")); + try testing.expect(!pager_pane.tty_filter); + try testing.expect(try panes.Output.openPager(p, 0, "/tmp") != pager_id); } test "compact tag commands stay beside their own prefix across layout changes" { @@ -1194,6 +1206,73 @@ test "Lspwhy after a Hover asks to explain that hover, in its file at its place, try std.testing.expect(seen); } +test "Def and Refs are a speaking file's tag words; gd, gr and a 2-1 chord all run them" { + if (!lsp.supports.contains(.definition)) return error.SkipZigTest; + const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 24, .tty_only = true }); + defer p.deinit(); + const pane = try p.setTestFile("const alpha = 1;\nconst beta = alpha;\n"); + // A .txt has no server: no Def, no Refs. + try std.testing.expect(std.mem.indexOf(u8, tagline.curTail(pane), "Def") == null); + const f = &pane.file.?; + p.gpa.free(f.path); + f.path = try p.gpa.dupe(u8, "/tmp/x.zig"); + try std.testing.expect(std.mem.endsWith(u8, tagline.curTail(pane), " Def Refs")); + p.sync(); + while (p.nextEffect()) |_| {} + const Asked = struct { + fn one(q: *Pardes, kind: lsp.Kind) !u32 { + var at: ?u32 = null; + while (q.nextEffect()) |e| if (e == .lsp) { + try std.testing.expectEqual(kind, e.lsp.kind); + try std.testing.expectEqualStrings("", e.lsp.arg.slice()); + try std.testing.expect(at == null); + at = e.lsp.offset; + }; + q.lsp_wait = null; + return at orelse error.NothingAsked; + } + }; + // gd and gr: at the cursor, on `alpha`'s declaration. + pane.body.cur_row = 0; + pane.body.cur_col = 8; + p.update(.{ .key = .{ .cp = 'g' } }); + p.update(.{ .key = .{ .cp = 'd' } }); + try std.testing.expectEqual(@as(u32, 8), try Asked.one(p, .definition)); + p.update(.{ .key = .{ .cp = 'g' } }); + p.update(.{ .key = .{ .cp = 'r' } }); + try std.testing.expectEqual(@as(u32, 8), try Asked.one(p, .references)); + + const r = p.rects[0]; + const x0 = r.x + config.GUTTER + panes.File.gutterWidth(pane); + const use_y = p.bodyTop(pane, r) + 1; + const tag = try tagline.tagText(p, p.scratch.allocator(), pane); + for ([_]struct { word: []const u8, kind: lsp.Kind }{ .{ .word = " Def ", .kind = .definition }, .{ .word = " Refs", .kind = .references } }) |w| { + // B1 sweeps the use of `alpha` on the second line (bytes 30..35), + // leaving the cursor at its far end. + p.update(.{ .mouse = .{ .button = config.select_button, .kind = .press, .col = x0 + 13, .row = use_y } }); + p.update(.{ .mouse = .{ .button = config.select_button, .kind = .drag, .col = x0 + 17, .row = use_y } }); + p.update(.{ .mouse = .{ .button = config.select_button, .kind = .release, .col = x0 + 17, .row = use_y } }); + // B2 on the tag word, B1 clicked while it is held: the sweep is its + // argument, and it asks at the start of `alpha`, not at the cursor. + const wx = r.x + TAG_TEXT_INSET + @as(u16, @intCast(std.mem.indexOf(u8, tag, w.word).? + 1)); + p.update(.{ .mouse = .{ .button = config.exec_button, .kind = .press, .col = wx, .row = r.y } }); + p.update(.{ .mouse = .{ .button = config.select_button, .kind = .press, .col = wx, .row = r.y } }); + p.update(.{ .mouse = .{ .button = config.select_button, .kind = .release, .col = wx, .row = r.y } }); + p.update(.{ .mouse = .{ .button = config.exec_button, .kind = .release, .col = wx, .row = r.y } }); + try std.testing.expectEqual(@as(u32, 30), try Asked.one(p, w.kind)); + // Clicked bare, it asks at the cursor, where the sweep left it. + pane.body.cur_row = 0; + pane.body.cur_col = 2; + p.update(.{ .mouse = .{ .button = config.exec_button, .kind = .press, .col = wx, .row = r.y } }); + p.update(.{ .mouse = .{ .button = config.exec_button, .kind = .release, .col = wx, .row = r.y } }); + try std.testing.expectEqual(@as(u32, 2), try Asked.one(p, w.kind)); + } + // A symbol the file does not hold is said, and nothing is asked. + exec.runBuiltin(p, .Def, 0, "", "gamma"); + try std.testing.expectError(error.NothingAsked, Asked.one(p, .definition)); + try std.testing.expectEqualStrings("Def: no gamma in this file", pane.msg[0..pane.msg_len]); +} + test "the Tutor pane is named +Tutor in the session's directory, never a bare path at the root" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); defer p.deinit(); @@ -4508,6 +4587,9 @@ pub const Pardes = struct { chord_hold: bool = false, /// The look just run found nothing (look.zig missed). look_missed: bool = false, + /// The look being run opens a .diff or .patch as text whatever DiffLook + /// says: Diff going back from a +Diff, Edit's B (it edits the file). + look_text: bool = false, look_hover_wait: ?look.LookHoverWait = null, /// The place a look-hover last found nothing to open: the pointer /// resting there does not ask again every frame (look.noteLookHover). @@ -4748,6 +4830,8 @@ pub const Pardes = struct { const named = try std.fs.path.join(gpa, &.{ dir, "+Pager" }); gpa.free(shown.file.?.path); shown.file.?.path = named; + shown.file.?.pager = true; + shown.tty_filter = true; shown.file.?.pager_diff = panes.File.looksLikeDiff(content[0..@min(content.len, 64 * 1024)]); shown.file.?.pager_spans = page.spans; p.oneColumn(); @@ -6674,7 +6758,8 @@ pub const Pardes = struct { pub const SavePath = Effect.Buf(effect_path_cap); - pub fn lspRequest(p: *Pardes, asked: usize, kind: lsp.Kind, arg: []const u8) void { + pub fn lspRequest(p: *Pardes, asked: usize, kind: lsp.Kind, arg_in: []const u8) void { + var arg = arg_in; if (!normal.multiOnce(p)) return; // one question per keystroke, from the primary // Lspwhy narrates the last query where it was asked -- that pane's // file, place and argument -- from wherever it is run. @@ -6697,10 +6782,30 @@ pub const Pardes = struct { (!zig_buf and std.mem.indexOfAny(u8, arg, " \t\r\n\"\\") != null)) return p.reportFailure(id, std.fmt.bufPrint(&said, "Rename: {s} is no name", .{arg}) catch "Rename: no name"); } - const off = if (pane.file) |f| modal.offsetAt(f.content, .{ + var off = if (pane.file) |f| modal.offsetAt(f.content, .{ .row = @intCast(@max(0, pane.body.cur_row)), .col = @intCast(@max(0, pane.body.cur_col)), }) else 0; + // Def or Refs given a symbol (a 2-1 chord's selection) asks at its + // occurrence nearest the cursor, which a sweep leaves at one end of + // what it selected; the server is asked at a place, never a name. + if ((kind == .definition or kind == .references) and arg.len > 0) { + const content = pane.file.?.content; + var nearest: ?usize = null; + var best: usize = 0; + var from: usize = 0; + while (std.mem.indexOfPos(u8, content, from, arg)) |at_hit| : (from = at_hit + 1) { + const d = if (at_hit > off) at_hit - off else off -| (at_hit + arg.len); + if (nearest != null and at_hit > off and d >= best) break; + if (nearest == null or d < best) { + nearest = at_hit; + best = d; + } + } + off = nearest orelse + return p.reportFailure(id, std.fmt.bufPrint(&said, "{s}: no {s} in this file", .{ lspWord(kind), arg }) catch "no such symbol in this file"); + arg = ""; + } // Lspwhy asks the last query again, narrated: its kind and argument, // at its place when asked from its pane. None yet: a definition. var explained: [160]u8 = undefined; @@ -6858,6 +6963,8 @@ pub const Pardes = struct { fn lspWord(kind: lsp.Kind) []const u8 { return switch (kind) { .hover => "Hover", + .definition => "Def", + .references => "Refs", .explain => "Lspwhy", .incoming_calls => "Callers", .outgoing_calls => "Callees", diff --git a/src/syntax.zig b/src/syntax.zig index b7406b04..89d96239 100644 --- a/src/syntax.zig +++ b/src/syntax.zig @@ -854,7 +854,13 @@ pub fn highlightLocationRows(gpa: std.mem.Allocator, content: []const u8, rows: if (comptime @hasField(@TypeOf(row), "location_end")) { address_only = row.location_end > 0 and source_start == end; } - if (!address_only) { + // A row its producer coloured whole is coloured below: no + // fragment of it to parse. + var coloured = false; + if (comptime @hasField(@TypeOf(row), "colors")) { + coloured = row.colors.len > 0 and row.colors.len >= end - source_start; + } + if (!address_only and !coloured) { sources[source_count] = .{ .index = index, .start = source_start, .len = end - source_start }; source_count += 1; } @@ -1037,10 +1043,15 @@ fn childOfKind(node: ts.Node, kind: []const u8) ?ts.Node { /// A diff line's style byte carries whether the line was added or removed /// over its syntax style (the low bits), so the painter can tint its row -/// and mark its prefix. +/// and mark its prefix; Diff marks the words a changed line changed +/// (hunks.zig), drawn on a stronger tint. pub const diff_added: u8 = 0x80; pub const diff_removed: u8 = 0x40; -pub const syn_bits: u8 = 0x3f; +pub const diff_emph: u8 = 0x20; +/// A +Diff line added or removed whole, paired with no line it changed: +/// its row takes a faint tint, on its marker's byte. +pub const diff_whole: u8 = 0x10; +pub const syn_bits: u8 = 0x0f; /// A file section's hunks are parsed together, each side as one text, in /// pieces: a piece takes whole hunks until it holds `diff_piece_lines` diff --git a/src/tagline.zig b/src/tagline.zig index d13f3c5f..cf0b17fd 100644 --- a/src/tagline.zig +++ b/src/tagline.zig @@ -21,6 +21,13 @@ pub const pdf_pane_tail = " " ++ config.pdf_pane_builtins_str; pub const file_pane_tail = " " ++ config.file_pane_builtins_str; pub const context_pane_tail = file_pane_tail ++ " TreeContext"; pub const locations_pane_tail = file_pane_tail ++ " LocationsConfig"; +/// A file a language server speaks for (by its extension): its jumps too. +pub const lsp_pane_tail = file_pane_tail ++ " " ++ config.lsp_pane_builtins_str; +pub const lsp_context_pane_tail = context_pane_tail ++ " " ++ config.lsp_pane_builtins_str; +pub const pager_pane_tail = " " ++ config.pager_pane_builtins_str; +pub const diff_pane_tail = " " ++ config.diff_pane_builtins_str; +pub const pager_diff_pane_tail = " " ++ config.pager_diff_pane_builtins_str; +pub const diff_view_tail = " " ++ config.diff_view_builtins_str ++ " LocationsConfig"; pub const terminal_pane_tail = " " ++ config.terminal_pane_builtins_str; pub const command_pane_tail = " " ++ config.command_pane_builtins_str; pub const dir_pane_tail = " " ++ config.dir_pane_builtins_str; @@ -164,10 +171,15 @@ pub fn curTail(pane: *Pane) []const u8 { pub fn defaultTail(pane: *const Pane) []const u8 { if (comptime pdf_enabled) if (pane.pdf != null) return pdf_pane_tail; if (pane.file) |file| if (file.listing != null) return dir_pane_tail; - if (pane.file) |file| if (file.output) |out| + if (pane.file) |file| if (file.pager) return if (file.pager_diff) pager_diff_pane_tail else pager_pane_tail; + if (pane.file != null and pane.colorAlgo() == .diff) return diff_pane_tail; + if (pane.file) |file| if (file.output) |out| { + if (std.meta.eql(out.from, panes.Output.Origin{ .cmd = .Diff })) return diff_view_tail; if (panes.Output.usesLocationsConfig(out.from)) return locations_pane_tail; - if (panes.File.supportsContext(pane)) return context_pane_tail; - if (pane.file != null) return file_pane_tail; + }; + const speaks = if (pane.file) |file| file.output == null and file.mini == null and pardes.lsp.speaks(file.path) else false; + if (panes.File.supportsContext(pane)) return if (speaks) lsp_context_pane_tail else context_pane_tail; + if (pane.file != null) return if (speaks) lsp_pane_tail else file_pane_tail; if (pane.command != null) return command_pane_tail; if (pane.isTerminal()) return if (pane.shell_tail_len > 0) pane.shell_tail[0..pane.shell_tail_len] else terminal_pane_tail; return pane_tail; diff --git a/src/terminal.zig b/src/terminal.zig index 3bb1fbda..3190c6e3 100644 --- a/src/terminal.zig +++ b/src/terminal.zig @@ -2041,7 +2041,7 @@ pub fn recolorAnsi(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, tx: u16 const filtered: ?*FilteredColors = if (pane.tty_filter) blk: { const tz_filter = tracy.zone(@src(), "filterInit"); defer tz_filter.end(); - filtered_storage = FilteredColors.init(p, pane); + filtered_storage = FilteredColors.init(p, &pane.terminal.?.vt); break :blk &filtered_storage; } else null; // DECSCNM, read once: the filtered palette folds it in itself, the raw @@ -2192,7 +2192,9 @@ fn cellStyle(p: *Pardes, ci: ghostty_vt.PageList.Cell, filtered: ?*FilteredColor return cs; } -const FilteredColors = struct { +/// A program's colours mapped to the theme (Filter): a terminal's cells, or +/// a +Pager's spans (`vt` null, the program's palette xterm's own). +pub const FilteredColors = if (enabled) struct { source: GColor.Palette, target: *const GColor.Palette, theme_bg: GColor.RGB, @@ -2212,16 +2214,18 @@ const FilteredColors = struct { cache_key: [256]u8 = undefined, cache_valid: [256]bool = @splat(false), - fn init(p: *Pardes, pane: *const Pane) FilteredColors { + pub fn init(p: *Pardes, vt: ?*const ghostty_vt.Terminal) FilteredColors { var source = GColor.default; - for (&source, 0..) |*rgb, i| - rgb.* = pane.terminal.?.vt.colorForXterm(.{ .palette = @intCast(i) }) orelse rgb.*; + if (vt) |t| { + for (&source, 0..) |*rgb, i| + rgb.* = t.colorForXterm(.{ .palette = @intCast(i) }) orelse rgb.*; + } const theme = p.theme(); var theme_bg = asGhostRgb(theme.bg orelse theme.tag_bg); var theme_fg = asGhostRgb(theme.fg orelse theme.tag_fg); - var dynamic_bg = pane.terminal.?.vt.colorForXterm(.{ .dynamic = .background }); - var dynamic_fg = pane.terminal.?.vt.colorForXterm(.{ .dynamic = .foreground }); - if (pane.terminal.?.vt.modes.get(.reverse_colors)) { + var dynamic_bg = if (vt) |t| t.colorForXterm(.{ .dynamic = .background }) else null; + var dynamic_fg = if (vt) |t| t.colorForXterm(.{ .dynamic = .foreground }) else null; + if (vt != null and vt.?.modes.get(.reverse_colors)) { std.mem.swap(GColor.RGB, &theme_bg, &theme_fg); std.mem.swap(?GColor.RGB, &dynamic_bg, &dynamic_fg); } @@ -2280,6 +2284,18 @@ const FilteredColors = struct { return asPardesColor(self.keyedRgb(style.bg(cell, &self.source).?)); } + /// A +Pager span's colour (pager.zig), as `fg` and `bg` map a cell's. + pub fn spanColor(self: *FilteredColors, color: pardes.Color, is_bg: bool) pardes.Color { + return switch (color) { + .default => color, + .index => |idx| if (is_bg) self.bg_for_palette[idx] else self.fg_for_palette[idx], + .rgb => |rgb| blk: { + const keyed = self.keyedRgb(asGhostRgb(rgb)); + break :blk asPardesColor(if (is_bg) keyed else self.legible(keyed)); + }, + }; + } + fn legible(self: *const FilteredColors, rgb: GColor.RGB) GColor.RGB { if (contrastOf(luminanceOf(rgb), self.default_bg_luminance) >= config.tty_filter_min_contrast) return rgb; @@ -2317,7 +2333,7 @@ const FilteredColors = struct { self.cache_valid[slot] = true; return best; } -}; +} else struct {}; const channel_luminance: [256]f64 = blk: { @setEvalBranchQuota(20000); @@ -2570,7 +2586,7 @@ test "terminal Filter maps the default roles before it maps anything else" { // the null-page fallback that only the legacy dark theme exercises. for (0..9) |t| { p.settings.theme = @intCast(t); - const stage_one = FilteredColors.init(p, pane); + const stage_one = FilteredColors.init(p, &pane.terminal.?.vt); // `dark` declares no background of its own, which is exactly why the // resolver reads the tag colours as the fallback rather than `.?`. const theme = p.theme(); @@ -2584,7 +2600,7 @@ test "terminal Filter maps the default roles before it maps anything else" { p.settings.theme = 0; p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b]11;#5f5f5f\x1b\\" } }); - var moved = FilteredColors.init(p, pane); + var moved = FilteredColors.init(p, &pane.terminal.?.vt); try testing.expect(!moved.default_bg.eql(moved.theme_bg)); try testing.expect(moved.default_bg.eql(moved.keyedRgb(.{ .r = 0x5f, .g = 0x5f, .b = 0x5f }))); } @@ -2609,7 +2625,7 @@ test "terminal Filter refuses a foreground that would collapse onto the page" { for (0..9) |t| { p.settings.theme = @intCast(t); - var fc = FilteredColors.init(p, pane); + var fc = FilteredColors.init(p, &pane.terminal.?.vt); const page = asPardesColor(fc.default_bg); const rescued = asPardesColor(fc.fallback_fg); _ = frame.reset(.retain_capacity); @@ -2661,7 +2677,7 @@ test "terminal Filter holds every projected foreground off the page" { for (0..9) |t| { p.settings.theme = @intCast(t); - var fc = FilteredColors.init(p, pane); + var fc = FilteredColors.init(p, &pane.terminal.?.vt); var refused: usize = 0; for (fc.target, 0..) |projected, key| { const ink = fc.legible(projected); diff --git a/test/snapshots/diffview.golden b/test/snapshots/diffview.golden index 9e171fd8..868e5e85 100644 --- a/test/snapshots/diffview.golden +++ b/test/snapshots/diffview.golden @@ -1,7 +1,7 @@ == snap diff-pane grid=100x31 cursor=7,3 |Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/diffview/cwd/change.diff Save Tty Collapse Del +| /tmp/pardes-snap/diffview/cwd/change.diff Save Tty Diff Collapse Del | 1 diff --git a/src/shape.zig b/src/shape.zig | 2 index 1111111..2222222 100644 | 3 --- a/src/shape.zig @@ -55,7 +55,7 @@ |29: 0-0 d,#608269, 1-99 d,#0d1410, |30: 0-0 d,#608269, 1-99 d,#0d1410, == snap look-added-line grid=100x31 cursor=55,22 -|16: /tmp/pardes-snap/diffview/cwd/src/shape.zig Save Tty Collapse Del TreeContext +|16: /tmp/pardes-snap/diffview/cwd/src/shape.zig Save Tty Collapse Del TreeContext Def Refs |17: 1 const std = @import("std"); |18: 2 |19: 3 pub const Shape = union(enum) { @@ -134,7 +134,7 @@ |30: 0-0 d,#152019, 1-99 d,#0d1410, == snap command-look grid=100x31 cursor=23,10 |3: 1 cat change.diff -|5: /tmp/pardes-snap/diffview/cwd/src/shape.zig Save Tty Collapse Del TreeContext +|5: /tmp/pardes-snap/diffview/cwd/src/shape.zig Save Tty Collapse Del TreeContext Def Refs |6: 1 const std = @import("std"); |7: 2 |8: 3 pub const Shape = union(enum) { diff --git a/test/snapshots/lsp-client-edit.golden b/test/snapshots/lsp-client-edit.golden index c36d15be..c9d93379 100644 --- a/test/snapshots/lsp-client-edit.golden +++ b/test/snapshots/lsp-client-edit.golden @@ -1,7 +1,7 @@ == snap formatted grid=100x25 cursor=7,4 |Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol -| * /tmp/pardes-snap/lsp-client-edit/cwd/main.rs Save Tty Collapse Del TreeContext +| * /tmp/pardes-snap/lsp-client-edit/cwd/main.rs Save Tty Collapse Del TreeContext Def Refs | 1 // formatted by mock formatted 1 range(s) | 2 mod lib; | 3 @@ -12,7 +12,7 @@ | 8 } | 9 == snap unformatted grid=100x25 cursor=7,3 -|2: /tmp/pardes-snap/lsp-client-edit/cwd/main.rs Save Tty Collapse Del TreeContext +|2: /tmp/pardes-snap/lsp-client-edit/cwd/main.rs Save Tty Collapse Del TreeContext Def Refs |3: 1 mod lib; |4: 2 |5: 3 fn main() { @@ -23,12 +23,12 @@ |10: 8 |11: == snap renamed grid=100x25 cursor=12,5 -|2: * /tmp/pardes-snap/lsp-client-edit/cwd/main.rs Save Tty Collapse Del TreeContext +|2: * /tmp/pardes-snap/lsp-client-edit/cwd/main.rs Save Tty Collapse Del TreeContext Def Refs |3: 1 mod lib; renamed 2 range(s) |6: 4 let x = sum(1, 2); |7: 5 let y = sum(3, 4); == snap unrenamed grid=100x25 cursor=12,5 -|2: /tmp/pardes-snap/lsp-client-edit/cwd/main.rs Save Tty Collapse Del TreeContext +|2: /tmp/pardes-snap/lsp-client-edit/cwd/main.rs Save Tty Collapse Del TreeContext Def Refs |3: 1 mod lib; |6: 4 let x = add(1, 2); |7: 5 let y = add(3, 4); diff --git a/test/snapshots/lsp-client.golden b/test/snapshots/lsp-client.golden index 23d86e11..13771394 100644 --- a/test/snapshots/lsp-client.golden +++ b/test/snapshots/lsp-client.golden @@ -1,7 +1,7 @@ == snap gd-jumped grid=100x25 cursor=16,12 |Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/lsp-client/cwd/main.rs Save Tty Collapse Del TreeContext +| /tmp/pardes-snap/lsp-client/cwd/main.rs Save Tty Collapse Del TreeContext Def Refs | 1 mod lib; --:--:-- lsp rust-analyzer: ready | 2 | 3 fn main() { @@ -9,7 +9,7 @@ | 5 let y = add(3, 4); | 6 let _ = x + y; | 7 } -| /tmp/pardes-snap/lsp-client/cwd/lib.rs Save Tty Collapse Del TreeContext +| /tmp/pardes-snap/lsp-client/cwd/lib.rs Save Tty Collapse Del TreeContext Def Refs | 1 // mock fixture | 2 pub fn add(a: i32, b: i32) -> i32 { | 3 a + b diff --git a/test/snapshots/lsp-rename-files.golden b/test/snapshots/lsp-rename-files.golden index ea093dbf..4f71424e 100644 --- a/test/snapshots/lsp-rename-files.golden +++ b/test/snapshots/lsp-rename-files.golden @@ -1,12 +1,12 @@ == snap opened grid=100x25 cursor=7,8 |Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/lsp-rename-files/cwd/lib.rs Save Tty Collapse Del TreeContext +| /tmp/pardes-snap/lsp-rename-files/cwd/lib.rs Save Tty Collapse Del TreeContext Def Refs | 1 // main.rs | 2 pub fn add(a: i32, b: i32) -> i32 { | 3 a + b | 4 } -| /tmp/pardes-snap/lsp-rename-files/cwd/main.rs Save Tty Collapse Del TreeContext +| /tmp/pardes-snap/lsp-rename-files/cwd/main.rs Save Tty Collapse Del TreeContext Def Refs | 1 mod lib; | 2 | 3 fn main() { diff --git a/test/snapshots/lsp-rename.golden b/test/snapshots/lsp-rename.golden index ba19d8f0..6b85822c 100644 --- a/test/snapshots/lsp-rename.golden +++ b/test/snapshots/lsp-rename.golden @@ -1,7 +1,7 @@ == snap renamed grid=110x25 cursor=17,10 |Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol -| * /tmp/pardes-snap/lsp-rename/cwd/rename.zig Save Tty Collapse Del TreeContext +| * /tmp/pardes-snap/lsp-rename/cwd/rename.zig Save Tty Collapse Del TreeContext Def Refs | 1 const std = @import("std"); renamed 2 range(s) | 2 | 3 fn renamed_helper(x: u32) u32 { @@ -18,11 +18,11 @@ | 14 } | 15 == snap undone grid=110x25 cursor=17,10 -|2: /tmp/pardes-snap/lsp-rename/cwd/rename.zig Save Tty Collapse Del TreeContext +|2: /tmp/pardes-snap/lsp-rename/cwd/rename.zig Save Tty Collapse Del TreeContext Def Refs |3: 1 const std = @import("std"); |5: 3 fn helper(x: u32) u32 { |10: 8 _ = helper(41); == snap redone grid=110x25 cursor=17,10 -|2: * /tmp/pardes-snap/lsp-rename/cwd/rename.zig Save Tty Collapse Del TreeContext +|2: * /tmp/pardes-snap/lsp-rename/cwd/rename.zig Save Tty Collapse Del TreeContext Def Refs |5: 3 fn renamed_helper(x: u32) u32 { |10: 8 _ = renamed_helper(41); diff --git a/test/snapshots/lsp.golden b/test/snapshots/lsp.golden index 048d1ed3..2225de00 100644 --- a/test/snapshots/lsp.golden +++ b/test/snapshots/lsp.golden @@ -1,7 +1,7 @@ == snap opened grid=120x41 cursor=7,3 |Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/lsp/cwd/a.zig Save Tty Collapse Del TreeContext +| /tmp/pardes-snap/lsp/cwd/a.zig Save Tty Collapse Del TreeContext Def Refs | 1 const std = @import("std"); | 2 | 3 fn helper(x: u32) u32 { @@ -34,4 +34,4 @@ == snap step grid=120x41 cursor=15,3 |3: 1 const std = @import("std"); == snap nothing grid=120x41 cursor=7,5 -|3: 1 const std = @import("std"); definition: not found +|3: 1 const std = @import("std"); Def: not found diff --git a/test/snapshots/lspcomplete.golden b/test/snapshots/lspcomplete.golden index a56101e8..85c26e30 100644 --- a/test/snapshots/lspcomplete.golden +++ b/test/snapshots/lspcomplete.golden @@ -1,7 +1,7 @@ == snap opened grid=120x41 cursor=7,3 |Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/lspcomplete/cwd/a.zig Save Tty Collapse Del TreeContext +| /tmp/pardes-snap/lspcomplete/cwd/a.zig Save Tty Collapse Del TreeContext Def Refs | 1 const Shade = enum { | 2 verdigris, | 3 cinnabar, @@ -16,7 +16,7 @@ | 12 // note. see below | 13 == snap indent grid=120x41 cursor=11,12 -|2: ^* /tmp/pardes-snap/lspcomplete/cwd/a.zig Save Tty Collapse Del TreeContext +|2: ^* /tmp/pardes-snap/lspcomplete/cwd/a.zig Save Tty Collapse Del TreeContext Def Refs |12: 10 } == snap commentindent grid=120x41 cursor=19,14 |3: 1 const Shade = enum { --:--:-- lsp zls ready — /tmp/pardes-snap/lspcomplete/cwd @@ -31,7 +31,7 @@ |18: 3 == snap refill grid=120x41 cursor=16,10 == snap step grid=120x41 cursor=16,10 -|2: * /tmp/pardes-snap/lspcomplete/cwd/a.zig Save Tty Collapse Del TreeContext +|2: * /tmp/pardes-snap/lspcomplete/cwd/a.zig Save Tty Collapse Del TreeContext Def Refs == snap txtindent grid=120x41 cursor=15,3 |Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol @@ -41,7 +41,7 @@ == snap nosemi grid=100x19 cursor=29,9 |Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol -|^* /tmp/pardes-snap/lspcomplete/cwd/c.zig Save Tty Collapse Del TreeContext +|^* /tmp/pardes-snap/lspcomplete/cwd/c.zig Save Tty Collapse Del TreeContext Def Refs | 1 const Shade = enum { --:--:-- lsp zls ready — /tmp/pardes-snap/lspcomplete/cwd | 2 verdigris, | 3 cinnabar, @@ -57,7 +57,7 @@ == snap nobrace grid=100x19 cursor=16,10 |Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol -|^* /tmp/pardes-snap/lspcomplete/cwd/d.zig Save Tty Collapse Del TreeContext +|^* /tmp/pardes-snap/lspcomplete/cwd/d.zig Save Tty Collapse Del TreeContext Def Refs | 1 const Shade = enum { --:--:-- lsp zls ready — /tmp/pardes-snap/lspcomplete/cwd | 2 verdigris, | 3 cinnabar, diff --git a/test/snapshots/lspcompletemoved.golden b/test/snapshots/lspcompletemoved.golden index c83e3038..403c6931 100644 --- a/test/snapshots/lspcompletemoved.golden +++ b/test/snapshots/lspcompletemoved.golden @@ -1,7 +1,7 @@ == snap typedthrough grid=120x21 cursor=16,14 |Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol -|^* /tmp/pardes-snap/lspcompletemoved/cwd/a.zig Save Tty Collapse Del TreeContext +|^* /tmp/pardes-snap/lspcompletemoved/cwd/a.zig Save Tty Collapse Del TreeContext Def Refs | 1 const Shade = enum { --:--:-- lsp zls ready — /tmp/pardes-snap/lspcompletemoved/cwd | 2 verdigris, | 3 cinnabar, diff --git a/test/snapshots/lspdebug.golden b/test/snapshots/lspdebug.golden index 75fba98f..4beda019 100644 --- a/test/snapshots/lspdebug.golden +++ b/test/snapshots/lspdebug.golden @@ -1,7 +1,7 @@ == snap opened grid=120x45 cursor=7,3 |Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/lspdebug/cwd/z.zig Save Tty Collapse Del TreeContext +| /tmp/pardes-snap/lspdebug/cwd/z.zig Save Tty Collapse Del TreeContext Def Refs | 1 const std = @import("std"); | 2 | 3 fn helper() u32 { diff --git a/test/snapshots/lsprelpath.golden b/test/snapshots/lsprelpath.golden index b4022b1d..a3760316 100644 --- a/test/snapshots/lsprelpath.golden +++ b/test/snapshots/lsprelpath.golden @@ -1,7 +1,7 @@ == snap absrow grid=100x35 cursor=21,16 |Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/lsprelpath/cwd/sub/parent.zig Save Tty Collapse Del TreeContext +| /tmp/pardes-snap/lsprelpath/cwd/sub/parent.zig Save Tty Collapse Del TreeContext Def Refs | 1 const shade = @import("../shad --:--:-- lsp zls ready — /tmp/pardes-snap/lsprelpath/cwd/sub | 2 | 3 pub fn pick(s: shade.Shade) u8 { @@ -14,7 +14,7 @@ | 2 pub const Shade = enum { | 3 parent.zig:3:22-26 | 4 pub fn pick(s: shade.Shade) u8 { -| /tmp/pardes-snap/lsprelpath/cwd/shade.zig Save Tty Collapse Del TreeContext +| /tmp/pardes-snap/lsprelpath/cwd/shade.zig Save Tty Collapse Del TreeContext Def Refs | 1 pub const Shade = enum { | 2 verdigris, | 3 cinnabar, @@ -61,7 +61,7 @@ == snap subrow grid=100x35 cursor=20,16 |Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/lsprelpath/cwd/sub/subdir.zig Save Tty Collapse Del TreeContext +| /tmp/pardes-snap/lsprelpath/cwd/sub/subdir.zig Save Tty Collapse Del TreeContext Def Refs | 1 const tint = @import("inner/ti --:--:-- lsp zls ready — /tmp/pardes-snap/lsprelpath/cwd/sub | 2 | 3 pub fn hue(t: tint.Tint) u8 { @@ -74,7 +74,7 @@ | 2 pub const Tint = enum { | 3 subdir.zig:3:20-23 | 4 pub fn hue(t: tint.Tint) u8 { -| /tmp/pardes-snap/lsprelpath/cwd/sub/inner/tint.zig Save Tty Collapse Del TreeContext +| /tmp/pardes-snap/lsprelpath/cwd/sub/inner/tint.zig Save Tty Collapse Del TreeContext Def Refs | 1 pub const Tint = enum { | 2 ochre, | 3 indigo, diff --git a/test/snapshots/ninep.golden b/test/snapshots/ninep.golden index c6b5f0af..e524fa30 100644 --- a/test/snapshots/ninep.golden +++ b/test/snapshots/ninep.golden @@ -1,7 +1,7 @@ == snap opened grid=90x15 cursor=7,3 |Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/ninep/cwd/demo.zig Save Tty Collapse Del TreeContext +| /tmp/pardes-snap/ninep/cwd/demo.zig Save Tty Collapse Del TreeContext Def Refs | 1 const greeting = "café λ 界 é"; | 2 | 3 pub fn choose(ok: bool) u32 { @@ -30,8 +30,8 @@ @0: 0-74 #b2c3b8,#1d2824,,tagline 75-89 d,#1d2824,,tagline |1: New Tty Find Grep Joincol Delcol @1: 0-1 #ffffff,#887455,,tagline 2-2 d,#314738,,tagline 3-34 #becfc4,#314738,,tagline 35-89 d,#314738,,tagline -|2: /tmp/pardes-snap/ninep/cwd/demo.zig Save Tty Collapse Del TreeContext -@2: 0-1 #000000,#add38a,,tagline 2-2 d,#314738,,tagline 3-29 #becfc4,#314738,,tagline 30-37 #dfbce5,#314738,,tagline 38-71 #becfc4,#314738,,tagline 72-89 d,#314738,,tagline +|2: /tmp/pardes-snap/ninep/cwd/demo.zig Save Tty Collapse Del TreeContext Def Refs +@2: 0-1 #000000,#add38a,,tagline 2-2 d,#314738,,tagline 3-29 #becfc4,#314738,,tagline 30-37 #dfbce5,#314738,,tagline 38-80 #becfc4,#314738,,tagline 81-89 d,#314738,,tagline |3: 1 const greeting = "café λ 界 é"; +3: 28="é" 30="λ" 32="界" 33="" 35="é" @3: 0-0 d,#608269,,body 1-1 d,#0d1410,,body 2-6 #616f64,#0d1410,b,body 7-23 #e5eee5,#0d1410,,body 24-36 #b8d88a,#0d1410,,body 37-37 #e5eee5,#0d1410,,body 38-89 d,#0d1410,,body @@ -73,7 +73,7 @@ |7: 5 return 7; @7: 0-0 d,#608269,,body 1-1 d,#0d1410,,body 2-6 #59675c,#0d1410,,body 7-19 #e5eee5,#0d1410,,body 20-89 d,#0d1410,,body == snap edited-with-colors-off grid=90x15 cursor=7,4 -|2: * /tmp/pardes-snap/ninep/cwd/demo.zig Save Tty Collapse Del TreeContext +|2: * /tmp/pardes-snap/ninep/cwd/demo.zig Save Tty Collapse Del TreeContext Def Refs |3: 1 // café λ 界 |4: 2 const greeting = "café λ 界 é"; |5: 3 @@ -83,8 +83,8 @@ |9: 7 } |10: 8 == 9p edited-with-colors-off grid=90x15 cursor=7,4,block -|2: * /tmp/pardes-snap/ninep/cwd/demo.zig Save Tty Collapse Del TreeContext -@2: 0-0 #000000,#add38a,,tagline 1-1 #000000,#f9cb70,b,tagline 2-2 d,#314738,,tagline 3-29 #becfc4,#314738,,tagline 30-37 #dfbce5,#314738,,tagline 38-71 #becfc4,#314738,,tagline 72-89 d,#314738,,tagline +|2: * /tmp/pardes-snap/ninep/cwd/demo.zig Save Tty Collapse Del TreeContext Def Refs +@2: 0-0 #000000,#add38a,,tagline 1-1 #000000,#f9cb70,b,tagline 2-2 d,#314738,,tagline 3-29 #becfc4,#314738,,tagline 30-37 #dfbce5,#314738,,tagline 38-80 #becfc4,#314738,,tagline 81-89 d,#314738,,tagline |3: 1 // café λ 界 +3: 13="é" 15="λ" 17="界" 18="" @3: 0-0 d,#608269,,body 1-1 d,#0d1410,,body 2-6 #59675c,#0d1410,,body 7-18 #e5eee5,#0d1410,,body 19-89 d,#0d1410,,body @@ -152,8 +152,8 @@ @0: 0-74 #b2c3b8,#1d2824,,tagline 75-104 d,#1d2824,,tagline |1: New Tty Find Grep Joincol Delcol @1: 0-1 #ffffff,#887455,,tagline 2-2 d,#314738,,tagline 3-34 #becfc4,#314738,,tagline 35-104 d,#314738,,tagline -|2: * /tmp/pardes-snap/ninep/cwd/demo.zig Save Tty Collapse Del TreeContext -@2: 0-0 #000000,#add38a,,tagline 1-1 #000000,#f9cb70,b,tagline 2-2 d,#314738,,tagline 3-29 #becfc4,#314738,,tagline 30-37 #dfbce5,#314738,,tagline 38-71 #becfc4,#314738,,tagline 72-104 d,#314738,,tagline +|2: * /tmp/pardes-snap/ninep/cwd/demo.zig Save Tty Collapse Del TreeContext Def Refs +@2: 0-0 #000000,#add38a,,tagline 1-1 #000000,#f9cb70,b,tagline 2-2 d,#314738,,tagline 3-29 #becfc4,#314738,,tagline 30-37 #dfbce5,#314738,,tagline 38-80 #becfc4,#314738,,tagline 81-104 d,#314738,,tagline |3: 1 // café λ 界 Colors +3: 13="é" 15="λ" 17="界" 18="" @3: 0-0 d,#608269,,body 1-1 d,#0d1410,,body 2-6 #59675c,#0d1410,,body 7-18 #b9f480,#0d1410,,body 19-96 d,#0d1410,,body 97-97 d,#1d2824,,tagline 98-103 #b2c3b8,#1d2824,,tagline 104-104 d,#1d2824,,tagline @@ -193,7 +193,7 @@ == snap resized grid=105x20 cursor=7,4 |Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol -| * /tmp/pardes-snap/ninep/cwd/demo.zig Save Tty Collapse Del TreeContext +| * /tmp/pardes-snap/ninep/cwd/demo.zig Save Tty Collapse Del TreeContext Def Refs | 1 // café λ 界 Colors | 2 const greeting = "café λ 界 é"; | 3 diff --git a/test/snapshots/pagercolor.golden b/test/snapshots/pagercolor.golden index 811d3d96..abd264d1 100644 --- a/test/snapshots/pagercolor.golden +++ b/test/snapshots/pagercolor.golden @@ -41,9 +41,8 @@ | | | -| /tmp/pardes-snap/pagercolor/cwd/+Pager Save Tty Collapse Del -| 1 red bold green rgb ul NAME us plain -| 2 +| /tmp/pardes-snap/pagercolor/cwd/+Pager Save Tty Filter Collapse Del +| red bold green rgb ul NAME us plain == style pager-colours grid=100x50 |0: 0-99 #b2c3b8,#1d2824, |1: 0-1 d,#887455, 2-2 d,#314738, 3-99 #becfc4,#314738, @@ -88,8 +87,8 @@ |40: 0-0 d,#608269, 1-99 d,#0d1410, |41: 0-0 d,#608269, 1-99 d,#0d1410, |42: 0-1 d,#496656, 2-2 d,#1d2824, 3-34 #b2c3b8,#1d2824, 35-41 #d3b0d9,#1d2824, 42-99 #b2c3b8,#1d2824, -|43: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #f1a39b,#0d1410, 11-20 #b6ce94,#0d1410,b 21-21 #b6ce94,#0d1410, 22-25 #c86400,#0d1410, 26-27 #e5eee5,#0d1410,u 28-28 #e5eee5,#0d1410, 29-32 #e5eee5,#0d1410,b 33-33 #e5eee5,#0d1410, 34-35 #e5eee5,#0d1410,u 36-99 #e5eee5,#0d1410, -|44: 0-0 d,#608269, 1-4 d,#0d1410, 5-99 #59675c,#0d1410, +|43: 0-0 d,#608269, 1-1 d,#0d1410, 2-5 #f1a39b,#0d1410, 6-15 #b6ce94,#0d1410,b 16-16 #b6ce94,#0d1410, 17-20 #c5917e,#0d1410, 21-22 #e5eee5,#0d1410,u 23-23 #e5eee5,#0d1410, 24-27 #e5eee5,#0d1410,b 28-28 #e5eee5,#0d1410, 29-30 #e5eee5,#0d1410,u 31-99 #e5eee5,#0d1410, +|44: 0-0 d,#608269, 1-99 d,#0d1410, |45: 0-0 d,#608269, 1-99 d,#0d1410, |46: 0-0 d,#608269, 1-99 d,#0d1410, |47: 0-0 d,#608269, 1-99 d,#0d1410, @@ -100,21 +99,19 @@ |6: 3[m\n\033[1m+++ b/x\033[m\n\033[36m@@ -1 +1 @@\033[m\n\033[31m-old\033[m\n\033[32m+new\033[m\n' | |7: $(readlink /proc/$PPID/exe) - |8: $ -|43: 1 commit 0123abc -|44: 2 diff --git a/x b/x -|45: 3 --- a/x -|46: 4 +++ b/x -|47: 5 @@ -1 +1 @@ -|48: 6 -old -|49: 7 +new +|9: /tmp/pardes-snap/pagercolor/cwd/+Diff Save Tty Diff Collapse Del LocationsConfig +|10: commit 0123abc +|11: x:1 +|12: -old +|13: +new +|49: /tmp/pardes-snap/pagercolor/cwd/+Pager Save Tty Filter Diff Collapse Del == style pager-diff-colours grid=100x50 |6: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410, |7: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410, |8: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410, -|43: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-99 #e9c680,#0d1410, -|44: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-24 #b9f480,#0d1410,b 25-99 #b9f480,#0d1410, -|45: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-13 #b9f480,#0d1410,b 14-99 #b9f480,#0d1410, -|46: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-13 #b9f480,#0d1410,b 14-99 #b9f480,#0d1410, -|47: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-99 #b6c59e,#0d1410, -|48: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-7 #f1a39b,#302b25,b 8-99 #f8c082,#302b25, -|49: 0-0 d,#152019, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-7 #b6ce94,#263025,b 8-99 #b8d88a,#263025, +|9: 0-1 d,#496656, 2-2 d,#1d2824, 3-34 #b2c3b8,#1d2824, 35-40 #d3b0d9,#1d2824, 41-99 #b2c3b8,#1d2824, +|10: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410, +|11: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #59675c,#0d1410, +|12: 0-0 d,#608269, 1-1 d,#0d1410, 2-2 #f1a39b,#1a1d18,b 3-99 #f8c082,#1a1d18, +|13: 0-0 d,#608269, 1-1 d,#0d1410, 2-2 #b6ce94,#171f18,b 3-99 #b8d88a,#171f18, +|49: 0-1 d,#496656, 2-2 d,#1d2824, 3-34 #b2c3b8,#1d2824, 35-41 #d3b0d9,#1d2824, 42-99 #b2c3b8,#1d2824, diff --git a/test/snapshots/selregex.golden b/test/snapshots/selregex.golden index e3f3b2d7..480ad8a2 100644 --- a/test/snapshots/selregex.golden +++ b/test/snapshots/selregex.golden @@ -1,7 +1,7 @@ == snap prompt-armed grid=160x25 cursor=159,3 |Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol -| /tmp/pardes-snap/selregex/cwd/m.zig Save Tty Collapse Del TreeContext +| /tmp/pardes-snap/selregex/cwd/m.zig Save Tty Collapse Del TreeContext Def Refs | 1 const one = 1; Select / | 2 const two = 2; | 3 const three = 3; @@ -51,12 +51,12 @@ |4: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #f5f7ee,#243a2d, 11-11 #3c614a,#f5f7ee, 12-12 #3c614a,#0d1410, 13-18 #e5eee5,#0d1410, 19-19 #f8c082,#0d1410, 20-159 #e5eee5,#0d1410, |5: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #f5f7ee,#243a2d, 11-11 #3c614a,#f5f7ee, 12-12 #3c614a,#0d1410, 13-20 #e5eee5,#0d1410, 21-21 #f8c082,#0d1410, 22-159 #e5eee5,#0d1410, == snap commented grid=160x25 cursor=14,3 -|2: * /tmp/pardes-snap/selregex/cwd/m.zig Save Tty Collapse Del TreeContext +|2: * /tmp/pardes-snap/selregex/cwd/m.zig Save Tty Collapse Del TreeContext Def Refs |3: 1 // const one = 1; |4: 2 // const two = 2; |5: 3 // const three = 3; == snap uncommented grid=160x25 cursor=11,3 -|2: /tmp/pardes-snap/selregex/cwd/m.zig Save Tty Collapse Del TreeContext +|2: /tmp/pardes-snap/selregex/cwd/m.zig Save Tty Collapse Del TreeContext Def Refs |3: 1 const one = 1; |4: 2 const two = 2; |5: 3 const three = 3; diff --git a/test/snapshots/syntax.golden b/test/snapshots/syntax.golden index 2f7a6b74..43bfe485 100644 --- a/test/snapshots/syntax.golden +++ b/test/snapshots/syntax.golden @@ -1,11 +1,12 @@ -== snap zig-open grid=150x31 cursor=7,7 +== snap zig-open grid=150x31 cursor=7,8 |Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit | New Tty Find Grep Joincol Delcol New Tty Find Grep Joincol Delcol | /tmp/pardes-snap/syntax/cwd Tty+bash Save Mode Filter Collapse Del /tmp/pardes-snap/syntax/cwd Tty+bash Save Mode Filter Collapse Del | ls ls | demo.zig demo.zig | -| /tmp/pardes-snap/syntax/cwd/demo.zig Save Tty Collapse Del TreeContext +| /tmp/pardes-snap/syntax/cwd/demo.zig Save Tty Collapse Del TreeContext D +| ef Refs | 1 const std = @import("std"); // greet | 2 pub fn main() void { | 3 var x: u32 = 42; @@ -15,7 +16,6 @@ | | | -| | /tmp/pardes-snap/syntax/cwd Tty+bash Save Mode Filter Collapse Del | ls | demo.zig @@ -27,12 +27,12 @@ |4: 0-0 d,#608269, 1-1 d,#0d1410, 2-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, |5: 0-0 d,#608269, 1-74 d,#0d1410, 75-75 d,#608269, 76-149 d,#0d1410, |6: 0-1 d,#add38a, 2-2 d,#314738, 3-30 #becfc4,#314738, 31-39 #dfbce5,#314738, 40-74 #becfc4,#314738, 75-75 #becfc4,#608269, 76-149 #becfc4,#0d1410, -|7: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-18 #e5eee5,#0d1410, 19-25 #c9a7ed,#0d1410, 26-26 #e5eee5,#0d1410, 27-31 #b8d88a,#0d1410, 32-34 #e5eee5,#0d1410, 35-74 #b9f480,#0d1410, 75-75 #b9f480,#608269, 76-149 #b9f480,#0d1410, -|8: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #e5eee5,#0d1410, 11-13 #c9a7ed,#0d1410, 14-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, -|9: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-23 #e5eee5,#0d1410, 24-25 #f8c082,#0d1410, 26-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, -|10: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, -|11: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, -|12: 0-0 d,#608269, 1-74 d,#0d1410, 75-75 d,#608269, 76-149 d,#0d1410, +|7: 0-2 d,#314738, 3-74 #becfc4,#314738, 75-75 #becfc4,#608269, 76-149 #becfc4,#0d1410, +|8: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-18 #e5eee5,#0d1410, 19-25 #c9a7ed,#0d1410, 26-26 #e5eee5,#0d1410, 27-31 #b8d88a,#0d1410, 32-34 #e5eee5,#0d1410, 35-74 #b9f480,#0d1410, 75-75 #b9f480,#608269, 76-149 #b9f480,#0d1410, +|9: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #e5eee5,#0d1410, 11-13 #c9a7ed,#0d1410, 14-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, +|10: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-23 #e5eee5,#0d1410, 24-25 #f8c082,#0d1410, 26-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, +|11: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, +|12: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, |13: 0-0 d,#608269, 1-74 d,#0d1410, 75-75 d,#608269, 76-149 d,#0d1410, |14: 0-0 d,#608269, 1-74 d,#0d1410, 75-75 d,#608269, 76-149 d,#0d1410, |15: 0-0 d,#608269, 1-74 d,#0d1410, 75-75 d,#608269, 76-149 d,#0d1410, @@ -52,10 +52,10 @@ |29: 0-0 d,#608269, 1-74 d,#0d1410, 75-75 d,#608269, 76-149 d,#0d1410, |30: 0-0 d,#608269, 1-74 d,#0d1410, 75-75 d,#608269, 76-149 d,#0d1410, == style colors-off grid=150x31 -|7: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-66 #e5eee5,#0d1410, 67-67 #e5eee5,#1d2824, 68-74 #b2c3b8,#1d2824, 75-75 #b2c3b8,#608269, 76-149 #b2c3b8,#0d1410, -|8: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, -|9: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, +|8: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-66 #e5eee5,#0d1410, 67-67 #e5eee5,#1d2824, 68-74 #b2c3b8,#1d2824, 75-75 #b2c3b8,#608269, 76-149 #b2c3b8,#0d1410, +|9: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, +|10: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, == style colors-on grid=150x31 -|7: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-18 #e5eee5,#0d1410, 19-25 #c9a7ed,#0d1410, 26-26 #e5eee5,#0d1410, 27-31 #b8d88a,#0d1410, 32-34 #e5eee5,#0d1410, 35-66 #b9f480,#0d1410, 67-67 #b9f480,#1d2824, 68-74 #b2c3b8,#1d2824, 75-75 #b2c3b8,#608269, 76-149 #b2c3b8,#0d1410, -|8: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #e5eee5,#0d1410, 11-13 #c9a7ed,#0d1410, 14-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, -|9: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-23 #e5eee5,#0d1410, 24-25 #f8c082,#0d1410, 26-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, +|8: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-18 #e5eee5,#0d1410, 19-25 #c9a7ed,#0d1410, 26-26 #e5eee5,#0d1410, 27-31 #b8d88a,#0d1410, 32-34 #e5eee5,#0d1410, 35-66 #b9f480,#0d1410, 67-67 #b9f480,#1d2824, 68-74 #b2c3b8,#1d2824, 75-75 #b2c3b8,#608269, 76-149 #b2c3b8,#0d1410, +|9: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #e5eee5,#0d1410, 11-13 #c9a7ed,#0d1410, 14-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, +|10: 0-0 d,#608269, 1-4 d,#0d1410, 5-10 #59675c,#0d1410, 11-23 #e5eee5,#0d1410, 24-25 #f8c082,#0d1410, 26-74 #e5eee5,#0d1410, 75-75 #e5eee5,#608269, 76-149 #e5eee5,#0d1410, |
