minterm

package module
v0.0.0-...-5b19393 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2016 License: MIT Imports: 8 Imported by: 4

README

minterm

minterm

Just a small library to help manipulate the terminal in Go. I needed something like Python's shutil.get_terminal_size(), so I wrote this, then added some more stuff I ended up needing.

Usage

###Import

import "github.com/MinoMino/minterm"

###Terminal Size

columns, rows, err := minterm.TerminalSize()

###Line Reservation

lr, _ := NewLineReserver()
defer lr.Release()
lr.Set("This line will always be the last line.")
fmt.Println("You can now print normally.")

An example of it used in conjunction with minprogress: Image of line reservation in use with minprogress.

License

MIT. See LICENSE for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TerminalSize

func TerminalSize() (columns, rows int, err error)

Returns the terminal's number of columns and rows. If something goes wrong, err will be non-nil, but also with reasonable fallback values of (80, 24). In other words, the error can often be discarded.

Types

type LineReserver

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

Reserves a line at the bottom of the terminal, while normal stdout and stderr goes above it. It does not play well any other prints using carriage returns.

A side-effect of the implementation is that anything printed that doesn't have a newline in it gets buffered instead of printed immediately.

func NewLineReserver

func NewLineReserver() (*LineReserver, error)

Takes control of stdout and stderr in order to reserve the last line of the terminal, which can be set with Set().

func (*LineReserver) Refresh

func (lr *LineReserver) Refresh()

Prints the reserved line again, updating the line if it was changed since last time. Note that if something was buffered (i.e. something printed without a newline in it), a newline will be appended to avoid erasing what was in the buffer.

func (*LineReserver) Release

func (lr *LineReserver) Release()

Clears the reserved line and restores control to stdout and stderr.

func (*LineReserver) Set

func (lr *LineReserver) Set(line string)

Sets the reserved line to the desired string.

Jump to

Keyboard shortcuts

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