ui

package
v0.3.0-beta Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2015 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cursor

type Cursor struct {
	Line int
	Fg   termbox.Attribute
	Ch   rune
}

type Key

type Key struct {
	KeyCodes []rune
	Keys     []tb.Key
	HelpText string
}

type Layout

type Layout struct {
	Header  Renderer
	Content Renderer
	Footer  Renderer
	// contains filtered or unexported fields
}

func NewLayout

func NewLayout() *Layout

func (*Layout) Render

func (l *Layout) Render() string

type Markup

type Markup struct {
	Foreground   termbox.Attribute // Foreground color.
	Background   termbox.Attribute // Background color (so far always termbox.ColorDefault).
	RightAligned bool              // True when the string is right aligned.
	// contains filtered or unexported fields
}

Markup implements some minimalistic text formatting conventions that get translated to Termbox colors and attributes. To colorize a string wrap it in <color-name>...</> tags. Unlike HTML each tag sets a new color whereas the </> tag changes color back to default. For example:

<green>Hello, <red>world!</>

The color tags could be combined with the attributes: <b>...</b> for bold, <u>...</u> for underline, and <r>...</r> for reverse. Unlike colors the attributes require matching closing tag.

The <right>...</right> tag is used to right align the enclosed string

func NewMarkup

func NewMarkup() *Markup

Creates markup to define tag to Termbox translation rules and store default colors and column alignments.

func (*Markup) IsTag

func (markup *Markup) IsTag(str string) bool

IsTag returns true when the given string looks like markup tag. When the tag name matches one of the markup-supported tags it gets translated to relevant Termbox attributes and colors.

func (*Markup) Tokenize

func (markup *Markup) Tokenize(str string) []string

Tokenize works just like strings.Split() except the resulting array includes the delimiters. For example, the "<green>Hello, <red>world!</>" string when tokenized by tags produces the following:

[0] "<green>"
[1] "Hello, "
[2] "<red>"
[3] "world!"
[4] "</>"

type Renderer

type Renderer interface {
	Render() string
}

Renderable is a mark for anything worth rendering as text

type Screen

type Screen struct {
	Width  int // Current number of columns.
	Height int // Current number of rows.

	Cursor *Cursor // Pointer to cursor (gets created by screen).
	// contains filtered or unexported fields
}

Screen is thin wrapper aroung Termbox library to provide basic display capabilities as required by dry.

func NewScreen

func NewScreen() *Screen

Initializes Termbox, creates screen along with layout and markup, and calculates current screen dimensions. Once initialized the screen is ready for display.

func (*Screen) Clear

func (screen *Screen) Clear() *Screen

Clear makes the entire screen blank using default background color.

func (*Screen) ClearLine

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

ClearLine erases the contents of the line starting from (x,y) coordinate till the end of the line.

func (*Screen) Close

func (screen *Screen) Close() *Screen

Close gets called upon program termination to close the Termbox.

func (*Screen) CursorPosition

func (screen *Screen) CursorPosition() int

func (*Screen) Flush

func (screen *Screen) Flush() *Screen

func (*Screen) MoveCursorDown

func (screen *Screen) MoveCursorDown()

func (*Screen) MoveCursorUp

func (screen *Screen) MoveCursorUp()

func (*Screen) Pause

func (screen *Screen) Pause(pause bool) *Screen

Pause is a toggle function that either creates a timestamp of the pause request or resets it to nil.

func (*Screen) Render

func (screen *Screen) Render(column int, str string)

func (*Screen) RenderLine

func (screen *Screen) RenderLine(x int, y int, str string)

RenderLine takes the incoming string, tokenizes it to extract markup elements, and displays it all starting at (x,y) location.

func (*Screen) Resize

func (screen *Screen) Resize() *Screen

Resize gets called when the screen is being resized. It recalculates screen dimensions and requests to clear the screen on next update.

func (*Screen) Sync

func (screen *Screen) Sync() *Screen

type View

type View struct {

	// BgColor and FgColor allow to configure the background and foreground
	// colors of the View.
	BgColor, FgColor termbox.Attribute

	// If Editable is true, keystrokes will be added to the view's internal
	// buffer at the cursor position.
	Editable bool

	// Overwrite enables or disables the overwrite mode of the view.
	Overwrite bool

	// If Wrap is true, the content that is written to this View is
	// automatically wrapped when it is longer than its width. If true the
	// view's x-origin will be ignored.
	Wrap bool

	// If Autoscroll is true, the View will automatically scroll down when the
	// text overflows. If true the view's y-origin will be ignored.
	Autoscroll bool
	// contains filtered or unexported fields
}

A View is a window. It maintains its own internal buffer and cursor position.

func NewMarkupView

func NewMarkupView(name string, x0, y0, x1, y1 int, showCursor bool) *View

NewMarkupView returns a new View with markup support

func NewView

func NewView(name string, x0, y0, x1, y1 int, showCursor bool) *View

NewView returns a new View

func (*View) Buffer

func (v *View) Buffer() string

Buffer returns a string with the contents of the view's internal buffer

func (*View) Clear

func (v *View) Clear()

Clear empties the view's internal buffer.

func (*View) Cursor

func (v *View) Cursor() (x, y int)

Cursor returns the cursor position of the view.

func (*View) CursorDown

func (v *View) CursorDown()

CursorDown moves the cursor down one line

func (*View) CursorPageDown

func (v *View) CursorPageDown()

CursorPageDown moves the cursor one page down

func (*View) CursorPageUp

func (v *View) CursorPageUp()

CursorPageUp moves the cursor one page up

func (*View) CursorUp

func (v *View) CursorUp()

CursorUp moves the cursor up one line

func (*View) Line

func (v *View) Line(y int) (string, error)

Line returns a string with the line of the view's internal buffer at the position corresponding to the point (x, y).

func (*View) MoveCursorToBottom

func (v *View) MoveCursorToBottom()

MoveCursorToBottom moves the cursor to the bottom of the view buffer

func (*View) MoveCursorToTop

func (v *View) MoveCursorToTop()

func (*View) Name

func (v *View) Name() string

Name returns the name of the view.

func (*View) Position

func (v *View) Position() (x, y int)

Position returns the position in the view buffer.

func (*View) Read

func (v *View) Read(p []byte) (n int, err error)

Read reads data into p. It returns the number of bytes read into p. At EOF, err will be io.EOF. Calling Read() after Rewind() makes the cache to be refreshed with the contents of the view.

func (*View) Render

func (v *View) Render() error

Render renders the view buffer contents.

func (*View) Rewind

func (v *View) Rewind()

Rewind sets the offset for the next Read to 0, which also refresh the read cache.

func (*View) ViewBuffer

func (v *View) ViewBuffer() string

ViewBuffer returns a string with the contents of the view's buffer that is showed to the user

func (*View) ViewSize

func (v *View) ViewSize() (x, y int)

ViewSize returns the number of visible columns and rows in the View.

func (*View) Word

func (v *View) Word(x, y int) (string, error)

Word returns a string with the word of the view's internal buffer at the position corresponding to the point (x, y).

func (*View) Write

func (v *View) Write(p []byte) (n int, err error)

Write appends a byte slice into the view's internal buffer. Because View implements the io.Writer interface, it can be passed as parameter of functions like fmt.Fprintf, fmt.Fprintln, io.Copy, etc. Clear must be called to clear the view's buffer.

Jump to

Keyboard shortcuts

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