topsl

package module
v0.0.0-...-8e65ebd Latest Latest
Warning

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

Go to latest
Published: May 24, 2016 License: Apache-2.0 Imports: 3 Imported by: 2

README

topsl

** THIS PROJECT IS NO LONGER MAINTAINED **

The functionality here has been merged (with improvements) into the tcell Views package. (go get github.com/gdamore/tcell/views)

Please use that package instead.

I'm leaving the rest of this package here for posterity.

Linux Status Windows Status GitHub License Issues Gitter GoDoc

Tops'l is a work in progress (Alpha). Please use with caution; at this time it is not suitable for production use.

Package topsl is a terminal oriented panels support library. What it really does is provide mid-level abstractions to make it easier to build richer terminal applications, which can include editors, complex dialogs, etc. It is built upon the excellent termbox-go library.

Note that this is super preliminary work, and was extracted out of a project to create a nice interface for my govisor project. I wouldn't recommend its use in other projects at this time. Hopefully this will change quickly.

Documentation

Index

Constants

View Source
const (
	KeyF1        KeyCode = KeyCode(termbox.KeyF1)
	KeyF2                = KeyCode(termbox.KeyF2)
	KeyF3                = KeyCode(termbox.KeyF3)
	KeyF4                = KeyCode(termbox.KeyF4)
	KeyF5                = KeyCode(termbox.KeyF5)
	KeyF6                = KeyCode(termbox.KeyF6)
	KeyF7                = KeyCode(termbox.KeyF7)
	KeyF8                = KeyCode(termbox.KeyF8)
	KeyF9                = KeyCode(termbox.KeyF9)
	KeyF10               = KeyCode(termbox.KeyF10)
	KeyF11               = KeyCode(termbox.KeyF11)
	KeyF12               = KeyCode(termbox.KeyF12)
	KeyInsert            = KeyCode(termbox.KeyInsert)
	KeyDelete            = KeyCode(termbox.KeyDelete)
	KeyHome              = KeyCode(termbox.KeyHome)
	KeyEnd               = KeyCode(termbox.KeyEnd)
	KeyUp                = KeyCode(termbox.KeyArrowUp)
	KeyDown              = KeyCode(termbox.KeyArrowDown)
	KeyLeft              = KeyCode(termbox.KeyArrowLeft)
	KeyRight             = KeyCode(termbox.KeyArrowRight)
	KeyPgDn              = KeyCode(termbox.KeyPgdn)
	KeyPgUp              = KeyCode(termbox.KeyPgup)
	KeyCtrlA             = KeyCode(termbox.KeyCtrlA)
	KeyCtrlB             = KeyCode(termbox.KeyCtrlB)
	KeyCtrlC             = KeyCode(termbox.KeyCtrlC)
	KeyCtrlD             = KeyCode(termbox.KeyCtrlD)
	KeyCtrlE             = KeyCode(termbox.KeyCtrlE)
	KeyCtrlF             = KeyCode(termbox.KeyCtrlF)
	KeyCtrlG             = KeyCode(termbox.KeyCtrlG)
	KeyCtrlH             = KeyCode(termbox.KeyCtrlH)
	KeyCtrlI             = KeyCode(termbox.KeyCtrlI)
	KeyCtrlJ             = KeyCode(termbox.KeyCtrlJ)
	KeyCtrlK             = KeyCode(termbox.KeyCtrlK)
	KeyCtrlL             = KeyCode(termbox.KeyCtrlL)
	KeyCtrlM             = KeyCode(termbox.KeyCtrlM)
	KeyCtrlN             = KeyCode(termbox.KeyCtrlN)
	KeyCtrlO             = KeyCode(termbox.KeyCtrlO)
	KeyCtrlP             = KeyCode(termbox.KeyCtrlP)
	KeyCtrlQ             = KeyCode(termbox.KeyCtrlQ)
	KeyCtrlR             = KeyCode(termbox.KeyCtrlR)
	KeyCtrlS             = KeyCode(termbox.KeyCtrlS)
	KeyCtrlT             = KeyCode(termbox.KeyCtrlT)
	KeyCtrlU             = KeyCode(termbox.KeyCtrlU)
	KeyCtrlV             = KeyCode(termbox.KeyCtrlV)
	KeyCtrlW             = KeyCode(termbox.KeyCtrlW)
	KeyCtrlX             = KeyCode(termbox.KeyCtrlX)
	KeyCtrlY             = KeyCode(termbox.KeyCtrlY)
	KeyCtrlZ             = KeyCode(termbox.KeyCtrlZ)
	KeyTab               = KeyCode(termbox.KeyTab)
	KeyBackspace         = KeyCode(termbox.KeyBackspace)
	KeyEnter             = KeyCode(termbox.KeyEnter)
	KeyEsc               = KeyCode(termbox.KeyEsc)
)

We take a very simplistic approach here, and do not expose every possible key code. Only those codes which are likely to be useful in real apps are listed. Applications shouldn't rely on non-portable key codes.

Variables

Some stock styles

View Source
var DefaultScreen = &screen{}

Screen represents the default screen.

Functions

func AppDraw

func AppDraw()

func AppFini

func AppFini()

func AppInit

func AppInit() error

func AppLock

func AppLock()

func AppRedraw

func AppRedraw()

func AppUnlock

func AppUnlock()

func RunApplication

func RunApplication()

func SetApplication

func SetApplication(app Widget)

Types

type Attribute

type Attribute uint16

Attribute represents a single color, or additional attributes such as bold, reverse, underline. For the moment, we are not supporting the entire 256 color palette. We should explore that later.

type CellModel

type CellModel interface {
	GetCell(x, y int) (rune, Style)
	GetBounds() (int, int)
	SetCursor(int, int)
	GetCursor() (int, int, bool, bool)
	MoveCursor(offx, offy int)
}

CellModel models the content of a CellView. The dimensions used within a CellModel are always logical, and have origin 0, 0.

type CellView

type CellView struct {
	// contains filtered or unexported fields
}

A CellView is a flexible view of a CellModel, offering both cursor management and a panning.

func NewCellView

func NewCellView() *CellView

func (*CellView) Draw

func (a *CellView) Draw()

func (*CellView) HandleEvent

func (a *CellView) HandleEvent(e Event) bool

func (*CellView) MakeCursorVisible

func (a *CellView) MakeCursorVisible()

func (*CellView) MakeVisible

func (a *CellView) MakeVisible(x, y int)

func (*CellView) Resize

func (a *CellView) Resize()

func (*CellView) SetCursor

func (a *CellView) SetCursor(x, y int)

func (*CellView) SetCursorX

func (a *CellView) SetCursorX(x int)

func (*CellView) SetCursorY

func (a *CellView) SetCursorY(y int)

func (*CellView) SetModel

func (a *CellView) SetModel(model CellModel)

func (*CellView) SetView

func (a *CellView) SetView(view View)

type Event

type Event interface {
}

type KeyBar

type KeyBar struct {
	// contains filtered or unexported fields
}

func NewKeyBar

func NewKeyBar() *KeyBar

func (*KeyBar) Draw

func (k *KeyBar) Draw()

func (*KeyBar) HandleEvent

func (k *KeyBar) HandleEvent(Event) bool

func (*KeyBar) Resize

func (k *KeyBar) Resize()

func (*KeyBar) SetKeys

func (k *KeyBar) SetKeys(words []string)

func (*KeyBar) SetView

func (k *KeyBar) SetView(view View)

type KeyCode

type KeyCode termbox.Key

type KeyEvent

type KeyEvent struct {
	Key KeyCode
	Ch  rune
}

type Panel

type Panel struct {
	// contains filtered or unexported fields
}

func NewPanel

func NewPanel() *Panel

func (*Panel) Draw

func (p *Panel) Draw()

func (*Panel) HandleEvent

func (p *Panel) HandleEvent(e Event) bool

func (*Panel) Resize

func (p *Panel) Resize()

func (*Panel) SetBottom

func (p *Panel) SetBottom(w Widget)

func (*Panel) SetContent

func (p *Panel) SetContent(w Widget)

func (*Panel) SetStatus

func (p *Panel) SetStatus(w Widget)

func (*Panel) SetTitle

func (p *Panel) SetTitle(w Widget)

func (*Panel) SetView

func (p *Panel) SetView(view View)

type ResizeEvent

type ResizeEvent struct {
}

type Screen

type Screen interface {
	PollEvent() Event
	Init() error
	Fini()
	Sync()
	Flush()
	Interrupt()
	View
	sync.Locker
}

func GetScreen

func GetScreen() Screen

type StatusBar

type StatusBar struct {
	// contains filtered or unexported fields
}

func NewStatusBar

func NewStatusBar() *StatusBar

func (*StatusBar) Draw

func (s *StatusBar) Draw()

func (*StatusBar) HandleEvent

func (s *StatusBar) HandleEvent(Event) bool

func (*StatusBar) Resize

func (s *StatusBar) Resize()

func (*StatusBar) SetFail

func (s *StatusBar) SetFail()

func (*StatusBar) SetGood

func (s *StatusBar) SetGood()

func (*StatusBar) SetNormal

func (s *StatusBar) SetNormal()

func (*StatusBar) SetStatus

func (s *StatusBar) SetStatus(text string)

func (*StatusBar) SetView

func (s *StatusBar) SetView(view View)

func (*StatusBar) SetWarn

func (s *StatusBar) SetWarn()

type Style

type Style uint32

Style incorporates the various elements of a style, both foreground and background. Logically the foreground occupies the upper 16 bits, and the background the lower 16, but applications must not depend on that.

func NewStyle

func NewStyle(fg, bg Attribute) Style

func (Style) Bg

func (s Style) Bg() Attribute
func (s Style) Blink() Style

func (Style) Bold

func (s Style) Bold() Style

func (Style) Fg

func (s Style) Fg() Attribute

func (Style) Normal

func (s Style) Normal() Style

func (Style) Reverse

func (s Style) Reverse() Style

func (Style) Underline

func (s Style) Underline() Style

type TextArea

type TextArea struct {
	// contains filtered or unexported fields
}

func NewTextArea

func NewTextArea() *TextArea

func (*TextArea) Draw

func (ta *TextArea) Draw()

func (*TextArea) EnableCursor

func (ta *TextArea) EnableCursor(on bool)

func (*TextArea) HandleEvent

func (ta *TextArea) HandleEvent(ev Event) bool

func (*TextArea) HideCursor

func (ta *TextArea) HideCursor(on bool)

func (*TextArea) Resize

func (ta *TextArea) Resize()

func (*TextArea) SetContent

func (ta *TextArea) SetContent(text string)

func (*TextArea) SetLines

func (ta *TextArea) SetLines(lines []string)

func (*TextArea) SetView

func (ta *TextArea) SetView(view View)

type TextBar

type TextBar struct {
	// contains filtered or unexported fields
}

func NewTextBar

func NewTextBar() *TextBar

func (*TextBar) Draw

func (t *TextBar) Draw()

func (*TextBar) HandleEvent

func (t *TextBar) HandleEvent(Event) bool

func (*TextBar) Resize

func (t *TextBar) Resize()

func (*TextBar) SetCenter

func (t *TextBar) SetCenter(s string, style Style)

func (*TextBar) SetLeft

func (t *TextBar) SetLeft(s string, style Style)

func (*TextBar) SetRight

func (t *TextBar) SetRight(s string, style Style)

func (*TextBar) SetStyle

func (t *TextBar) SetStyle(style Style)

func (*TextBar) SetView

func (t *TextBar) SetView(view View)

type TitleBar

type TitleBar struct {
	// contains filtered or unexported fields
}

func NewTitleBar

func NewTitleBar() *TitleBar

func (*TitleBar) Draw

func (t *TitleBar) Draw()

func (*TitleBar) HandleEvent

func (t *TitleBar) HandleEvent(Event) bool

func (*TitleBar) Resize

func (t *TitleBar) Resize()

func (*TitleBar) SetCenter

func (t *TitleBar) SetCenter(s string)

func (*TitleBar) SetLeft

func (t *TitleBar) SetLeft(s string)

func (*TitleBar) SetRight

func (t *TitleBar) SetRight(s string)

func (*TitleBar) SetView

func (t *TitleBar) SetView(view View)

type View

type View interface {
	// SetCell writes a single Unicode rune to a given x/y coordinate,
	// using the specified Style.
	SetCell(x int, y int, ch rune, style Style)

	// Clear clears the visible view, by filling it with spaces using
	// the specified Style.
	Clear(style Style)

	// Size represents the visible size.  The actual content may be
	// larger or smaller.
	Size() (int, int)
}

type ViewPort

type ViewPort struct {
	// contains filtered or unexported fields
}

func NewViewPort

func NewViewPort(view View, x, y, width, height int) *ViewPort

Return a new view. The x and y coordinates are an offset relative to the parent. 0,0 represents the upper left. The width and height indicate a width and height. If the value -1 is supplied, then the dimension is calculated from the parent.

func (*ViewPort) Center

func (v *ViewPort) Center(x, y int)

This centers the point, if possible, in the view.

func (*ViewPort) Clear

func (v *ViewPort) Clear(s Style)

func (*ViewPort) GetContentSize

func (v *ViewPort) GetContentSize() (int, int)

func (*ViewPort) MakeVisible

func (v *ViewPort) MakeVisible(x, y int)

This moves the ViewPort the minimum necessary to make the given point visible.

func (*ViewPort) Reset

func (v *ViewPort) Reset()

Reset resets the record of content, and also resets the offset back to the origin. It doesn't alter the dimensions of the view port, nor the physical location relative to its parent.

func (*ViewPort) Resize

func (v *ViewPort) Resize(x, y, width, height int)

Resize is called with the new dimensions, and also the new location in the the parent.

func (*ViewPort) ScrollDown

func (v *ViewPort) ScrollDown(rows int)

func (*ViewPort) ScrollLeft

func (v *ViewPort) ScrollLeft(cols int)

func (*ViewPort) ScrollRight

func (v *ViewPort) ScrollRight(cols int)

func (*ViewPort) ScrollUp

func (v *ViewPort) ScrollUp(rows int)

func (*ViewPort) SetCell

func (v *ViewPort) SetCell(x, y int, ch rune, s Style)

func (*ViewPort) SetContentSize

func (v *ViewPort) SetContentSize(width, height int)

func (*ViewPort) SetSize

func (v *ViewPort) SetSize(width, height int)

func (*ViewPort) SetView

func (v *ViewPort) SetView(view View)

func (*ViewPort) Size

func (v *ViewPort) Size() (int, int)

func (*ViewPort) ValidateView

func (v *ViewPort) ValidateView()

ValidateView does both ValidateViewX and ValidateViewY, ensuring both offsets are valid.

func (*ViewPort) ValidateViewX

func (v *ViewPort) ValidateViewX()

ValidateViewX ensures that the X offset of the view port is limited so that it cannot scroll away from the content.

func (*ViewPort) ValidateViewY

func (v *ViewPort) ValidateViewY()

ValidateViewY ensures that the Y offset of the view port is limited so that it cannot scroll away from the content.

type Widget

type Widget interface {
	// Draw is called to inform the widget to draw itself.
	Draw()

	// Resize is called in response to a window resize.  Unlike with
	// other events, Resize performed by parents first, and they must
	// then call their children.  This is because the children need to
	// see the updated sizes from the parents before they are called.
	Resize()

	// HandleEvent is called to ask the widget to handle any events.
	// If the widget has consumed the event, it should return true.
	// Generally, events are handled by the lower layers first, that
	// is for example, a button may have a chance to handle an event
	// before the enclosing window or panel.
	HandleEvent(ev Event) bool

	// SetView is used by callers to set the visual parent of the
	// Widget.  The Widget should use the View as a context for
	// drawing.
	SetView(view View)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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