editor

package
v0.0.0-...-c8a214a Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2018 License: Apache-2.0 Imports: 5 Imported by: 1

Documentation

Overview

Package editor provides simple wrappers for interacting with an environment configured text editor. The editor command is taken from the environment variable EDITOR and the package variable DefaultEditor will be used if EDITOR is not set.

Index

Constants

View Source
const EditorVar = "EDITOR"

EditorVar specifies the environment variable we use to discover the editor command.

Variables

View Source
var (
	// DefaultEditor is used if the user does not have EDITOR specified.
	DefaultEditor = ""

	// ErrNoEditor indicates that no EDITOR was set in the environment.
	ErrNoEditor = fmt.Errorf(
		"the $%s environment variable is empty or unset. Please set $%s to a path within $PATH to the command-line editor of your choice (e.g. /usr/bin/vi or /usr/bin/emacs)",
		EditorVar,
		EditorVar,
	)
)

Functions

func EditPath

func EditPath(path string) error

EditPath opens a specified path in the configured editor. If the path doesn't exist or fails to open then an error is returned.

func EditText

func EditText(str string) (string, error)

EditText opens an editor with the initial contents populated from the provided string; the edited string is returned.

func EditTextType

func EditTextType(str, ext string) (string, error)

EditTextType takes a string that should be edited and opens an editor with that content preloaded; it returns the edited string. If ext is not empty it will be used as the file extension.

In the event of an error an empty string and the error will be returned.

func Get

func Get() (string, []string, error)

Get returns the editor that will be used as determined by reading the EditorVar environment variable. The unmodified content of EditorVar will returned as the first return value. The second return value will be a space split slice of the contents.

Types

This section is empty.

Jump to

Keyboard shortcuts

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