editor

package
v0.85.2 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2019 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package editor provides utilities for editing and re-editing text files in an editor until the changes are accepted or the user aborts the attempt.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EditRetryLoop

func EditRetryLoop(args RetryLoopArgs) error

EditRetryLoop seeds a temp file, prefixed with FilePrefix, with content from SelectFn and passes it to ApplyFn. If ApplyFn errors, the editor will be re-opened with recent error message included in the header comments. The current implementation prefixes comment lines with "#".

Types

type RetryLoopArgs

type RetryLoopArgs struct {
	// FilePrefix
	FilePrefix string
	// SelectFn returns content to be displayed within the editor.
	// It is invoked on each retry of the editing loop.
	SelectFn func() io.Reader
	// ApplyFn attempts to apply the edited contents. If it returns
	// an error, the editor will be re-opened with the error message.
	ApplyFn func(b []byte) error
	// AbortIfUnchanged indicates the editing loop should abort if the
	// editor exits without making any file changes. In this case,
	// ApplyFn is not called with edited content.
	AbortIfUnchanged bool
}

RetryLoopArgs is arguments of EditRetryLoop.

Jump to

Keyboard shortcuts

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