screen

package module
v0.0.0-...-3972bfe Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2023 License: MIT Imports: 5 Imported by: 1

README

Screen

Simple Terminal UI Library in Go

Installation

$ go get github.com/shoumodip/screen-go

Usage

package main

import (
	"fmt"
	"github.com/shoumodip/screen-go"
)

func main() {
	scr, err := screen.New()
	if err != nil {
		panic(err)
	}
	defer scr.Reset()

	scr.HideCursor()
	defer scr.ShowCursor()

	for {
		scr.Clear()

		// Coordinates start at (0, 0) instead of (1, 1)
		scr.MoveCursor(0, 0)
		scr.Apply(screen.STYLE_BOLD, screen.COLOR_BLUE)

		// Newlines have to be '\r\n'
		fmt.Fprint(scr, "Hello, world!\r\n")
		scr.Apply(screen.STYLE_NONE)

		// Present the rendered state to the screen
		scr.Flush()

		key, err := scr.Input()
		if err != nil {
			panic(err)
		}

		if key == 'q' {
			break
		}
	}
}

Documentation

Index

Constants

View Source
const (
	STYLE_NONE    = 0
	STYLE_BOLD    = 1
	STYLE_REVERSE = 7

	COLOR_RED     = 31
	COLOR_BLUE    = 34
	COLOR_MAGENTA = 35
	COLOR_CYAN    = 36
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Screen

type Screen struct {
	Width, Height int
	// contains filtered or unexported fields
}

func New

func New() (Screen, error)

func (*Screen) Apply

func (screen *Screen) Apply(effects ...int)

func (*Screen) Clear

func (screen *Screen) Clear()

func (*Screen) Flush

func (screen *Screen) Flush() error

func (*Screen) HideCursor

func (screen *Screen) HideCursor()

func (*Screen) Input

func (screen *Screen) Input() (byte, error)

func (*Screen) MoveCursor

func (screen *Screen) MoveCursor(x, y int)

func (*Screen) Reset

func (screen *Screen) Reset()

func (*Screen) ShowCursor

func (screen *Screen) ShowCursor()

func (Screen) Write

func (screen Screen) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳