editor

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package editor provides functionality for opening external editors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Command added in v1.9.0

func Command(ctx context.Context, tmpFile string) *exec.Cmd

Command builds the *exec.Cmd that opens tmpFile in the user's editor. It resolves VISUAL then EDITOR, falling back to notepad on Windows or vi on other platforms, and invokes through the shell (`sh -c 'editor "$1"' sh tmpFile`) so that quoting and arguments behave exactly like Git does: the temp-file path is passed as $1 so an $EDITOR that itself carries flags or a space-containing path is expanded by the shell (e.g. "code --wait" or "/Applications/Visual Studio Code.app/.../code").

It does NOT wire Stdin/Stdout/Stderr, so the caller (the CLI, or the TUI via tea.ExecProcess) owns the terminal handoff. This is the single command builder both the CLI editor and the TUI's $EDITOR handoff share, so they cannot diverge on VISUAL→EDITOR precedence, shell quoting, or the OS fallback.

func Normalize added in v1.9.0

func Normalize(content, result string) string

Normalize applies the round-trip-lossless rule to the editor's read-back (result) given the exact content that was written into the tmpfile.

Editors typically auto-append a single trailing newline to a buffer that did not already end with one. We reverse ONLY that editor-added newline: if the original content did not end with a newline, a single trailing newline (Unix "\n" or Windows "\r\n") is stripped from the read-back. A trailing newline the value carried in (PEM keys, JSON, ...) is preserved, so opening a value and saving it untouched is byte-identical — which the callers then detect and report as a no-op change.

func Open

func Open(ctx context.Context, content string) (string, error)

Open opens the content in an external editor and returns the edited result. It uses the VISUAL or EDITOR environment variable to determine the editor. Falls back to notepad on Windows or vi on other platforms.

Types

type OpenFunc

type OpenFunc func(ctx context.Context, content string) (string, error)

OpenFunc is the type for editor functions.

Jump to

Keyboard shortcuts

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