wm

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2018 License: BSD-3-Clause Imports: 12 Imported by: 2

README

wm

Package wm is a terminal window manager.

Installation

$ go get modernc.org/wm

Documentation: godoc.org/modernc.org/wm


Demo

$ go run demo.go

Screen shot (go run view_demo.go in tk/)

Documentation

Overview

Package wm is a terminal window manager.

Screenshot

An example content of a terminal window (colors cannot be shown here):

Use mouse to resize the window or scroll the view.
Arrow keys change the viewport of the focused window.
To focus the desktop, click on it.
<Esc> or 'q' to quit.

                    ┌ view_demo.go ─────────────────────────────────────────────────────[X]┐
                    │                                                                     ▴│
                    │                                                                     ░│
 ┌ view.go ─────────│Use mouse to resize the window or scroll the view.                   ░│
 │        "github.co│e the viewport of the focused window.                                ▒│
 │        "github.co│ktop, click on it.                                                   ▒│
 │)                 │quit.`                                                               ░│
 │                  │                                                                     ░│
 │// Meter provides │                                                                     ░│────[X]┐
 │type Meter interfa│'\n'}                                                                ░│      ▴│
 │        // Metrics│                                                                     ░│      ░│
 │        // result │arent *wm.Window, x, y int, title string, src []byte) {              ░│      ░│
 │        // reflect│rent.Size()                                                          ░│      ░│
 │        // values │ || y < 0 {                                                          ░│, len(░│
 │        // output │x = rand.Intn(sz.Width - sz.Width/5)                                 ░│      ░│
 │        Metrics(vi│y = rand.Intn(sz.Height - sz.Height/5)                               ░│)     ░│
 │}                 │                                                                     ░│s:%d: ░│
 │                  │ent.NewChild(wm.Rectangle{wm.Position{x, y}, wm.Size{0, 0}})         ░│      ░│
 │// View displays c│seButton(true)                                                       ░│      ░│
 │◂▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒│le(title)                                                            ░│      ░│
 └──────────────────│.HasSuffix(src, nl) {                                                ░│      ▒│
                    │src = src[:len(src)-1]                                               ░│      ▒│
                    │                                                                     ▾│OOK   ▒│
                    │◂░░░░░░░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░░░░░░░▸ │)     ▒│
                    └──────────────────────────────────────────────────────────────────────┘%d:\n"▒│

Changelog

2016-12-16: Initial release of the accompanying toolkit package: http://modernc.org/wm/tree/master/tk

2016-11-25: Windows now support views (viewports). See Windows.Origin and friends.

2015-12-11: WM now uses no locks and renders 2 to 3 times faster. The price is that any methods of Application, Desktop or Window must be called only from a function that was enqueued by Application.Post or Application.PostWait.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddOnMouseHandler

func AddOnMouseHandler(l **OnMouseHandlerList, h OnMouseHandler, finalizer func())

AddOnMouseHandler adds a handler to the handler list.

func AddOnPaintHandler

func AddOnPaintHandler(l **OnPaintHandlerList, h OnPaintHandler, finalizer func())

AddOnPaintHandler adds a handler to the handler list.

func AddOnSetBoolHandler

func AddOnSetBoolHandler(l **OnSetBoolHandlerList, h OnSetBoolHandler, finalizer func())

AddOnSetBoolHandler adds a handler to the handler list.

func AddOnSetIntHandler

func AddOnSetIntHandler(l **OnSetIntHandlerList, h OnSetIntHandler, finalizer func())

AddOnSetIntHandler adds a handler to the handler list.

func AddOnSetPositionHandler

func AddOnSetPositionHandler(l **OnSetPositionHandlerList, h OnSetPositionHandler, finalizer func())

AddOnSetPositionHandler adds a handler to the handler list.

func AddOnSetSizeHandler

func AddOnSetSizeHandler(l **OnSetSizeHandlerList, h OnSetSizeHandler, finalizer func())

AddOnSetSizeHandler adds a handler to the handler list.

func AddOnSetStyleHandler

func AddOnSetStyleHandler(l **OnSetStyleHandlerList, h OnSetStyleHandler, finalizer func())

AddOnSetStyleHandler adds a handler to the handler list.

func RemoveOnMouseHandler

func RemoveOnMouseHandler(l **OnMouseHandlerList)

RemoveOnMouseHandler undoes the most recent call to AddOnMouseHandler.

func RemoveOnPaintHandler

func RemoveOnPaintHandler(l **OnPaintHandlerList)

RemoveOnPaintHandler undoes the most recent call to AddOnPaintHandler.

func RemoveOnSetBoolHandler

func RemoveOnSetBoolHandler(l **OnSetBoolHandlerList)

RemoveOnSetBoolHandler undoes the most recent call to AddOnSetBoolHandler.

func RemoveOnSetIntHandler

func RemoveOnSetIntHandler(l **OnSetIntHandlerList)

RemoveOnSetIntHandler undoes the most recent call to AddOnSetIntHandler.

func RemoveOnSetPositionHandler

func RemoveOnSetPositionHandler(l **OnSetPositionHandlerList)

RemoveOnSetPositionHandler undoes the most recent call to AddOnSetPositionHandler.

func RemoveOnSetSizeHandler

func RemoveOnSetSizeHandler(l **OnSetSizeHandlerList)

RemoveOnSetSizeHandler undoes the most recent call to AddOnSetSizeHandler.

func RemoveOnSetStyleHandler

func RemoveOnSetStyleHandler(l **OnSetStyleHandlerList)

RemoveOnSetStyleHandler undoes the most recent call to AddOnSetStyleHandler.

Types

type Application

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

Application represents an interactive terminal application.

Application methods must be called only directly from an event handler goroutine or from a function that was enqueued using Application.Post or Application.PostWait. The only exception is Application.Wait, it can be called from any goroutine.

var (
	// App is the instance of Application created by NewApplication.
	App *Application
)

func NewApplication

func NewApplication(theme *Theme) (*Application, error)

NewApplication returns a newly created Application or an error, if any.

// Skeleton example.
func main() {
	app, err := wm.NewApplication(theme)
	if err != nil {
		log.Fatalf("error: %v", err)
	}

	...

	if err = app.Wait(); err != nil {
		log.Fatal(err)
	}
}

Calling this function more than once will panic.

func (*Application) BeginUpdate

func (a *Application) BeginUpdate()

BeginUpdate marks the start of one or more updates to the application screen.

Failing to properly pair BeginUpdate with a corresponding EndUpdate will cause application screen corruption and/or freeze.

func (*Application) ChildWindowStyle

func (a *Application) ChildWindowStyle() WindowStyle

ChildWindowStyle returns the style assigned to new child windows.

func (*Application) ClickDuration

func (a *Application) ClickDuration() time.Duration

ClickDuration returns the maximum duration of a single click. Holding a mouse button for any longer duration generates a drag event instead.

func (*Application) Colors

func (a *Application) Colors() int

Colors returns the number of colors the host terminal supports. All colors are assumed to use the ANSI color map. If a terminal is monochrome, it will return 0.

func (*Application) Desktop

func (a *Application) Desktop() (d *Desktop)

Desktop returns the currently active desktop.

func (*Application) DesktopStyle

func (a *Application) DesktopStyle() WindowStyle

DesktopStyle returns the style assigned to new desktops.

func (*Application) DoubleClickDuration

func (a *Application) DoubleClickDuration() time.Duration

DoubleClickDuration returns the maximum duration of a double click. Mouse click not followed by another one within the DoubleClickDuration is a single click.

func (*Application) EndUpdate

func (a *Application) EndUpdate()

EndUpdate marks the end of one or more updates to the application screen.

Failing to properly pair BeginUpdate with a corresponding EndUpdate will cause application screen corruption and/or freeze.

func (*Application) Exit

func (a *Application) Exit(err error)

Exit terminates the interactive terminal application and returns err from Wait(). Only the first call of this method is considered.

func (*Application) NewDesktop

func (a *Application) NewDesktop() *Desktop

NewDesktop returns a newly created desktop.

func (*Application) OnKey

func (a *Application) OnKey(h OnKeyHandler, finalize func())

OnKey sets a key event handler. When the event handler is removed, finalize is called, if not nil.

func (*Application) OnSetClickDuration

func (a *Application) OnSetClickDuration(h OnSetDurationHandler, finalize func())

OnSetClickDuration sets a handler invoked on SetClickDuration. When the event handler is removed, finalize is called, if not nil.

func (*Application) OnSetDesktop

func (a *Application) OnSetDesktop(h OnSetDesktopHandler, finalize func())

OnSetDesktop sets a handler invoked on SetDesktop. When the event handler is removed, finalize is called, if not nil.

func (*Application) OnSetDoubleClickDuration

func (a *Application) OnSetDoubleClickDuration(h OnSetDurationHandler, finalize func())

OnSetDoubleClickDuration sets a handler invoked on SetDoubleClickDuration. When the event handler is removed, finalize is called, if not nil.

func (*Application) OnSetSize

func (a *Application) OnSetSize(h OnSetSizeHandler, finalize func())

OnSetSize sets a handler invoked on resizing the application screen. When the event handler is removed, finalize is called, if not nil.

func (*Application) Post

func (a *Application) Post(f func())

Post puts f in the event queue, if the queue is not full, and executes it on dequeuing the event.

func (*Application) PostWait

func (a *Application) PostWait(f func())

PostWait puts f in the event queue and executes it on dequeuing the event.

func (*Application) RemoveOnKey

func (a *Application) RemoveOnKey()

RemoveOnKey undoes the most recent OnKey call. The function will panic if there is no handler set.

func (*Application) RemoveOnSetClickDuration

func (a *Application) RemoveOnSetClickDuration()

RemoveOnSetClickDuration undoes the most recent OnSetClickDuration call. The function will panic if there is no handler set.

func (*Application) RemoveOnSetDesktop

func (a *Application) RemoveOnSetDesktop()

RemoveOnSetDesktop undoes the most recent OnSetDesktop call. The function will panic if there is no handler set.

func (*Application) RemoveOnSetDoubleClickDuration

func (a *Application) RemoveOnSetDoubleClickDuration()

RemoveOnSetDoubleClickDuration undoes the most recent OnSetDoubleClickDuration call. The function will panic if there is no handler set.

func (*Application) RemoveOnSetSize

func (a *Application) RemoveOnSetSize()

RemoveOnSetSize undoes the most recent OnSetSize call. The function will panic if there is no handler set.

func (*Application) Run

func (a *Application) Run(setup func()) error

Run is a shorthand for

app.PostWait(setup)
return app.Wait()

func (*Application) SetClickDuration

func (a *Application) SetClickDuration(d time.Duration)

SetClickDuration sets the maximum duration of a single click. Holding a mouse button for any longer duration generates a drag event instead.

func (*Application) SetDesktop

func (a *Application) SetDesktop(d *Desktop)

SetDesktop sets the currently active desktop. Passing nil d will panic.

func (*Application) SetDoubleClickDuration

func (a *Application) SetDoubleClickDuration(d time.Duration)

SetDoubleClickDuration sets the maximum duration of a single click. Mouse click not followed by another one within the DoubleClickDuration is a single click.

Note: Setting DoubleClickDuration to zero disables double click support.

func (*Application) Size

func (a *Application) Size() (s Size)

Size returns the size of the terminal the application runs in.

func (*Application) Sync

func (a *Application) Sync()

Sync updates every character cell of the application screen.

func (*Application) Wait

func (a *Application) Wait() error

Wait blocks until the interactive terminal application terminates.

Calling this method more than once will panic.

type Desktop

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

Desktop represents a virtual screen. An application has one or more independent desktops, of which only one is visible at any given moment.

A desktop initially contains only the automatically created root window.

Desktop methods must be called only directly from an event handler goroutine or from a function that was enqueued using Application.Post or Application.PostWait.

func (*Desktop) FocusedWindow

func (d *Desktop) FocusedWindow() *Window

FocusedWindow returns the window with focus, if any.

func (*Desktop) OnSetFocusedWindow

func (d *Desktop) OnSetFocusedWindow(h OnSetWindowHandler, finalize func())

OnSetFocusedWindow sets a handler invoked on SetFocusedWindow. When the event handler is removed, finalize is called, if not nil.

func (*Desktop) OnSetSelection

func (d *Desktop) OnSetSelection(h OnSetRectangleHandler, finalize func())

OnSetSelection sets a handler invoked on SetSelection. When the event handler is removed, finalize is called, if not nil.

func (*Desktop) RemoveOnSetFocusedWindow

func (d *Desktop) RemoveOnSetFocusedWindow()

RemoveOnSetFocusedWindow undoes the most recent OnSetFocusedWindow call. The function will panic if there is no handler set.

func (*Desktop) RemoveOnSetSelection

func (d *Desktop) RemoveOnSetSelection()

RemoveOnSetSelection undoes the most recent OnSetSelection call. The function will panic if there is no handler set.

func (*Desktop) Root

func (d *Desktop) Root() *Window

Root returns the root window of d.

func (*Desktop) Selection

func (d *Desktop) Selection() Rectangle

Selection returns the area of the desktop shown in reverse.

func (*Desktop) SetFocusedWindow

func (d *Desktop) SetFocusedWindow(w *Window)

SetFocusedWindow sets the focused window.

func (*Desktop) SetSelection

func (d *Desktop) SetSelection(area Rectangle)

SetSelection sets the area of the desktop shown in reverse.

func (*Desktop) Show

func (d *Desktop) Show()

Show sets d as the application active desktop.

type OnCloseHandler

type OnCloseHandler func(w *Window, prev OnCloseHandler)

OnCloseHandler is called on window close. If there was a previous handler installed, it's passed in prev. The handler then has the opportunity to call the previous handler before or after its own execution.

type OnKeyHandler

type OnKeyHandler func(w *Window, prev OnKeyHandler, key tcell.Key, mod tcell.ModMask, r rune) bool

OnKeyHandler handles key events. If there was a previous handler installed, it's passed in prev. The handler then has the opportunity to call the previous handler before or after its own execution. The handler should return true if it consumes the event and it should not be considered by other subscribed handlers.

type OnMouseHandler

type OnMouseHandler func(w *Window, prev OnMouseHandler, button tcell.ButtonMask, screenPos, winPos Position, mods tcell.ModMask) bool

OnMouseHandler handles mouse events. If there was a previous handler installed, it's passed in prev. The handler then has the opportunity to call the previous handler before or after its own execution. The handler should return true if it consumes the event and it should not be considered by other subscribed handlers.

type OnMouseHandlerList

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

OnMouseHandlerList represents a list of handlers subscribed to an event.

func (*OnMouseHandlerList) Clear

func (l *OnMouseHandlerList) Clear()

Clear calls any finalizers on the handler list.

func (*OnMouseHandlerList) Handle

func (l *OnMouseHandlerList) Handle(w *Window, button tcell.ButtonMask, screenPos, winPos Position, mods tcell.ModMask) bool

Handle performs handling mouse events.

type OnPaintHandler

type OnPaintHandler func(w *Window, prev OnPaintHandler, ctx PaintContext)

OnPaintHandler handles paint requests. If there was a previous handler installed, it's passed in prev. The handler then has the opportunity to call the previous handler before or after its own execution.

OnPaint handlers can safely try to modify window cells outside of the area argument as such attempts will be silently ignored. In other words, an OnPaintHandler cannot affect any window cell outside of the area argument.

type OnPaintHandlerList

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

OnPaintHandlerList represents a list of handlers subscribed to an event.

func (*OnPaintHandlerList) Clear

func (l *OnPaintHandlerList) Clear()

Clear calls any finalizers on the handler list.

func (*OnPaintHandlerList) Handle

func (l *OnPaintHandlerList) Handle(w *Window, ctx PaintContext)

Handle performs painting of ctx.

type OnSetBoolHandler

type OnSetBoolHandler func(w *Window, prev OnSetBoolHandler, dst *bool, src bool)

OnSetBoolHandler handles requests to change values of type bool. If there was a previous handler installed, it's passed in prev. The handler then has the opportunity to call the previous handler before or after its own execution.

type OnSetBoolHandlerList

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

OnSetBoolHandlerList represents a list of handlers subscribed to an event.

func (*OnSetBoolHandlerList) Clear

func (l *OnSetBoolHandlerList) Clear()

Clear calls any finalizers on the handler list.

func (*OnSetBoolHandlerList) Handle

func (l *OnSetBoolHandlerList) Handle(w *Window, dst *bool, src bool)

Handle performs updating of dst from src or calling and associated handler.

type OnSetDesktopHandler

type OnSetDesktopHandler func(w *Window, prev OnSetDesktopHandler, dst **Desktop, src *Desktop)

OnSetDesktopHandler handles requests to change values of type *Desktop. If there was a previous handler installed, it's passed in prev. The handler then has the opportunity to call the previous handler before or after its own execution.

type OnSetDurationHandler

type OnSetDurationHandler func(w *Window, prev OnSetDurationHandler, dst *time.Duration, src time.Duration)

OnSetDurationHandler handles requests to change values of type time.Duration. If there was a previous handler installed, it's passed in prev. The handler then has the opportunity to call the previous handler before or after its own execution.

type OnSetIntHandler

type OnSetIntHandler func(w *Window, prev OnSetIntHandler, dst *int, src int)

OnSetIntHandler handles requests to change values of type int. If there was a previous handler installed, it's passed in prev. The handler then has the opportunity to call the previous handler before or after its own execution.

type OnSetIntHandlerList

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

OnSetIntHandlerList represents a list of handlers subscribed to an event.

func (*OnSetIntHandlerList) Clear

func (l *OnSetIntHandlerList) Clear()

Clear calls any finalizers on the handler list.

func (*OnSetIntHandlerList) Handle

func (l *OnSetIntHandlerList) Handle(w *Window, dst *int, src int)

Handle performs updating of dst from src or calling and associated handler.

type OnSetPositionHandler

type OnSetPositionHandler func(w *Window, prev OnSetPositionHandler, dst *Position, src Position)

OnSetPositionHandler handles requests to change values of type Position. If there was a previous handler installed, it's passed in prev. The handler then has the opportunity to call the previous handler before or after its own execution.

type OnSetPositionHandlerList

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

OnSetPositionHandlerList represents a list of handlers subscribed to an event.

func (*OnSetPositionHandlerList) Clear

func (l *OnSetPositionHandlerList) Clear()

Clear calls any finalizers on the handler list.

func (*OnSetPositionHandlerList) Handle

func (l *OnSetPositionHandlerList) Handle(w *Window, dst *Position, src Position)

Handle performs updating of dst from src or calling and associated handler.

type OnSetRectangleHandler

type OnSetRectangleHandler func(w *Window, prev OnSetRectangleHandler, dst *Rectangle, src Rectangle)

OnSetRectangleHandler handles requests to change values of type Rectangle. If there was a previous handler installed, it's passed in prev. The handler then has the opportunity to call the previous handler before or after its own execution.

type OnSetSizeHandler

type OnSetSizeHandler func(w *Window, prev OnSetSizeHandler, dst *Size, src Size)

OnSetSizeHandler handles requests to change values of type Size. If there was a previous handler installed, it's passed in prev. The handler then has the opportunity to call the previous handler before or after its own execution.

type OnSetSizeHandlerList

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

OnSetSizeHandlerList represents a list of handlers subscribed to an event.

func (*OnSetSizeHandlerList) Clear

func (l *OnSetSizeHandlerList) Clear()

Clear calls any finalizers on the handler list.

func (*OnSetSizeHandlerList) Handle

func (l *OnSetSizeHandlerList) Handle(w *Window, dst *Size, src Size)

Handle performs updating of dst from src or calling and associated handler.

type OnSetStringHandler

type OnSetStringHandler func(w *Window, prev OnSetStringHandler, dst *string, src string)

OnSetStringHandler handles requests to change values of type String. If there was a previous handler installed, it's passed in prev. The handler then has the opportunity to call the previous handler before or after its own execution.

type OnSetStyleHandler

type OnSetStyleHandler func(w *Window, prev OnSetStyleHandler, dst *Style, src Style)

OnSetStyleHandler handles requests to change values of type Style. If there was a previous handler installed, it's passed in prev. The handler then has the opportunity to call the previous handler before or after its own execution.

type OnSetStyleHandlerList

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

OnSetStyleHandlerList represents a list of handlers subscribed to an event.

func (*OnSetStyleHandlerList) Clear

func (l *OnSetStyleHandlerList) Clear()

Clear calls any finalizers on the handler list.

func (*OnSetStyleHandlerList) Handle

func (l *OnSetStyleHandlerList) Handle(w *Window, dst *Style, src Style)

Handle performs updating of dst from src or calling and associated handler.

type OnSetWindowHandler

type OnSetWindowHandler func(w *Window, prev OnSetWindowHandler, dst **Window, src *Window)

OnSetWindowHandler handles requests to change values of type *Window. If there was a previous handler installed, it's passed in prev. The handler then has the opportunity to call the previous handler before or after its own execution.

type OnSetWindowStyleHandler

type OnSetWindowStyleHandler func(w *Window, prev OnSetWindowStyleHandler, dst *WindowStyle, src WindowStyle)

OnSetWindowStyleHandler handles requests to change values of type WindowStyle. If there was a previous handler installed, it's passed in prev. The handler then has the opportunity to call the previous handler before or after its own execution.

type PaintContext

type PaintContext struct {
	Rectangle
	// contains filtered or unexported fields
}

PaintContext represents the context passed to paint handlers.

type Position

type Position struct {
	X, Y int
}

Position represents 2D coordinates.

func (Position) In

func (p Position) In(r Rectangle) bool

In returns whether p is inside r.

type Rectangle

type Rectangle struct {
	Position
	Size
}

Rectangle represents a 2D area.

func NewRectangle

func NewRectangle(x1, y1, x2, y2 int) Rectangle

NewRectangle returns a Rectangle from 4 coordinates.

func (*Rectangle) Clip

func (r *Rectangle) Clip(s Rectangle) bool

Clip sets r to the intersection of r and s and returns a boolean value indicating whether the result is of non zero size.

func (*Rectangle) Has

func (r *Rectangle) Has(p Position) bool

Has returns whether r contains p.

type Size

type Size struct {
	Width, Height int
}

Size represents 2D dimensions.

func (*Size) IsZero

func (s *Size) IsZero() bool

IsZero returns whether s.Width or s.Height is zero.

type Style

type Style struct {
	Foreground tcell.Color
	Background tcell.Color
	Attr       tcell.AttrMask
}

Style represents a text style.

func NewStyle

func NewStyle(s tcell.Style) Style

NewStyle returns Style having values filled from s.

func (*Style) IsZero

func (s *Style) IsZero() bool

IsZero returns whether s is the zero value of Style.

func (Style) TCellStyle

func (s Style) TCellStyle() tcell.Style

TCellStyle converts a Style to a tcell.Style value.

type Theme

type Theme struct {
	ChildWindow WindowStyle
	Desktop     WindowStyle
}

Theme represents visual styles of UI elements.

func (*Theme) Clear

func (t *Theme) Clear()

Clear sets t to its zero value.

func (*Theme) ReadFrom

func (t *Theme) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads t from r in JSON format. Values of fields having no JSON data are preserved.

func (*Theme) WriteTo

func (t *Theme) WriteTo(w io.Writer) (int64, error)

WriteTo writes t to w in JSON format.

type Window

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

Window represents a rectangular area of a screen. A window can have borders on all of its sides and a title.

Window methods must be called only directly from an event handler goroutine or from a function that was enqueued using Application.Post or Application.PostWait.

func (*Window) Area

func (w *Window) Area() Rectangle

Area returns the area of the window.

func (*Window) BeginUpdate

func (w *Window) BeginUpdate()

BeginUpdate marks the start of one or more updates to w.

Failing to properly pair BeginUpdate with a corresponding EndUpdate will cause application screen corruption and/or freeze.

func (*Window) BorderBottom

func (w *Window) BorderBottom() int

BorderBottom returns the height of the bottom border.

func (*Window) BorderBottomArea

func (w *Window) BorderBottomArea() (r Rectangle)

BorderBottomArea returns the area of the bottom border.

func (*Window) BorderLeft

func (w *Window) BorderLeft() int

BorderLeft returns the width of the left border.

func (*Window) BorderLeftArea

func (w *Window) BorderLeftArea() (r Rectangle)

BorderLeftArea returns the area of the left border.

func (*Window) BorderRight

func (w *Window) BorderRight() int

BorderRight returns the width of the right border.

func (*Window) BorderRightArea

func (w *Window) BorderRightArea() (r Rectangle)

BorderRightArea returns the area of the right border.

func (*Window) BorderStyle

func (w *Window) BorderStyle() Style

BorderStyle returns the border style.

func (*Window) BorderTop

func (w *Window) BorderTop() int

BorderTop returns the height of the top border.

func (*Window) BorderTopArea

func (w *Window) BorderTopArea() (r Rectangle)

BorderTopArea returns the area of the top border.

func (*Window) BringToFront

func (w *Window) BringToFront()

BringToFront puts a child window on top of all its siblings. The method has no effect if w is a root window.

func (*Window) Child

func (w *Window) Child(n int) (r *Window)

Child returns the nth child window or nil if no such exists.

func (*Window) Children

func (w *Window) Children() (r int)

Children returns the number of child windows.

func (*Window) ClientArea

func (w *Window) ClientArea() Rectangle

ClientArea returns the client area.

func (*Window) ClientAreaStyle

func (w *Window) ClientAreaStyle() Style

ClientAreaStyle returns the client area style.

func (*Window) ClientPosition

func (w *Window) ClientPosition() Position

ClientPosition returns the position of the client area relative to w.

func (*Window) ClientSize

func (w *Window) ClientSize() Size

ClientSize returns the size of the client area.

func (*Window) Close

func (w *Window) Close()

Close closes w.

func (*Window) CloseButton

func (w *Window) CloseButton() bool

CloseButton returns whether the window shows a close button.

func (*Window) Desktop

func (w *Window) Desktop() *Desktop

Desktop returns which Desktop w appears on.

func (*Window) EndUpdate

func (w *Window) EndUpdate()

EndUpdate marks the end of one or more updates to w.

Failing to properly pair BeginUpdate with a corresponding EndUpdate will cause application screen corruption and/or freeze.

func (*Window) Focus

func (w *Window) Focus() bool

Focus returns wheter the window is focused.

func (*Window) Invalidate

func (w *Window) Invalidate(area Rectangle)

Invalidate marks a window area for repaint.

func (*Window) InvalidateClientArea

func (w *Window) InvalidateClientArea(area Rectangle)

InvalidateClientArea marks an area of the client area for repaint.

func (*Window) NewChild

func (w *Window) NewChild(area Rectangle) *Window

NewChild creates a child window.

func (*Window) OnClick

func (w *Window) OnClick(h OnMouseHandler, finalize func())

OnClick sets a mouse click event handler. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnClickBorder

func (w *Window) OnClickBorder(h OnMouseHandler, finalize func())

OnClickBorder sets a mouse click border event handler. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnClose

func (w *Window) OnClose(h OnCloseHandler, finalize func())

OnClose sets a window close event handler. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnDoubleClick

func (w *Window) OnDoubleClick(h OnMouseHandler, finalize func())

OnDoubleClick sets a mouse double click event handler. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnDoubleClickBorder

func (w *Window) OnDoubleClickBorder(h OnMouseHandler, finalize func())

OnDoubleClickBorder sets a mouse double click border event handler. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnDrag

func (w *Window) OnDrag(h OnMouseHandler, finalize func())

OnDrag sets a mouse drag event handler. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnDragBorder

func (w *Window) OnDragBorder(h OnMouseHandler, finalize func())

OnDragBorder sets a mouse drag border event handler. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnDrop

func (w *Window) OnDrop(h OnMouseHandler, finalize func())

OnDrop sets a mouse drop event handler. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnKey

func (w *Window) OnKey(h OnKeyHandler, finalize func())

OnKey sets a key event handler. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnMouseMove

func (w *Window) OnMouseMove(h OnMouseHandler, finalize func())

OnMouseMove sets a mouse move event handler. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnPaintBorderBottom

func (w *Window) OnPaintBorderBottom(h OnPaintHandler, finalize func())

OnPaintBorderBottom sets a bottom border paint handler. When the event handler is removed, finalize is called, if not nil. Example:

func onPaintBorderBottom(w *wm.Window, prev wm.OnPaintHandler, area wm.Rectangle) {
	if prev != nil {
		prev(w, nil, area)
	}
	style := w.Style().TCellStyle()
	w := w.BorderBottomArea().Width
	for x := 0; x < w; x++ {
		var r rune
		switch x {
		case 0:
			r = tcell.RuneLLCorner
		case w - 1:
			r = tcell.RuneLRCorner
		default:
			r = tcell.RuneHLine
		}
		w.SetCell(x, 0, r, nil, style)
	}
}

...

w.OnPaintBorderBottom(onPaintBorderBottom, nil)
w.SetBorderBottom(1)

func (*Window) OnPaintBorderLeft

func (w *Window) OnPaintBorderLeft(h OnPaintHandler, finalize func())

OnPaintBorderLeft sets a left border paint handler. When the event handler is removed, finalize is called, if not nil. Example:

func onPaintBorderLeft(w *wm.Window, prev wm.OnPaintHandler, area wm.Rectangle) {
	if prev != nil {
		prev(w, nil, area)
	}
	style := w.Style().TCellStyle()
	h := w.BorderLeftArea().Height
	for y := 0; y < h; y++ {
		var r rune
		switch y {
		case 0:
			r = tcell.RuneULCorner
		case h - 1:
			r = tcell.RuneLLCorner
		default:
			r = tcell.RuneVLine
		}
		w.SetCell(0, y, r, nil, style)
	}
}

...

w.OnPaintBorderLeft(onPaintBorderLeft, nil)
w.SetBorderLeft(1)

func (*Window) OnPaintBorderRight

func (w *Window) OnPaintBorderRight(h OnPaintHandler, finalize func())

OnPaintBorderRight sets a right border paint handler. When the event handler is removed, finalize is called, if not nil. Example:

func onPaintBorderRight(w *wm.Window, prev wm.OnPaintHandler, area wm.Rectangle) {
	if prev != nil {
		prev(w, nil, area)
	}
	style := w.Style().TCellStyle()
	h := w.BorderRightArea().Height
	for y := 0; y < h; y++ {
		var r rune
		switch y {
		case 0:
			r = tcell.RuneURCorner
		case h - 1:
			r = tcell.RuneLRCorner
		default:
			r = tcell.RuneVLine
		}
		w.SetCell(0, y, r, nil, style)
	}
}

...

w.OnPaintBorderRight(onPaintBorderRight, nil)
w.SetBorderRight(1)

func (*Window) OnPaintBorderTop

func (w *Window) OnPaintBorderTop(h OnPaintHandler, finalize func())

OnPaintBorderTop sets a top border paint handler. When the event handler is removed, finalize is called, if not nil. Example:

func onPaintBorderTop(w *wm.Window, prev wm.OnPaintHandler, area wm.Rectangle) {
	if prev != nil {
		prev(w, nil, area)
	}
	style := w.Style().TCellStyle()
	w := w.BorderTopArea().Width
	for x := 0; x < w; x++ {
		var r rune
		switch x {
		case 0:
			r = tcell.RuneULCorner
		case w - 1:
			r = tcell.RuneURCorner
		default:
			r = tcell.RuneHLine
		}
		w.SetCell(x, 0, r, nil, style)
	}
}

...

w.OnPaintBorderTop(onPaintBorderTop, nil)
w.SetBorderTop(1)

func (*Window) OnPaintClientArea

func (w *Window) OnPaintClientArea(h OnPaintHandler, finalize func())

OnPaintClientArea sets a client area paint handler. When the event handler is removed, finalize is called, if not nil. Example:

func onPaintClientArea(w *wm.Window, prev wm.OnPaintHandler, area wm.Rectangle) {
	if prev != nil {
		prev(w, nil, area)
	}
	w.Printf(0, 0, w.Style(), "Hello 世界!\nTime: %s", time.Now())
}

...

w.OnPaintClientArea(onPaintClientArea, nil)

func (*Window) OnPaintTitle

func (w *Window) OnPaintTitle(h OnPaintHandler, finalize func())

OnPaintTitle sets a window title paint handler. When the event handler is removed, finalize is called, if not nil. Example:

if s := w.Title(); s != "" {
	w.Printf(0, 0, w.Style().Title, " %s ", s)
}

func (*Window) OnSetBorderBottom

func (w *Window) OnSetBorderBottom(h OnSetIntHandler, finalize func())

OnSetBorderBottom sets a handler invoked on SetBorderBottom. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnSetBorderLeft

func (w *Window) OnSetBorderLeft(h OnSetIntHandler, finalize func())

OnSetBorderLeft sets a handler invoked on SetBorderLeft. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnSetBorderRight

func (w *Window) OnSetBorderRight(h OnSetIntHandler, finalize func())

OnSetBorderRight sets a handler invoked on SetBorderRight. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnSetBorderStyle

func (w *Window) OnSetBorderStyle(h OnSetStyleHandler, finalize func())

OnSetBorderStyle sets a handler invoked on SetBorderStyle. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnSetBorderTop

func (w *Window) OnSetBorderTop(h OnSetIntHandler, finalize func())

OnSetBorderTop sets a handler invoked on SetBorderTop. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnSetClientAreaStyle

func (w *Window) OnSetClientAreaStyle(h OnSetStyleHandler, finalize func())

OnSetClientAreaStyle sets a handler invoked on SetClientAreaStyle. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnSetClientSize

func (w *Window) OnSetClientSize(h OnSetSizeHandler, finalize func())

OnSetClientSize sets a handler invoked on SetClientSize. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnSetCloseButton

func (w *Window) OnSetCloseButton(h OnSetBoolHandler, finalize func())

OnSetCloseButton sets a handler invoked on SetCloseButton. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnSetFocus

func (w *Window) OnSetFocus(h OnSetBoolHandler, finalize func())

OnSetFocus sets a handler invoked on SetFocus. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnSetOrigin

func (w *Window) OnSetOrigin(h OnSetPositionHandler, finalize func())

OnSetOrigin sets a handler invoked on SetOrigin. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnSetPosition

func (w *Window) OnSetPosition(h OnSetPositionHandler, finalize func())

OnSetPosition sets a handler invoked on SetPosition. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnSetSize

func (w *Window) OnSetSize(h OnSetSizeHandler, finalize func())

OnSetSize sets a handler invoked on SetSize. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnSetStyle

func (w *Window) OnSetStyle(h OnSetWindowStyleHandler, finalize func())

OnSetStyle sets a handler invoked on SetStyle. When the event handler is removed, finalize is called, if not nil.

func (*Window) OnSetTitle

func (w *Window) OnSetTitle(h OnSetStringHandler, finalize func())

OnSetTitle sets a handler invoked on SetTitle. When the event handler is removed, finalize is called, if not nil.

func (*Window) Origin

func (w *Window) Origin() Position

Origin returns the window's origin..

func (*Window) Parent

func (w *Window) Parent() *Window

Parent returns the window's parent. Root windows have nil parent.

func (*Window) Position

func (w *Window) Position() Position

Position returns the window position relative to its parent.

func (*Window) Printf

func (w *Window) Printf(x, y int, style Style, format string, arg ...interface{})

Printf prints format with arguments at x, y. Calling this method outside of an OnPaint handler is ignored.

Special handling:

'\t'	x, y = x + 8 - x%8, y
'\n'	x, y = 0, y+1
'\r'	x, y = 0, y

func (*Window) RemoveOnClick

func (w *Window) RemoveOnClick()

RemoveOnClick undoes the most recent OnClick call. The function will panic if there is no handler set.

func (*Window) RemoveOnClickBorder

func (w *Window) RemoveOnClickBorder()

RemoveOnClickBorder undoes the most recent OnClickBorder call. The function will panic if there is no handler set.

func (*Window) RemoveOnClose

func (w *Window) RemoveOnClose()

RemoveOnClose undoes the most recent OnClose call. The function will panic if there is no handler set.

func (*Window) RemoveOnDoubleClick

func (w *Window) RemoveOnDoubleClick()

RemoveOnDoubleClick undoes the most recent OnDoubleClick call. The function will panic if there is no handler set.

func (*Window) RemoveOnDoubleClickBorder

func (w *Window) RemoveOnDoubleClickBorder()

RemoveOnDoubleClickBorder undoes the most recent OnDoubleClickBorder call. The function will panic if there is no handler set.

func (*Window) RemoveOnDrag

func (w *Window) RemoveOnDrag()

RemoveOnDrag undoes the most recent OnDrag call. The function will panic if there is no handler set.

func (*Window) RemoveOnDragBorder

func (w *Window) RemoveOnDragBorder()

RemoveOnDragBorder undoes the most recent OnDragBorder call. The function will panic if there is no handler set.

func (*Window) RemoveOnDrop

func (w *Window) RemoveOnDrop()

RemoveOnDrop undoes the most recent OnDrop call. The function will panic if there is no handler set.

func (*Window) RemoveOnKey

func (w *Window) RemoveOnKey()

RemoveOnKey undoes the most recent OnKey call. The function will panic if there is no handler set.

func (*Window) RemoveOnMouseMove

func (w *Window) RemoveOnMouseMove()

RemoveOnMouseMove undoes the most recent OnMouseMove call. The function will panic if there is no handler set.

func (*Window) RemoveOnPaintBorderBottom

func (w *Window) RemoveOnPaintBorderBottom()

RemoveOnPaintBorderBottom undoes the most recent OnPaintBorderBottom call. The function will panic if there is no handler set.

func (*Window) RemoveOnPaintBorderLeft

func (w *Window) RemoveOnPaintBorderLeft()

RemoveOnPaintBorderLeft undoes the most recent OnPaintBorderLeft call. The function will panic if there is no handler set.

func (*Window) RemoveOnPaintBorderRight

func (w *Window) RemoveOnPaintBorderRight()

RemoveOnPaintBorderRight undoes the most recent OnPaintBorderRight call. The function will panic if there is no handler set.

func (*Window) RemoveOnPaintBorderTop

func (w *Window) RemoveOnPaintBorderTop()

RemoveOnPaintBorderTop undoes the most recent OnPaintBorderTop call. The function will panic if there is no handler set.

func (*Window) RemoveOnPaintClientArea

func (w *Window) RemoveOnPaintClientArea()

RemoveOnPaintClientArea undoes the most recent OnPaintClientArea call. The function will panic if there is no handler set.

func (*Window) RemoveOnPaintTitle

func (w *Window) RemoveOnPaintTitle()

RemoveOnPaintTitle undoes the most recent OnPaintTitle call. The function will panic if there is no handler set.

func (*Window) RemoveOnSetBorderBottom

func (w *Window) RemoveOnSetBorderBottom()

RemoveOnSetBorderBottom undoes the most recent OnSetBorderBottom call. The function will panic if there is no handler set.

func (*Window) RemoveOnSetBorderLeft

func (w *Window) RemoveOnSetBorderLeft()

RemoveOnSetBorderLeft undoes the most recent OnSetBorderLeft call. The function will panic if there is no handler set.

func (*Window) RemoveOnSetBorderRight

func (w *Window) RemoveOnSetBorderRight()

RemoveOnSetBorderRight undoes the most recent OnSetBorderRight call. The function will panic if there is no handler set.

func (*Window) RemoveOnSetBorderStyle

func (w *Window) RemoveOnSetBorderStyle()

RemoveOnSetBorderStyle undoes the most recent OnSetBorderStyle call. The function will panic if there is no handler set.

func (*Window) RemoveOnSetBorderTop

func (w *Window) RemoveOnSetBorderTop()

RemoveOnSetBorderTop undoes the most recent OnSetBorderTop call. The function will panic if there is no handler set.

func (*Window) RemoveOnSetClientAreaStyle

func (w *Window) RemoveOnSetClientAreaStyle()

RemoveOnSetClientAreaStyle undoes the most recent OnSetClientAreaStyle call. The function will panic if there is no handler set.

func (*Window) RemoveOnSetClientSize

func (w *Window) RemoveOnSetClientSize()

RemoveOnSetClientSize undoes the most recent OnSetClientSize call. The function will panic if there is no handler set.

func (*Window) RemoveOnSetCloseButton

func (w *Window) RemoveOnSetCloseButton()

RemoveOnSetCloseButton undoes the most recent OnSetCloseButton call. The function will panic if there is no handler set.

func (*Window) RemoveOnSetFocus

func (w *Window) RemoveOnSetFocus()

RemoveOnSetFocus undoes the most recent OnSetFocus call. The function will panic if there is no handler set.

func (*Window) RemoveOnSetOrigin

func (w *Window) RemoveOnSetOrigin()

RemoveOnSetOrigin undoes the most recent OnSetOrigin call. The function will panic if there is no handler set.

func (*Window) RemoveOnSetPosition

func (w *Window) RemoveOnSetPosition()

RemoveOnSetPosition undoes the most recent OnSetPosition call. The function will panic if there is no handler set.

func (*Window) RemoveOnSetSize

func (w *Window) RemoveOnSetSize()

RemoveOnSetSize undoes the most recent OnSetSize call. The function will panic if there is no handler set.

func (*Window) RemoveOnSetStyle

func (w *Window) RemoveOnSetStyle()

RemoveOnSetStyle undoes the most recent OnSetStyle call. The function will panic if there is no handler set.

func (*Window) RemoveOnSetTitle

func (w *Window) RemoveOnSetTitle()

RemoveOnSetTitle undoes the most recent OnSetTitle call. The function will panic if there is no handler set.

func (*Window) Rendered

func (w *Window) Rendered() time.Duration

Rendered returns how long the last desktop rendering took. Valid only for desktop's root window.

func (*Window) SetBorderBottom

func (w *Window) SetBorderBottom(v int)

SetBorderBottom sets the height of the bottom border.

func (*Window) SetBorderLeft

func (w *Window) SetBorderLeft(v int)

SetBorderLeft sets the width of the left border.

func (*Window) SetBorderRight

func (w *Window) SetBorderRight(v int)

SetBorderRight sets the width of the right border.

func (*Window) SetBorderStyle

func (w *Window) SetBorderStyle(s Style)

SetBorderStyle sets the border style.

func (*Window) SetBorderTop

func (w *Window) SetBorderTop(v int)

SetBorderTop sets the height of the top border.

func (*Window) SetCell

func (w *Window) SetCell(x, y int, mainc rune, combc []rune, style tcell.Style)

SetCell renders a single character cell. Calling this method outside of an OnPaint* handler is ignored.

func (*Window) SetClientAreaStyle

func (w *Window) SetClientAreaStyle(s Style)

SetClientAreaStyle sets the client area style.

func (*Window) SetClientSize

func (w *Window) SetClientSize(s Size)

SetClientSize sets the size of the client area.

func (*Window) SetCloseButton

func (w *Window) SetCloseButton(v bool)

SetCloseButton sets whether the window shows a close button.

func (*Window) SetFocus

func (w *Window) SetFocus(v bool)

SetFocus sets whether the window is focused.

func (*Window) SetOrigin

func (w *Window) SetOrigin(p Position)

SetOrigin sets the origin of the window. By default the origin of a window is (0, 0). When a paint handler is invoked the window's origin is subtracted from the coordinates the handler paints to. Also, the PaintContext.Rectangle value passed to the handler is adjusted accordingly.

Setting origin other than (0, 0) provides a view into the content created by the respective paint handlers. The mechanism aids in displaying scrolling content.

Negative values of p.X or p.Y are ignored.

func (*Window) SetPosition

func (w *Window) SetPosition(p Position)

SetPosition sets the window position relative to its parent.

func (*Window) SetSize

func (w *Window) SetSize(s Size)

SetSize sets the window size.

func (*Window) SetStyle

func (w *Window) SetStyle(s WindowStyle)

SetStyle sets the window style.

func (*Window) SetTitle

func (w *Window) SetTitle(s string)

SetTitle sets the window title.

func (*Window) Size

func (w *Window) Size() Size

Size returns the window size.

func (*Window) Style

func (w *Window) Style() WindowStyle

Style returns the window style.

func (*Window) Title

func (w *Window) Title() string

Title returns the window title.

type WindowStyle

type WindowStyle struct {
	Border     Style
	ClientArea Style
	Title      Style
}

WindowStyle represents visual styles of a Window.

Directories

Path Synopsis
internal
demoapp
Package demoapp is a terminal application skeleton.
Package demoapp is a terminal application skeleton.
Package tk is a wm[0] toolkit.
Package tk is a wm[0] toolkit.

Jump to

Keyboard shortcuts

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