Documentation
¶
Overview ¶
Package editor hands text and files to the user's own editor.
Most multi-line things workflow asks for — a commit body, a pull request description, an announcement — are written in $EDITOR rather than in a text box drawn inside the interface: people already have an editor they are fast in, and a text box would be a worse one. A comment is the exception: it is written in the comment box, with vim's normal and insert modes, and handed here only when asked (TRADE-30).
Index ¶
- Constants
- Variables
- func Collect(path string, done func(string, error) tea.Msg) func(error) tea.Msg
- func Draft(text, help string) string
- func Edit(getenv Getenv, dir, text, help string, done func(string, error) tea.Msg) tea.Cmd
- func Invocation(getenv Getenv, dir, file string, line int) proc.Command
- func Locate(dir, file string) (string, error)
- func Open(getenv Getenv, dir, file string, line int, done func(error) tea.Msg) tea.Cmd
- func Parse(raw string) string
- func Resolve(dir string, tree fs.FS, places []string) map[string]string
- type Getenv
Constants ¶
const Scissors = "# ------------------------ >8 ------------------------"
Scissors marks where a draft's text ends and its help begins. Everything from this line down is thrown away when the draft comes back. It is git's own scissors line, and it is a line rather than a # comment prefix because the text is often Markdown, whose headings start with #.
Variables ¶
var ErrNoSuchFile = errors.New("no such file")
ErrNoSuchFile reports a place to open that names no file.
Functions ¶
func Collect ¶
Collect is what happens once the editor closes: the draft at path is read back, parsed, reported through done, and removed.
func Draft ¶
Draft is what the editor opens: the text, then the scissors line and help that will be thrown away.
func Edit ¶
Edit hands text to the user's editor and reports what they saved, through done. The interface releases the terminal while the editor has it. The draft is written to $TMPDIR, or the system's temporary directory, never into the repository, where it would show up as an untracked file.
func Invocation ¶
Invocation is how to open a file in the user's editor, at a line when the editor can be told one and line is positive.
The editor setting is split into words here rather than run through a shell: "code --wait" is common and works, while shell syntax in $EDITOR is rare and is not something to hand to sh on the user's behalf.
func Locate ¶
Locate names a file in full: from dir, unless it is a full path already.
A place comes from what a tool printed, so it may name nothing (go test prints places relative to a package, not to the repository) and it may begin with anything a file name can. An editor handed a file that is not there opens an empty buffer, and saving that leaves a stray file; and an editor reads an argument by how it begins. Named in full, a file is there, and its name begins with the root.
func Open ¶
Open opens a file in the user's editor at a line, and reports through done once the editor has closed.
func Parse ¶
Parse is what the user wrote: everything above the first line that is the scissors line, with the trailing space editors leave behind removed. As in git, the scissors count only as a whole line, so a body quoting them keeps that line.
func Resolve ¶ added in v0.0.6
Resolve turns the places a tool printed into files Open can find, each keyed by the place as printed; a place missing from the result names no file. A place that is there as printed is kept unchanged. The rest — go test prints a place relative to its package, not the root — are looked for in tree, the files below dir, in one walk however many there are, and each is kept only when exactly one file matches, so an ambiguous name resolves to nothing rather than to the wrong file.