Documentation
¶
Overview ¶
Package editor renders and parses the header+body buffer format used by `brag edit` (and, eventually, `brag add` no-args). The format is pinned by DEC-009: RFC822-style headers parseable via net/textproto.Reader.ReadMIMEHeader, followed by a blank line, followed by a free-form markdown body (the entry's Description).
editor does NOT import internal/storage: Fields mirrors the user-editable subset of storage.Entry, and the CLI layer translates between the two. This keeps the format concern independent and avoids a dependency cycle risk.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EmptyTemplate ¶
func EmptyTemplate() []byte
EmptyTemplate returns a buffer shaped per DEC-009 with all five editable headers pre-listed but empty. Distinct from Render(Fields{}), which omits empty-valued headers — the template is a UX hint shown to users in editor-launch mode (e.g. `brag add` with no flags), not a renderer output.
func Launch ¶
Launch writes initial to a temp .md file, invokes edit on it, and returns the resulting bytes plus whether the content actually changed (SHA-256 of the raw bytes — stricter than semantic-equal but simpler). The temp file is removed on return.
func Render ¶
Render produces the editable buffer for f. Headers are emitted in a fixed canonical order (Title, Tags, Project, Type, Impact); empty- valued fields are omitted entirely. Description is written verbatim after a blank-line separator, with a trailing newline appended when not already present so the file plays nicely with editors that complain about missing final newlines.
Types ¶
type EditFunc ¶
EditFunc opens the file at path in an editor and returns once the user has saved (or aborted). The production implementation is Default; tests inject fakes so no real editor is spawned.
var Default EditFunc = func(path string) error { argv := append(resolveEditor(), path) c := exec.Command(argv[0], argv[1:]...) c.Stdin = os.Stdin c.Stdout = os.Stdout c.Stderr = os.Stderr if err := c.Run(); err != nil { return fmt.Errorf("editor exited: %w", err) } return nil }
Default resolves $EDITOR → $VISUAL → vi and execs it against the given path, wired to the current stdio so interactive editors work.
type Fields ¶
type Fields struct {
Title string
Description string
Tags string
Project string
Type string
Impact string
}
Fields is the user-editable subset of a brag entry. ID, CreatedAt, and UpdatedAt are intentionally absent — they're managed by the storage layer and never round-tripped through the editor buffer.