Documentation ¶
Overview ¶
Package pseudoterm is a framework for running iterative programs programmatically with Go.
https://github.com/henvic/picel
Index ¶
- Variables
- type ExecutionError
- type QueueStory
- func (q *QueueStory) Add(args ...Step)
- func (q *QueueStory) Cancel()
- func (q *QueueStory) HandleLine(s string) (in string, err error)
- func (q *QueueStory) Setup() (ctx context.Context, err error)
- func (q *QueueStory) Success() bool
- func (q *QueueStory) Teardown()
- func (q *QueueStory) TickHandler() error
- type Step
- type Story
- type Terminal
- func (t *Terminal) Run(story Story) (err error)
- func (t *Terminal) Start() (err error)
- func (t *Terminal) Stop() (err error)
- func (t *Terminal) Wait() (ps *os.ProcessState)
- func (t *Terminal) Watch(s Story) error
- func (t *Terminal) Write(b []byte) (n int, err error)
- func (t *Terminal) WriteLine(s string) (n int, err error)
- func (t *Terminal) WriteString(s string) (n int, err error)
Constants ¶
This section is empty.
Variables ¶
var ( // EOT is the End Of Transmission character EOT = []byte{4} // LineReaderInterval is the time to sleep between checks for output // Too low or too high mess things up (lower performance or high CPU usage). LineReaderInterval = 10 * time.Millisecond // SkipWrite is used as a return value from Story HandleLine to indicate // that a line should not be written when reading a line on a given step. SkipWrite = errors.New("Skip writing line input") // SkipZeroMatches is used as a return value from Story HandleLine to indicate // that there are no more steps left to be dealt with. SkipZeroMatches = errors.New("Skip line input due to no match available") // ErrUnsupported is used to indicate there is ErrUnsupported = pty.ErrUnsupported )
Functions ¶
This section is empty.
Types ¶
type ExecutionError ¶
ExecutionError indicates if any happened during the execution
func (ExecutionError) Error ¶
func (e ExecutionError) Error() string
type QueueStory ¶
type QueueStory struct { Sequence []Step Timeout time.Duration // contains filtered or unexported fields }
QueueStory is a command execution story with sequential steps that must be fulfilled before the next is executed
func (*QueueStory) HandleLine ¶
func (q *QueueStory) HandleLine(s string) (in string, err error)
HandleLine handles a QueueStory line the program prints
func (*QueueStory) Setup ¶
func (q *QueueStory) Setup() (ctx context.Context, err error)
Setup executed by Terminal on Watch()
func (*QueueStory) Success ¶
func (q *QueueStory) Success() bool
Success tells if all steps are executed and there is none left
func (*QueueStory) Teardown ¶
func (q *QueueStory) Teardown()
Teardown executed by Terminal during Watch() teardown
func (*QueueStory) TickHandler ¶
func (q *QueueStory) TickHandler() error
TickHandler is called on terminal Watch between LineReaderInterval regardless if there are changes or not, before HandleLine
type Step ¶
type Step struct { Read string ReadRegex *regexp.Regexp ReadFunc func(in string) bool Write string SkipWrite bool Timeout time.Duration // contains filtered or unexported fields }
Step is like a route rule to handle lines
type Story ¶
type Story interface { Setup() (ctx context.Context, err error) Teardown() TickHandler() (err error) HandleLine(s string) (in string, err error) }
Story is interface you can implement to handle commands
type Terminal ¶
type Terminal struct { Command *exec.Cmd EchoStream io.Writer CopyStreamError error // contains filtered or unexported fields }
Terminal is a pseudo terminal you can use to run commands on a pseudo tty programmatically
func (*Terminal) Wait ¶
func (t *Terminal) Wait() (ps *os.ProcessState)
Wait for process to end and return process state