goban

package module
v0.0.0-...-2682b1c Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2019 License: MIT Imports: 13 Imported by: 2

README

goban - minimal and concurrent CUI

package goban (碁盤, meaning of Go game board in Japanese) provides CUI with simple API.

Hello World

package main

import (
	"context"

	"github.com/eihigh/goban"
)

func main() {
	goban.Main(app, view)
}

func app(_ context.Context, es goban.Events) error {
	goban.Show()
	es.ReadKey()
	return nil
}

func view() {
	goban.Screen().Enclose("hello").Prints("Hello World!\nPress any key to exit.")
}

Features

  • Minimal API
  • Isolated Views and Controllers
  • Receive events from channel instead of event handlers
  • Color with escape sequences
  • Box drawings
  • Grid layouts

Status

goban is under active development. The API is subject to change.

TODO

  • Flexbox layouts
  • More widgets
  • Mouse support

Documentation

See https://godoc.org/github.com/eihigh/goban .

Dependencies

This package is based on github.com/gdamore/tcell .

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAborted represents that the program was aborted
	// for some reason, such as Ctrl+C or OS signals.
	ErrAborted = fmt.Errorf("program aborted")
)

Functions

func Main

func Main(app func(context.Context, Events) error, viewfns ...func()) error

Main runs the main process. When the app exits, Main also exits. If cancelled for any other reason, Main exits and the cancellation is propagated to the context.

func PopView

func PopView()

PopView pops the view on top.

func PushView

func PushView(v View)

PushView pushes the view on top.

func PushViewFunc

func PushViewFunc(f func())

PushViewFunc pushes the function as view on top.

func RemoveView

func RemoveView(v View)

RemoveView removes the specified view.

func Show

func Show()

Show calls each View to refresh the screen.

func Sync

func Sync()

Sync is similar to Show, but calls tcell.Screen's Sync instead.

Types

type Align

type Align int
const (
	AlignStart Align = iota
	AlignCenter
	AlignEnd
)

type Box

type Box struct {
	Pos    Point
	Size   Point
	Scroll Point
	Style  tcell.Style
	// contains filtered or unexported fields
}

Box represents an area on the screen and provides various drawing and layout functions.

func NewBox

func NewBox(x, y, w, h int) *Box

NewBox returns a box at the specified position and size.

func Screen

func Screen() *Box

Screen returns a box of screen size.

func (*Box) CenterOf

func (b *Box) CenterOf(dst *Box) *Box

func (*Box) Clear

func (b *Box) Clear()

func (*Box) DrawSides

func (b *Box) DrawSides(title string, left, top, right, bottom int) *Box

func (*Box) Enclose

func (b *Box) Enclose(title string) *Box

func (*Box) Fit

func (b *Box) Fit(dst *Box, dstx, dsty, srcx, srcy float64) *Box

func (*Box) GridCell

func (b *Box) GridCell(g *Grid, left, top, right, bottom int) *Box

func (*Box) GridItem

func (b *Box) GridItem(g *Grid, name string) *Box

func (*Box) InsideSides

func (b *Box) InsideSides(left, top, right, bottom int) *Box

func (*Box) IsClicked

func (b *Box) IsClicked(e *tcell.EventMouse) bool

func (*Box) Print

func (b *Box) Print(a ...interface{})

func (*Box) Printf

func (b *Box) Printf(format string, a ...interface{})

func (*Box) Println

func (b *Box) Println(a ...interface{})

func (*Box) Prints

func (b *Box) Prints(s string)

func (*Box) Puts

func (b *Box) Puts(s string)

func (*Box) Write

func (b *Box) Write(p []byte) (int, error)

type Buffer

type Buffer struct {
	VAlign, HAlign Align
	// contains filtered or unexported fields
}

func (*Buffer) Flush

func (b *Buffer) Flush(box *Box)

func (*Buffer) Prints

func (b *Buffer) Prints(s string)

type Events

type Events chan tcell.Event

Events is an alias of chan tcell.Event and provides some reading functions.

func (Events) ReadKey

func (es Events) ReadKey() *tcell.EventKey

ReadKey waits for a key event to the channel and returns it. Other events are ignored.

func (Events) ReadMouse

func (es Events) ReadMouse() *tcell.EventMouse

ReadMouse waits for a mouse event to the channel and returns it. Other events are ignored.

type Grid

type Grid struct {
	Cols, Rows []Length
	// contains filtered or unexported fields
}

func NewGrid

func NewGrid(layout ...string) *Grid

type Length

type Length struct {
	Unit  LengthUnit
	Value int
}

func NEm

func NEm(n int) Length

func NFr

func NFr(n int) Length

type LengthUnit

type LengthUnit int
const (
	Em LengthUnit = iota
	Fr
)

func (LengthUnit) String

func (u LengthUnit) String() string

type Point

type Point struct {
	X, Y int
}

Point represents a point on the screen.

type View

type View interface {
	View()
}

View represents a drawing function.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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