console

package module
v0.0.0-...-27323a2 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2021 License: MIT Imports: 5 Imported by: 2

README

go-console

Main GoDoc

go-console is a cross-platform PTY interface. On *nix platforms we rely on pty and on windows go-winpty (go-console will ship winpty-0.4.3-msvc2015 using go:embed, so there's no need to include winpty binaries)

Example

package main

import (
	"io"
	"log"
	"os"
	"runtime"
	"sync"

	"github.com/runletapp/go-console"
)

func main() {

	proc, err := console.New(120, 60)
	if err != nil {
		panic(err)
	}
	defer proc.Close()

	var args []string

	if runtime.GOOS == "windows" {
		args = []string{"cmd.exe", "/c", "dir"}
	} else {
		args = []string{"ls", "-lah", "--color"}
	}

	if err := proc.Start(args); err != nil {
		panic(err)
	}

	var wg sync.WaitGroup
	wg.Add(1)
	go func() {
		defer wg.Done()

		_, err = io.Copy(os.Stdout, proc)
		if err != nil {
			log.Printf("Error: %v\n", err)
		}
	}()

	if _, err := proc.Wait(); err != nil {
		log.Printf("Wait err: %v\n", err)
	}

	wg.Wait()
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrProcessNotStarted = errors.New("Process has not been started")
	ErrInvalidCmd        = errors.New("Invalid command")
)

Functions

This section is empty.

Types

type Console

type Console interfaces.Console

Console communication interface

func New

func New(w int, h int) (Console, error)

New creates a new console with initial size

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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