turbo-editors/turbo-gopublic Fork 0
v1.0.0
Commits
Clone
git clone https://git.rickub.com/turbo-editors/turbo-go.git
git clone ssh://git@rickub.com/turbo-editors/turbo-go.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

go-tools.md · 236 lines · 10.2 KBmarkdown Blame HistoryRaw
📦 Turbo Go 3d7798b k33g 10h ago1# Reference: go tools
2
3> Neutral description of `.turbo-go/tools.toml`, the Go menu, and what running a command does.
4
5## File
6
7| Property | Value |
8| --- | --- |
9| Path | `./.turbo-go/tools.toml` |
10| Search | The working directory only. Parent directories are **not** searched. |
11| Read | Every time one of its menus opens, for the items |
12| Re-read | Whenever the file's size or modification time changes, for the **set** of menus |
13| Missing file | Not an error |
14| Unreadable file | An error, shown in the menu |
15| User-level file | **None.** Unlike snippets, there is no `~/.config/turbo-go/tools.toml`. |
16
17## File format
18
19One `[[tool]]` table per command.
20
21| Key | Type | Required | Description |
22| --- | --- | --- | --- |
23| `name` | string | yes | What the menu shows. May carry a hot key written with tildes, as in `"~T~est"`. |
24| `command` | string | yes | The shell command to run |
25| `output` | string | no | Where its output goes: `popup`, `terminal` or `editor`. Absent means `popup`. |
26| `menu` | string | no | Which menu it appears in. Absent means `Go`. Any name; the menu is created for you. May carry a hot key written with tildes. |
27
28`menu` is not checked against a list, because there is no list: a name that no other tool uses simply creates a menu. A tool with no `name`, no `command`, or an `output` naming something that does not exist makes the whole file an error. An unknown `output` is **refused rather than corrected**: `"termnial"` would otherwise look as though it had worked while sending the output somewhere else.
29
30### Example
31
32```toml
33[[tool]]
34name = "~T~est"
35command = "go test ./..."
36output = "popup"
37
38[[tool]]
39name = "~E~cho"
40command = "echo TADA"
41output = "terminal"
42menu = "Tools"
43```
44
45## The starter file
46
47**Go ▸ Create tools file** writes these five, in this order:
48
49| Name | Command | Output |
50| --- | --- | --- |
51| Format | `gofmt -l -w .` | `popup` |
52| Lint | `go vet ./...` | `popup` |
53| Build | `go build ./...` | `popup` |
54| Test | `go test ./...` | `popup` |
55| Run | `go run .` | `terminal` |
56
57None of them names a `menu`, so all five are in the Go menu. Every one names its `output`, including the four that name the default: the key is the interesting part of the format, and a file where it appears once is a file where nobody notices it exists.
58
59The item is greyed out once the project has a tools file, so it cannot overwrite one. The file is written through a temporary file in the same directory, renamed into place.
60
61## The Go menu
62
63Always on the bar, whether or not a tools file exists. Its hot key is `Alt-G`.
64
65| Item | Condition |
66| --- | --- |
67| One line per tool with no `menu`, in file order | The file holds at least one |
68| `Cannot read tools`, greyed out | The file is present but unreadable |
69| `Create tools file` | The project has no tools file |
70| `Open tools file` | The project has one |
71
72## Menus a tool asks for
73
74A `menu` naming anything other than `Go` puts a menu of that name on the bar.
75
76| Property | Value |
77| --- | --- |
78| Position | Between Go and Help |
79| Order | The order each name first appears in the file |
80| Items | One line per tool naming that menu, in file order. Nothing else — `Create tools file` and `Open tools file` stay in Go. |
81| Unreadable file | No menus at all; the Go menu carries the error |
82| While the editor runs | Added, removed and renamed as the file changes, without restarting |
83
84### Hot keys
85
86Assigned automatically, because a name from a file cannot be checked against the fixed menus in advance.
87
88| Case | Result |
89| --- | --- |
90| No tildes in the name | The first letter no other menu has claimed is marked. `Format` becomes `For~m~at`: `F` is File's, `o` is Options', `r` is Run's. |
91| Tildes naming a free letter | Kept as written. `Doc~k~er` answers to `Alt-K`. |
92| Tildes naming a taken letter | Dropped, and a free letter chosen instead. `~F~oo` becomes `F~o~o`. |
93| Every letter taken | No hot key. `F10` and the mouse still open it. |
94
95The letters the editor's own menus hold are `F`, `E`, `S`, `R`, `O`, `W`, `N` (Snippets), `G` and `H`.
96
97## Running a command
98
99Common to every output:
100
101| Property | Value |
102| --- | --- |
103| Shell | `/bin/sh -c "<command>"` on Linux and macOS; `cmd.exe /S /C "<command>"` — the shell `%COMSPEC%` names — on Windows |
104| Directory | The directory the editor was started in |
105| Standard error | Merged into standard output, in the order the command wrote them |
106
107Going through a shell means pipes, globs, `&&` and `;` all work, so one tool can be a sequence. On Windows the shell is cmd.exe, which knows `&&`, `|` and `>` but does not expand globs, and where `;` is not a separator.
108
109### `output = "popup"`
110
111| Property | Value |
112| --- | --- |
113| Opens | Immediately, before the command has finished |
114| Modal | Yes: nothing else in the editor can be used while it is up |
115| Fills in | As output arrives, following it until you scroll back |
116| Title while running | `<command> — running` |
117| Title when finished | `<command> — ok`, or `<command> — exit <n>` |
118| Empty output, finished | Shows `(no output)` |
119| Empty output, running | Shows nothing |
120| Output cap | 10000 lines; past it the oldest go and a `… n earlier lines dropped …` line says so |
121
122| Key | Effect |
123| --- | --- |
124| `↑` `↓` `PgUp` `PgDn` `Home` `End` | Read through the output |
125| Wheel | The same |
126| `Escape`, `Enter`, **Close** | Close it, **stopping the command** if it is still running |
127
128Closing stops the command because there is no other way to interrupt one whose output is not in a terminal.
129
130### `output = "terminal"`
131
132| Property | Value |
133| --- | --- |
134| Window | A terminal window of its own, titled with the command |
135| Environment | The editor's own, with `TERM` set to `xterm-256color` |
136| After it exits | The window stays, showing its output |
137| Modal | No: the editor carries on beside it |
138
139Because it is a real terminal, colours, paging, `Ctrl-C` and reading from the keyboard all work. See [Terminal windows](terminal.md).
140
141Keys in a **finished** terminal window:
142
143| Key | Effect |
144| --- | --- |
145| `Shift-PgUp`, `Shift-PgDn` | Read back through the output |
146| `Ctrl-W` | Close the window |
147| Anything else | Reaches the editor, not the dead shell |
148
149### `output = "editor"`
150
151| Property | Value |
152| --- | --- |
153| Shows | A popup while it runs, as above |
154| On closing the popup | An editing window holding the output, titled with the command |
155| Filled | Once, when the command has finished — not as it goes |
156| The window | An ordinary editing window with no file name: searchable with `Ctrl-F`, and `Save as` keeps it |
157
158## Reloading after a command
159
160When a command finishes, every open file is considered.
161
162| The file | What happens |
163| --- | --- |
164| Unmodified, and changed on disk | Re-read; its syntax is re-decided and its title refreshed |
165| Unmodified, and unchanged on disk | Left alone, not counted |
166| Has unsaved changes | Left alone and counted as skipped |
167| Has never been named | Left alone |
168| Has gone from disk | Left alone |
169
170The cursor stays where it was, clamped into whatever the file now holds. The undo history is discarded, because undoing back past a reload would restore text the file no longer has.
171
172The project tree is refreshed at the same moment.
173
174| Status bar | When |
175| --- | --- |
176| `Running <command>` | The window opens |
177| `Reloaded 2 files` | Two files were re-read, none skipped |
178| `Reloaded 2 files; 1 file with unsaved changes left alone` | Some were skipped |
179| `Command finished; 1 file with unsaved changes left alone` | Nothing was re-read, something was skipped |
180
181## Errors
182
183| Message | Cause |
184| --- | --- |
185| `Cannot read tools` in the menu | The file is present but not valid TOML, or holds a tool with no name or no command |
186| `Already there: .turbo-go/tools.toml` | Creating in a project that already has one. Unreachable from the menu, which greys the item out; still possible for a caller that is not a menu. |
187| `This project has no .turbo-go/tools.toml yet.` | Opening in a project that has none, likewise |
188| `Cannot tell which directory this is: …` | The working directory could not be read |
189| `Terminal windows are not supported on this platform yet` | Running a command in a terminal needs a pseudo-terminal, which Linux, macOS and Windows have; see [Terminal windows](terminal.md) |
190
191## Asking for a value
192
193A `{{label}}` anywhere in a command is a value the editor asks for before it runs, in a box titled after the tool. The text between the braces is what the box asks for.
194
195| Written | Asked for | Substituted |
196| --- | --- | --- |
197| `{{module path}}` | `module path` | shell-quoted |
198| `{{extra flags...}}` | `extra flags` | verbatim |
199
200A value is **shell-quoted** by default, so a path with a space in it stays one argument. A trailing `...` inside the braces asks for it verbatim instead, which is how one field can stand for several arguments.
201
202```toml
203[[tool]]
204name = "~I~nit module"
205command = "go mod init {{module path}}"
206output = "popup"
207```
208
209| Rule | Behaviour |
210| --- | --- |
211| Several placeholders | One box, one field each, in the order they appear in the command |
212| The same label twice | One field; every occurrence gets what is typed into it |
213| A label written both ways | Asked for once; each occurrence honours its own braces |
214| Escape, or Cancel | The command does not run |
215| A field left empty | Substituted as empty — the command reports its own complaint |
216| Running the tool again | The box starts from what was typed last time, for this session only |
217| More fields than fit on screen | Refused, with a message saying how many fit |
218
219**Double braces, not single.** `awk '{print $1}'` and `find . -exec rm {} +` are ordinary commands, and a single-brace syntax would read the first as a request for a value called `print $1`.
220
221Nothing is written to disk. A value somebody typed this afternoon is not a decision the project made, so it does not go in the project's own directory.
222
223### Errors
224
225| Error | Cause |
226| --- | --- |
227| `tool "X": "{{module" is never closed` | An opening `{{` with no `}}` after it |
228| `tool "X": {{}} asks for a value but does not say what it is` | A placeholder with no label, or one that is only `...` |
229
230Both are refused when the file is read, so a half-typed placeholder never reaches the shell with its braces still in it.
231
232## See also
233
234- [How to run go commands from the editor](../how-to/run-go-commands.md)
235- [Go tools](../explanation/go-tools.md)
236- [Terminal windows](terminal.md)