editor

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package editor launches the user's external editor to compose review comments. Editor variables routinely carry arguments (e.g. "nvim -f", "code --wait"), so the command line is parsed into a program plus arguments rather than handed to a shell. The actual process launch is performed by the caller (the TUI uses tea.ExecProcess so the alternate screen is released and restored correctly); this package builds the *exec.Cmd and manages the temp file and template stripping.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildTemplate

func BuildTemplate(ctx TemplateContext, body string) string

BuildTemplate renders the initial editor buffer: an HTML-comment header with context, followed by any prior body. The header is stripped after editing, so the reviewer never has to delete it manually.

func CleanTemplate

func CleanTemplate(s string) string

CleanTemplate removes HTML comment blocks and trims surrounding whitespace, yielding the reviewer's note.

func Edit

func Edit(ctx context.Context, e Editor, initial, name string) (string, error)

Edit is a convenience blocking helper for non-TUI callers: it opens the editor, waits, and returns the cleaned result.

func SplitCommand

func SplitCommand(s string) []string

SplitCommand tokenises a command line with minimal shell semantics: it respects single and double quotes and backslash escapes, splitting on unquoted whitespace. It intentionally does not expand variables or globs.

Types

type Editor

type Editor struct {
	Command string
	Args    []string
}

Editor is a resolved editor invocation: a program and any fixed arguments that precede the file path.

func Resolve

func Resolve(configured string) (Editor, error)

Resolve picks an editor using the precedence:

configured (review.editor) → GIT_EDITOR → VISUAL → EDITOR →
`git var GIT_EDITOR` → platform fallback (vi / notepad).

The first non-empty source wins. The chosen value is parsed as a command line, so arguments are preserved.

func (Editor) Cmd

func (e Editor) Cmd(ctx context.Context, path string) *exec.Cmd

Cmd builds (but does not start) the command that opens path in the editor, wired to the current terminal's stdio.

type Session

type Session struct {
	Path string
	// contains filtered or unexported fields
}

Session owns a temporary Markdown file for one editing round.

func NewSession

func NewSession(initial, name string) (*Session, error)

NewSession writes initial content to a fresh temp .md file whose name carries context (so the editor's title bar is useful).

func (*Session) Close

func (s *Session) Close() error

Close removes the whole temporary directory, not just the file: the directory is per-session, and some editors drop swap/backup files next to the buffer that would otherwise be left behind. Safe to call on a zero-value Session.

func (*Session) Result

func (s *Session) Result() (string, error)

Result reads the edited file and strips the HTML-comment template, returning the reviewer's note. An empty result means the comment was abandoned.

type TemplateContext

type TemplateContext struct {
	Repository  string
	PullRequest string
	File        string
	Lines       string
	Side        string
	ReplyTo     string
}

TemplateContext carries the metadata rendered into the editor header comment. Fields left empty are omitted (e.g. PullRequest in local mode).

Jump to

Keyboard shortcuts

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