Help us shape the future of Go! Take the 2026 Go Developer Survey

console

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2023 License: Apache-2.0 Imports: 7 Imported by: 1,408

README

console

PkgGoDev Build Status Go Report Card

Golang package for dealing with consoles. Light on deps and a simple API.

Modifying the current process

current := console.Current()
defer current.Reset()

if err := current.SetRaw(); err != nil {
}
ws, err := current.Size()
current.Resize(ws)

Project details

console is a containerd sub-project, licensed under the Apache 2.0 license. As a containerd sub-project, you will find the:

information in our containerd/project repository.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotAConsole    = errors.New("provided file is not a console")
	ErrNotImplemented = errors.New("not implemented")
)

Functions

func ClearONLCR

func ClearONLCR(fd uintptr) error

ClearONLCR sets the necessary tty_ioctl(4)s to ensure that a pty pair created by us acts normally. In particular, a not-very-well-known default of Linux unix98 ptys is that they have +onlcr by default. While this isn't a problem for terminal emulators, because we relay data from the terminal we also relay that funky line discipline.

func SetONLCR

func SetONLCR(fd uintptr) error

SetONLCR sets the necessary tty_ioctl(4)s to ensure that a pty pair created by us acts as intended for a terminal emulator.

Types

type Console

type Console interface {
	File

	// Resize resizes the console to the provided window size
	Resize(WinSize) error
	// ResizeFrom resizes the calling console to the size of the
	// provided console
	ResizeFrom(Console) error
	// SetRaw sets the console in raw mode
	SetRaw() error
	// DisableEcho disables echo on the console
	DisableEcho() error
	// Reset restores the console to its original state
	Reset() error
	// Size returns the window size of the console
	Size() (WinSize, error)
}

func ConsoleFromFile

func ConsoleFromFile(f File) (Console, error)

ConsoleFromFile returns a console using the provided file nolint:revive

func Current

func Current() (c Console)

Current returns the current process' console

func NewPty

func NewPty() (Console, string, error)

NewPty creates a new pty pair The master is returned as the first console and a string with the path to the pty slave is returned as the second

type File

type File interface {
	io.ReadWriteCloser

	// Fd returns its file descriptor
	Fd() uintptr
	// Name returns its file name
	Name() string
}

type WinSize

type WinSize struct {
	// Height of the console
	Height uint16
	// Width of the console
	Width uint16
	// contains filtered or unexported fields
}

WinSize specifies the window size of the console

Jump to

Keyboard shortcuts

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