scrn

package module
v0.0.0-...-84c35e3 Latest Latest
Warning

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

Go to latest
Published: May 30, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

README

scrn

This repository contains keyPress handler and simple terminal screen control.

Installation

Install and update this go package with go get -u github.com/ackneal/scrn

Example
package main

import (
	"time"

	"github.com/ackneal/scrn"
)

func main() {
	var s scrn.Screen
	s.Open()        // open alternate screen
	defer s.Close() // close

	go func() {
		for {
			s.Move(1, 1) // moves the position of a cursor
			s.Printf("Current Time: %s", time.Now().Format(time.RFC1123Z))
			time.Sleep(time.Second)
		}
	}()

	// listens keyPress for q and ESC
	quitKey := []scrn.KeyCode{
		scrn.KeyCode(int('q')),
		scrn.KeyESC,
	}

	for {
		select {
		case <-scrn.KeyPress(quitKey...):
			return
		}
	}
}

Documentation

Index

Constants

View Source
const (
	KeyESC = KeyCode(int('\033'))
)

Variables

View Source
var (
	KeyPressCaseSensitive bool
)

Functions

func GetSize

func GetSize() (width, height int, err error)

func KeyPress

func KeyPress(code ...KeyCode) <-chan KeyCode

Types

type KeyCode

type KeyCode int

type Screen

type Screen struct{}

func (*Screen) Clear

func (s *Screen) Clear()

func (*Screen) Close

func (s *Screen) Close()

func (*Screen) Move

func (s *Screen) Move(col, row int)

func (*Screen) Open

func (s *Screen) Open()

func (*Screen) Print

func (s *Screen) Print(text string) (n int, err error)

func (*Screen) Printf

func (s *Screen) Printf(format string, a ...interface{}) (n int, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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