Skip to content
/ scrn Public

keyPress handler and simple terminal screen control by Golang

License

Notifications You must be signed in to change notification settings

ackneal/scrn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
		}
	}
}

About

keyPress handler and simple terminal screen control by Golang

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages