canvas

package module
v0.0.0-...-25281b2 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2019 License: MIT Imports: 12 Imported by: 0

README

Overview

Canvas - Drawing canvas for the command line to render artwork and games within the current session (and not screen into one).

Status

** Under construction ** But, you can try it out by running the examples under examples/:

cd examples
go run rain.go
go run sinewave.go

Documentation

Index

Constants

View Source
const (
	StyleNoChange = 1 << iota
	StyleNormal
	StyleBold
	StyleDim
	StyleUnderlined
	StyleBlink
	StyleInverted
	StyleHidden
)

Variables

View Source
var (
	ErrorOutOfBounds = errors.New("out of bounds")
	ErrorTruncated   = errors.New("string truncated")
)
View Source
var (
	ColorDefault      = Color{/* contains filtered or unexported fields */}
	ColorBlack        = Color{Term256: 0}
	ColorRed          = Color{Term256: 1}
	ColorGreen        = Color{Term256: 2}
	ColorYellow       = Color{Term256: 3}
	ColorBlue         = Color{Term256: 4}
	ColorMagenta      = Color{Term256: 5}
	ColorCyan         = Color{Term256: 6}
	ColorLightGray    = Color{Term256: 7}
	ColorDarkGray     = Color{Term256: 8}
	ColorLightRed     = Color{Term256: 9}
	ColorLightGreen   = Color{Term256: 10}
	ColorLightYellow  = Color{Term256: 11}
	ColorLightBlue    = Color{Term256: 12}
	ColorLightMagenta = Color{Term256: 13}
	ColorLightCyan    = Color{Term256: 14}
	ColorWhite        = Color{Term256: 15}
)
View Source
var Colors color.Palette = make([]color.Color, 256)

colors is a palette where the index corresponds to a 8 bit terminal color palette (i.e. 256 colors)

Functions

func DisableEcho

func DisableEcho()

func Draw

func Draw()

Draw renders all 256 colors to stdout for debugging purposes

func EnableEcho

func EnableEcho()

func HideCursor

func HideCursor()

func InitColors

func InitColors(num int) bool

InitColors initializes 'Colors' (the terminal emulator color palette) with 'num' colors. Accepted num values are 8, 16, 256. Returns a boolean indicating success or failure. If 'num' is not one of the accepted values, 256 colors are initialized and false is returned.

func ShowCursor

func ShowCursor()

Types

type Canvas

type Canvas struct {
	// Width is the width of the canvas
	Width int

	// Height is the height of the canvas
	Height int

	// Logger can be used for debugging purposes.
	Logger *log.Logger

	Background Color

	// CursorOnEnd will move the cursor to (x-Max, y-Max) when Flush()
	// is invoked. This comes in handy if you want the user prompt to
	// show up right after the canvas (as opposed to somewhere in
	// between), when there is an abrupt termination.
	CursorOnEnd bool
	// contains filtered or unexported fields
}

Canvas is a representation of a painting canvas on a terminal that supports 256 colors. The canvas is rendered in-line.

It provides functions to manipulate the canvas and thread-safe implementations of the same functions as well. If you don't intend to use this in a multi-threaded fashion, then use the non thread-safe functions as they offer better performance which is critical in animation and gaming applications.

func NewCanvas

func NewCanvas(width, height int, background Color) *Canvas

NewCanvas returns a new Canvas object

func (*Canvas) Clear

func (c *Canvas) Clear()

func (*Canvas) ClearSafe

func (c *Canvas) ClearSafe()

func (*Canvas) Flush

func (c *Canvas) Flush()

func (*Canvas) FlushSafe

func (c *Canvas) FlushSafe()

func (*Canvas) Move

func (c *Canvas) Move(x, y int) error

func (*Canvas) MoveSafe

func (c *Canvas) MoveSafe(x, y int) error

func (*Canvas) Set

func (c *Canvas) Set(x, y int, char rune)

func (*Canvas) SetBackground

func (c *Canvas) SetBackground(clr Color)

func (*Canvas) SetBackgroundSafe

func (c *Canvas) SetBackgroundSafe(clr Color)

func (*Canvas) SetForeground

func (c *Canvas) SetForeground(clr Color)

func (*Canvas) SetForegroundSafe

func (c *Canvas) SetForegroundSafe(clr Color)

func (*Canvas) SetSafe

func (c *Canvas) SetSafe(x, y int, char rune)

func (*Canvas) SetStyle

func (c *Canvas) SetStyle(style int)

func (*Canvas) SetStyleSafe

func (c *Canvas) SetStyleSafe(style int)

func (*Canvas) Write

func (c *Canvas) Write(text string)

func (*Canvas) WriteAt

func (c *Canvas) WriteAt(x, y int, foreground, background Color, style int, text string)

func (*Canvas) WriteAtSafe

func (c *Canvas) WriteAtSafe(x, y int, foreground, background Color, style int, text string)

func (*Canvas) WriteSafe

func (c *Canvas) WriteSafe(text string)

type Color

type Color struct {
	// RGBA defines a standard color value defined as R,G,B,A. The
	// system will pick the closest color on a terminal that supports
	// 256 colors.
	RGBA color.Color

	// Term256 can be used to specify one of the 256 terminal colors
	// on a terminal that supports 256 colors. This value will be used
	// only if RGBA is nil.
	Term256 uint8
	// contains filtered or unexported fields
}

Color defines a color either expressed as an RGBA value or as one of the 256 colors on a terminal that supports 256 colors.

func ColorRandom

func ColorRandom() Color

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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