editor

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Editor

type Editor struct {
	Args  []string
	Shell bool
}

Editor holds the command-line args to fire up the editor

func NewDefaultEditor

func NewDefaultEditor(envs []string) Editor

NewDefaultEditor creates a struct Editor that uses the OS environment to locate the editor program, looking at EDITOR environment variable to find the proper command line. If the provided editor has no spaces, or no quotes, it is treated as a bare command to be loaded. Otherwise, the string will be passed to the user's shell for execution.

func (Editor) Launch

func (e Editor) Launch(path string) error

Launch opens the described or returns an error. The TTY will be protected, and SIGQUIT, SIGTERM, and SIGINT will all be trapped.

func (Editor) LaunchTempFile

func (e Editor) LaunchTempFile(prefix, suffix string, r io.Reader) (bytes []byte, path string, err error)

LaunchTempFile reads the provided stream into a temporary file in the given directory and file prefix, and then invokes Launch with the path of that file. It will return the contents of the file after launch, any errors that occur, and the path of the temporary file so the caller can clean it up as needed.

type TTY

type TTY struct {
	// In is a reader representing stdin. It is a required field.
	In io.Reader
	// Out is a writer representing stdout. It must be set to support terminal resizing. It is an
	// optional field.
	Out io.Writer
	// Raw is true if the terminal should be set raw.
	Raw bool
	// TryDev indicates the TTY should try to open /dev/tty if the provided input
	// is not a file descriptor.
	TryDev bool
}

TTY helps invoke a function and preserve the state of the terminal, even if the process is terminated during execution. It also provides support for terminal resizing for remote command execution/attachment.

func (TTY) Safe

func (t TTY) Safe(fn func() error) error

Safe invokes the provided function and will attempt to ensure that when the function returns (or a termination signal is sent) that the terminal state is reset to the condition it was in prior to the function being invoked. If t.Raw is true the terminal will be put into raw mode prior to calling the function. If the input file descriptor is not a TTY and TryDev is true, the /dev/tty file will be opened (if available).

Jump to

Keyboard shortcuts

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