Help us shape the future of Go! Take the 2026 Go Developer Survey

editor

package
v0.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

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

View Source
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

View Source
var ErrNoSuchFile = errors.New("no such file")

ErrNoSuchFile reports a place to open that names no file.

Functions

func Collect

func Collect(path string, done func(string, error) tea.Msg) func(error) tea.Msg

Collect is what happens once the editor closes: the draft at path is read back, parsed, reported through done, and removed.

func Draft

func Draft(text, help string) string

Draft is what the editor opens: the text, then the scissors line and help that will be thrown away.

func Edit

func Edit(getenv Getenv, dir, text, help string, done func(string, error) tea.Msg) tea.Cmd

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

func Invocation(getenv Getenv, dir, file string, line int) proc.Command

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

func Locate(dir, file string) (string, error)

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

func Open(getenv Getenv, dir, file string, line int, done func(error) tea.Msg) tea.Cmd

Open opens a file in the user's editor at a line, and reports through done once the editor has closed.

func Parse

func Parse(raw string) string

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

func Resolve(dir string, tree fs.FS, places []string) map[string]string

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.

Types

type Getenv

type Getenv func(string) string

Getenv reads an environment variable. os.Getenv satisfies it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL