liblush

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2013 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Library functions and definitions for lush

Index

Constants

View Source
const Devnull devnull = 0

io.ReadWriteCloser that discards all incoming data and never fails

Variables

This section is empty.

Functions

This section is empty.

Types

type Cmd

type Cmd interface {
	Id() CmdId
	// if SetName has been called return that otherwise best effort
	Name() string
	SetName(string)
	Argv() []string
	// Error to call this after command has started
	SetArgv([]string) error
	// Run command and wait for it to exit
	Run() error
	// Start the command in the background. Follow by Wait() to get exit status
	Start() error
	// Block until command is complete return exit status
	Wait() error
	Stdin() InStream
	Stdout() OutStream
	Stderr() OutStream
	Status() CmdStatus
	// Opaque data, untouched by the shell
	UserData() interface{}
	SetUserData(interface{})
	Signal(os.Signal) error
}

A shell command state similar to os/exec.Cmd

type CmdId

type CmdId int64

Guaranteed to be unique for every command at one specific point in time but once a command is cleaned up another may reuse his id.

func ParseCmdId

func ParseCmdId(idstr string) (CmdId, error)

type CmdStatus

type CmdStatus interface {
	// Time the command was started or nil if not started yet
	Started() *time.Time
	// When the command stopped, nil if still running / not started
	Exited() *time.Time
	Success() bool
	// nil iff Success() == true
	Err() error
	// Called with this status as an argument on every update. If the callback
	// returns a non-nil error it will not be called for future updates.
	NotifyChange(func(CmdStatus) error)
}

type FlexibleMultiWriter

type FlexibleMultiWriter struct {
	// contains filtered or unexported fields
}

slightly tweaked io.MultiWriter: if an underlying writer fails it is removed and no error is returned. writers can be added and removed on the fly. if zero writers are configured Write() calls to this object block.

func (*FlexibleMultiWriter) AddWriter

func (mw *FlexibleMultiWriter) AddWriter(w io.Writer)

func (*FlexibleMultiWriter) RemoveWriter

func (mw *FlexibleMultiWriter) RemoveWriter(w io.Writer) bool

func (*FlexibleMultiWriter) Write

func (mw *FlexibleMultiWriter) Write(data []byte) (int, error)

always great success responsibility for failure is here not with caller

func (*FlexibleMultiWriter) Writers

func (mw *FlexibleMultiWriter) Writers() []io.Writer

type InStream

type InStream interface {
	io.WriteCloser
	// Command this stream belongs to (never nil)
	Cmd() Cmd
}

Input stream of a command. Writes to this stream block until the command is started and fail if it has exited

type OutStream

type OutStream interface {
	// Send all output to this writer. Multiple writers can be hooked up and
	// unloaded at any time. If this writer's Write returns an error it is
	// removed from the list without affecting anything else.  Output is
	// blocked if no writers are configured.
	AddWriter(w io.Writer)
	// Remove a writer previously set with AddWriter. Returns false if not set.
	RemoveWriter(w io.Writer) bool
	Writers() []io.Writer
	Scrollback() Ringbuffer
}

Output stream of a command

type Ringbuffer

type Ringbuffer interface {
	Size() int
	Resize(int)
	// Fill this buffer with the most recently written bytes
	Last(p []byte) int
	Write(data []byte) (int, error)
}

Circular fifo buffer.

type Session

type Session interface {
	Chdir(dir string) error
	NewCommand(name string, arg ...string) Cmd
	GetCommand(id CmdId) Cmd
	GetCommandIds() []CmdId
	// Environment that will be passed to child processes. NOT the environment
	// variables of this shell process. Eg setting Path will not affect where
	// this session looks for binaries. It will, however, affect how child
	// processes search for binaries because they will actually have the
	// modified PATH as an envvar.
	Setenv(key, value string)
	Unsetenv(key string)
	Getenv(name string) string
	Environ() map[string]string
}

func NewSession

func NewSession() Session

Jump to

Keyboard shortcuts

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