Documentation
¶
Index ¶
- Constants
- Variables
- func ByteSizeStr(s int64) string
- func FindKey(keys []cterm.Event, key cterm.Event) bool
- func GenUID() int64
- func Keys(keys ...interface{}) []cterm.Event
- func RunEventLoop(s *Sys, evHandler EventHandler, f ...EventLoopSleepDurationFunc)
- type Align
- type Attr
- type BorderRunes
- type Chx
- type Dir
- type EventHandler
- type EventLoopSleepDurationFunc
- type EventResponse
- type Point
- type Rect
- type Sys
- func (s *Sys) CenterBanner(parent Win, title, format string, a ...interface{}) Win
- func (s *Sys) Close()
- func (s *Sys) CreateWin(parent Win, cfg WinCfg) Win
- func (s *Sys) CreateWinEx(parent Win, createWin func() Win) Win
- func (s *Sys) Dump() string
- func (s *Sys) FPS() int64
- func (s *Sys) Find(w Win) Win
- func (s *Sys) GetEvent() cterm.Event
- func (s *Sys) GetFocused() Win
- func (s *Sys) MessageBox(parent Win, title, format string, a ...interface{}) bool
- func (s *Sys) MessageBoxEx(parent Win, keys []cterm.Event, title, format string, a ...interface{}) cterm.Event
- func (s *Sys) Refresh()
- func (s *Sys) RemoveWin(w Win)
- func (s *Sys) Run(fallbackHandler EventHandler, f ...EventLoopSleepDurationFunc)
- func (s *Sys) SetFocus(w Win)
- func (s *Sys) SyncExpectKey(f func(cterm.Key, rune) bool)
- func (s *Sys) SysWin() Win
- func (s *Sys) TotalChxRendered() int64
- func (s *Sys) TryFind(w Win) (Win, bool)
- func (s *Sys) TryGetEvent() cterm.Event
- func (s *Sys) Update()
- type Win
- type WinBase
- func (wb *WinBase) Base() *WinBase
- func (wb *WinBase) Cfg() WinCfg
- func (wb *WinBase) ChildFirst() Win
- func (wb *WinBase) ChildLast() Win
- func (wb *WinBase) ClientRect() Rect
- func (wb *WinBase) FillClient(cr Rect, chx Chx)
- func (wb *WinBase) Get(x, y int) Chx
- func (wb *WinBase) GetClient(cx, cy int) Chx
- func (wb *WinBase) Next() Win
- func (wb *WinBase) Parent() Win
- func (wb *WinBase) Prev() Win
- func (wb *WinBase) PutClient(cx, cy int, chx Chx)
- func (wb *WinBase) PutClientCh(cx, cy int, ch rune)
- func (wb *WinBase) Rect() Rect
- func (wb *WinBase) Same(other Win) bool
- func (wb *WinBase) SendToBottom(recursive bool)
- func (wb *WinBase) SendToTop(recursive bool)
- func (wb *WinBase) SetEventHandler(evHandler EventHandler)
- func (wb *WinBase) SetFocus(focused bool)
- func (wb *WinBase) SetLine(cy int, attr Attr, format string, a ...interface{})
- func (wb *WinBase) SetPosAbs(x, y int)
- func (wb *WinBase) SetPosRel(dx, dy int)
- func (wb *WinBase) SetText(format string, a ...interface{})
- func (wb *WinBase) SetTitle(format string, a ...interface{})
- func (wb *WinBase) String() string
- func (wb *WinBase) Sys() *Sys
- func (wb *WinBase) This() Win
- type WinCfg
Constants ¶
View Source
const ( DirUp = Dir(iota) DirUpRight DirRight DirDownRight DirDown DirDownLeft DirLeft DirUpLeft DirCount = int(DirUpLeft) )
View Source
const ( DirN = DirUp DirNE = DirUpRight DirE = DirRight DirSE = DirDownRight DirS = DirDown DirSW = DirDownLeft DirW = DirLeft DirNW = DirUpLeft )
View Source
const ( EventHandled = EventResponse(iota) EventNotHandled EventLoopStop )
View Source
const ( BorderRuneUL int = iota BorderRuneUR BorderRuneLR BorderRuneLL BorderRuneV BorderRuneH BorderRuneCount )
View Source
const (
RuneSpace rune = ' '
)
Variables ¶
View Source
var ( SingleLineBorderRunes = BorderRunes{'┏', '┓', '┛', '┗', '┃', '━'} DoubleLineBorderRunes = BorderRunes{'╔', '╗', '╝', '╚', '║', '═'} )
View Source
var ( DirOffSetXY = map[Dir]Point{ DirUp: {X: 0, Y: -1}, DirUpRight: {X: 1, Y: -1}, DirRight: {X: 1, Y: 0}, DirDownRight: {X: 1, Y: 1}, DirDown: {X: 0, Y: 1}, DirDownLeft: {X: -1, Y: 1}, DirLeft: {X: -1, Y: 0}, DirUpLeft: {X: -1, Y: -1}, } )
View Source
var ( DirRunes = map[Dir]rune{ DirN: '↑', DirNE: '↗', DirE: '→', DirSE: '↘', DirS: '↓', DirSW: '↙', DirW: '←', DirNW: '↖', } )
View Source
var ( Key2Dir = map[cterm.Key]Dir{ cterm.KeyArrowUp: DirUp, cterm.KeyArrowRight: DirRight, cterm.KeyArrowDown: DirDown, cterm.KeyArrowLeft: DirLeft, } )
Functions ¶
func ByteSizeStr ¶
func RunEventLoop ¶
func RunEventLoop(s *Sys, evHandler EventHandler, f ...EventLoopSleepDurationFunc)
Types ¶
type BorderRunes ¶
type BorderRunes [BorderRuneCount]rune
type EventHandler ¶
type EventHandler func(ev cterm.Event) EventResponse
type EventResponse ¶
type EventResponse int
func FalseForEventSystemStop ¶
func FalseForEventSystemStop(b bool) EventResponse
func NopHandledEventHandler ¶
func NopHandledEventHandler(ev cterm.Event) EventResponse
func NopNotHandledEventHandler ¶
func NopNotHandledEventHandler(ev cterm.Event) EventResponse
func TrueForEventSystemStop ¶
func TrueForEventSystemStop(b bool) EventResponse
type Sys ¶
type Sys struct {
// contains filtered or unexported fields
}
func (*Sys) CenterBanner ¶
func (*Sys) GetFocused ¶
func (*Sys) MessageBox ¶
MessageBox is mostly similar to MessageBoxEx but only with 2 expected keys: Enter or ESC It returns true if Enter is pressed or false if ESC is pressed.
func (*Sys) MessageBoxEx ¶
func (s *Sys) MessageBoxEx( parent Win, keys []cterm.Event, title, format string, a ...interface{}) cterm.Event
MessageBoxEx displays a blue-background message window centered in the client area of parent window, and synchronously waiting for a set of user specified keys, and return if any of the keys are pressed.
func (*Sys) Run ¶
func (s *Sys) Run(fallbackHandler EventHandler, f ...EventLoopSleepDurationFunc)
func (*Sys) SyncExpectKey ¶
if f == nil, SyncExpectKey waits for any single key and then returns if f != nil, SyncExpectKey repeatedly waits for a key & has it processed by f, if f returns false
func (*Sys) TotalChxRendered ¶
type Win ¶
type Win interface {
Cfg() WinCfg
Sys() *Sys
// Base returns the embedded WinBase pointer which can be used for accessing
// the library built-in WinBase functionalities, as well as serving as a unique
// identifier for the window.
Base() *WinBase
// Same tells if this Win is the same instance of other Win.
Same(other Win) bool
// This returns the actual object that implements Win interface that is registered
// with Sys. Because WinBase implements Win interface, sometimes we go into situation
// where a WinBase pointer is getting passed around but eventually when deverloper
// wants to cast back to their own object (which embeds WinBase) they get type assertion
// failure. As long as the object (that implements Win) passed into Sys.CreateWin is
// the "top-level" object, This() will always return that registered object. Note if
// calling This() on a non Sys managed (i.e. not from Sys.CreateWin) object, it will
// panic.
This() Win
Parent() Win
Prev() Win
Next() Win
ChildFirst() Win
ChildLast() Win
// Returns the Rect of the window relative to its parent window's client region.
Rect() Rect
// Returns the client Rect of the window, relative to this window.
ClientRect() Rect
// Moves the window position (relative to its parent's client region) to (x, y)
SetPosAbs(x, y int)
// Moves the window position (relative to its parent's client region) by (dx, dy)
SetPosRel(dx, dy int)
// Sets the event handler for this window.
SetEventHandler(evHandler EventHandler)
// Sets the window's title.
SetTitle(format string, a ...interface{})
// Sets a text, multi-line allowed, to the client region of the window
SetText(format string, a ...interface{})
// Sets a single line text, to the client region of the window
SetLine(cy int, attr Attr, format string, a ...interface{})
// Set the window to be in or out of focus. This method should only conduct focus related
// changes to this window only. To actually set a window in focus system-wise needs to do
// more things like set up message handler, changing z-order, etc, which requires a calling
// to Sys.SetFocus.
SetFocus(focused bool)
// Sets the window to the bottom position among all the child windows of its parent window.
SendToBottom(recursive bool)
// Sets the window to the top position among all the child windows of its parent window.
SendToTop(recursive bool)
// Gets the Chx from the window.
Get(x, y int) Chx
// Gets the Chx from the client region of the window. Note cx/cy are client coordinate,
// relative to this window's ClientRect.
GetClient(cx, cy int) Chx
// Puts a Chx to the client region of the window. Note cx/cy are client coordinate,
// relative to this window's ClientRect.
PutClient(cx, cy int, chx Chx)
// Puts a rune to the client region of the window with default color attributes. Note cx/cy
// are client coordinate, relative to this window's ClientRect.
PutClientCh(cx, cy int, ch rune)
// Fills a region inside the client region of the window. Note cr is the region Rect, relative
// to this window's ClientRect.
FillClient(cr Rect, chx Chx)
fmt.Stringer
}
Win represents a window
type WinBase ¶
type WinBase struct {
// contains filtered or unexported fields
}
func (*WinBase) ChildFirst ¶
func (*WinBase) ClientRect ¶
func (*WinBase) FillClient ¶
func (*WinBase) PutClientCh ¶
func (*WinBase) SendToBottom ¶
func (*WinBase) SetEventHandler ¶
func (wb *WinBase) SetEventHandler(evHandler EventHandler)
type WinCfg ¶
type WinCfg struct {
// Required.
// For root window, R.X/Y specify the absolute console x/y of the root window; W/H for its size
// For regular window (that is direct/indirect descendant of root window), R.X/Y is the relative
// position from its direct parent window. W/H for its size.
R Rect
// All the following are optional.
EventHandler EventHandler
Name string // also used as title (unless NoTitle or NoBorder is true)
NoBorder bool
BorderRunes *BorderRunes // if NoBorder && BorderRunes==nil, default to 1-line border
InFocusBorderRunes *BorderRunes // Used for border rendering when window is in focus. If nil, default to 2-line border
BorderAttr Attr
InFocusBorderAttr *Attr // Used for border rendering when window is in focus. If nil, default Fg=ColorLightYellow
ClientAttr Attr
NoTitle bool // in case user sets Name (for debug purpose) and border, but doesn't want Title
NoPaddingTitle bool // most cases, have a one-space padding on each side of title looks nice
NoPaddingText bool // most cases, have a one-space padding on each side of text block looks nice
TitleAlign Align
TextAlign Align
}
Source Files
¶
Click to show internal directories.
Click to hide internal directories.