tsize

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

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

Go to latest
Published: Feb 19, 2017 License: MIT Imports: 6 Imported by: 21

README

Go terminal size

GoDoc Build Status Go Report Card

Features:

  • Get the size of the current terminal as rows and columns.
  • Listen on terminal size changes and receive the new size via a channel.
  • Supports Linux and Windows.

Installation

$ go get github.com/kopoli/go-terminal-size

Usage

For a complete example see _example/example.go.

Abbreviated example:

package main

import (
	"fmt"

	tsize "github.com/kopoli/go-terminal-size"
)

func main() {
	var s tsize.Size

	s, err := tsize.GetSize()
	if err == nil {
		fmt.Println("Current size is", s.Width, "by", s.Height)
	}
}

License

MIT license

Documentation

Overview

Package tsize gets the terminal size. Supports Linux and Windows.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotATerminal = errors.New("Given file is not a terminal")

ErrNotATerminal is the error to return if the given file to FgetSize isn't a terminal.

Functions

This section is empty.

Types

type Size

type Size struct {
	Width  int
	Height int
}

Size represents terminal size in columns and rows as Width and Height, respectively.

func FgetSize

func FgetSize(fp *os.File) (s Size, err error)

FgetSize gets the terminal size of a given os.File. Returns the NotATerminal error, if it is not a terminal.

func GetSize

func GetSize() (s Size, err error)

GetSize gets the current terminal size. The terminal is expected to be os.Stdout. Returns the NotATerminal error, if it is not a terminal.

type SizeListener

type SizeListener struct {
	Change <-chan Size
	// contains filtered or unexported fields
}

SizeListener listens to terminal size changes. The new size is returned through the Change channel when the change occurs.

func NewSizeListener

func NewSizeListener() (sc *SizeListener, err error)

NewSizeListener creates a new size change listener

func (*SizeListener) Close

func (sc *SizeListener) Close() (err error)

Close implements the io.Closer interface that stops listening to terminal size changes.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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