Documentation ¶
Overview ¶
Package container defines a type that wraps other containers or widgets.
The container supports splitting container into sub containers, defining container styles and placing widgets. The container also creates and manages canvases assigned to the placed widgets.
Example ¶
Example demonstrates how to use the Container API.
bc, err := barchart.New() if err != nil { panic(err) } if _, err := New( /* terminal = */ nil, SplitVertical( Left( SplitHorizontal( Top( Border(linestyle.Light), ), Bottom( SplitHorizontal( Top( Border(linestyle.Light), ), Bottom( Border(linestyle.Light), ), ), ), SplitPercent(30), ), ), Right( Border(linestyle.Light), PlaceWidget(bc), ), ), ); err != nil { panic(err) }
Output:
Index ¶
- Constants
- type BottomOption
- type Container
- type LeftOption
- type Option
- func AlignHorizontal(h align.Horizontal) Option
- func AlignVertical(v align.Vertical) Option
- func Border(ls linestyle.LineStyle) Option
- func BorderColor(color cell.Color) Option
- func BorderTitle(title string) Option
- func BorderTitleAlignCenter() Option
- func BorderTitleAlignLeft() Option
- func BorderTitleAlignRight() Option
- func Clear() Option
- func FocusedColor(color cell.Color) Option
- func ID(id string) Option
- func MarginBottom(cells int) Option
- func MarginBottomPercent(perc int) Option
- func MarginLeft(cells int) Option
- func MarginLeftPercent(perc int) Option
- func MarginRight(cells int) Option
- func MarginRightPercent(perc int) Option
- func MarginTop(cells int) Option
- func MarginTopPercent(perc int) Option
- func PaddingBottom(cells int) Option
- func PaddingBottomPercent(perc int) Option
- func PaddingLeft(cells int) Option
- func PaddingLeftPercent(perc int) Option
- func PaddingRight(cells int) Option
- func PaddingRightPercent(perc int) Option
- func PaddingTop(cells int) Option
- func PaddingTopPercent(perc int) Option
- func PlaceWidget(w widgetapi.Widget) Option
- func SplitHorizontal(t TopOption, b BottomOption, opts ...SplitOption) Option
- func SplitVertical(l LeftOption, r RightOption, opts ...SplitOption) Option
- type RightOption
- type SplitOption
- type TopOption
Examples ¶
Constants ¶
const DefaultSplitFixed = -1
DefaultSplitFixed is the default value for the SplitFixed option.
const DefaultSplitPercent = 50
DefaultSplitPercent is the default value for the SplitPercent option.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BottomOption ¶
type BottomOption interface {
// contains filtered or unexported methods
}
BottomOption is used to provide options to the bottom sub container after a horizontal split of the parent.
func Bottom ¶
func Bottom(opts ...Option) BottomOption
Bottom applies options to the bottom sub container after a horizontal split of the parent.
type Container ¶
type Container struct {
// contains filtered or unexported fields
}
Container wraps either sub containers or widgets and positions them on the terminal. This is thread-safe.
func New ¶
func New(t terminalapi.Terminal, opts ...Option) (*Container, error)
New returns a new root container that will use the provided terminal and applies the provided options.
func (*Container) String ¶
String represents the container metadata in a human readable format. Implements fmt.Stringer.
func (*Container) Subscribe ¶ added in v0.7.0
func (c *Container) Subscribe(eds *event.DistributionSystem)
Subscribe tells the container to subscribe itself and widgets to the provided event distribution system. This method is private to termdash, stability isn't guaranteed and changes won't be backward compatible.
func (*Container) Update ¶ added in v0.8.0
Update updates container with the specified id by setting the provided options. This can be used to perform dynamic layout changes, i.e. anything between replacing the widget in the container and completely changing the layout and splits. The argument id must match exactly one container with that was created with matching ID() option. The argument id must not be an empty string.
type LeftOption ¶
type LeftOption interface {
// contains filtered or unexported methods
}
LeftOption is used to provide options to the left sub container after a vertical split of the parent.
func Left ¶
func Left(opts ...Option) LeftOption
Left applies options to the left sub container after a vertical split of the parent.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option is used to provide options to a container.
func AlignHorizontal ¶
func AlignHorizontal(h align.Horizontal) Option
AlignHorizontal sets the horizontal alignment for the widget placed in the container. Has no effect if the container contains no widget. Defaults to alignment in the center.
func AlignVertical ¶
AlignVertical sets the vertical alignment for the widget placed in the container. Has no effect if the container contains no widget. Defaults to alignment in the middle.
func BorderColor ¶
BorderColor sets the color of the border around the container. This option is inherited to sub containers created by container splits.
func BorderTitle ¶
BorderTitle sets a text title within the border.
func BorderTitleAlignCenter ¶
func BorderTitleAlignCenter() Option
BorderTitleAlignCenter aligns the border title in the center.
func BorderTitleAlignLeft ¶
func BorderTitleAlignLeft() Option
BorderTitleAlignLeft aligns the border title on the left.
func BorderTitleAlignRight ¶
func BorderTitleAlignRight() Option
BorderTitleAlignRight aligns the border title on the right.
func Clear ¶ added in v0.8.0
func Clear() Option
Clear clears this container. If the container contains a widget, the widget is removed. If the container had any sub containers or splits, they are removed.
func FocusedColor ¶
FocusedColor sets the color of the border around the container when it has keyboard focus. This option is inherited to sub containers created by container splits.
func ID ¶ added in v0.8.0
ID sets an identifier for this container. This ID can be later used to perform dynamic layout changes by passing new options to this container. When provided, it must be a non-empty string that is unique among all the containers.
func MarginBottom ¶ added in v0.8.0
MarginBottom sets reserved space outside of the container at its bottom. The provided number is the absolute margin in cells and must be zero or a positive integer. Only one of MarginBottom or MarginBottomPercent can be specified.
func MarginBottomPercent ¶ added in v0.8.0
MarginBottomPercent sets reserved space outside of the container at its bottom. The provided number is a relative margin defined as percentage of the container's height. Only one of MarginBottom or MarginBottomPercent can be specified. The value must be in range 0 <= value <= 100.
func MarginLeft ¶ added in v0.8.0
MarginLeft sets reserved space outside of the container at its left. The provided number is the absolute margin in cells and must be zero or a positive integer. Only one of MarginLeft or MarginLeftPercent can be specified.
func MarginLeftPercent ¶ added in v0.8.0
MarginLeftPercent sets reserved space outside of the container at its left. The provided number is a relative margin defined as percentage of the container's height. Only one of MarginLeft or MarginLeftPercent can be specified. The value must be in range 0 <= value <= 100.
func MarginRight ¶ added in v0.8.0
MarginRight sets reserved space outside of the container at its right. The provided number is the absolute margin in cells and must be zero or a positive integer. Only one of MarginRight or MarginRightPercent can be specified.
func MarginRightPercent ¶ added in v0.8.0
MarginRightPercent sets reserved space outside of the container at its right. The provided number is a relative margin defined as percentage of the container's height. Only one of MarginRight or MarginRightPercent can be specified. The value must be in range 0 <= value <= 100.
func MarginTop ¶ added in v0.8.0
MarginTop sets reserved space outside of the container at its top. The provided number is the absolute margin in cells and must be zero or a positive integer. Only one of MarginTop or MarginTopPercent can be specified.
func MarginTopPercent ¶ added in v0.8.0
MarginTopPercent sets reserved space outside of the container at its top. The provided number is a relative margin defined as percentage of the container's height. Only one of MarginTop or MarginTopPercent can be specified. The value must be in range 0 <= value <= 100.
func PaddingBottom ¶ added in v0.8.0
PaddingBottom sets reserved space between container and the bottom side of its widget. The widget's area size is decreased to accommodate the padding. The provided number is the absolute padding in cells and must be zero or a positive integer. Only one of PaddingBottom or PaddingBottomPercent can be specified.
func PaddingBottomPercent ¶ added in v0.8.0
PaddingBottomPercent sets reserved space between container and the bottom side of its widget. The widget's area size is decreased to accommodate the padding. The provided number is a relative padding defined as percentage of the container's height. The value must be in range 0 <= value <= 100. Only one of PaddingBottom or PaddingBottomPercent can be specified.
func PaddingLeft ¶ added in v0.8.0
PaddingLeft sets reserved space between container and the left side of its widget. The widget's area size is decreased to accommodate the padding. The provided number is the absolute padding in cells and must be zero or a positive integer. Only one of PaddingLeft or PaddingLeftPercent can be specified.
func PaddingLeftPercent ¶ added in v0.8.0
PaddingLeftPercent sets reserved space between container and the left side of its widget. The widget's area size is decreased to accommodate the padding. The provided number is a relative padding defined as percentage of the container's width. The value must be in range 0 <= value <= 100. Only one of PaddingLeft or PaddingLeftPercent can be specified.
func PaddingRight ¶ added in v0.8.0
PaddingRight sets reserved space between container and the right side of its widget. The widget's area size is decreased to accommodate the padding. The provided number is the absolute padding in cells and must be zero or a positive integer. Only one of PaddingRight or PaddingRightPercent can be specified.
func PaddingRightPercent ¶ added in v0.8.0
PaddingRightPercent sets reserved space between container and the right side of its widget. The widget's area size is decreased to accommodate the padding. The provided number is a relative padding defined as percentage of the container's width. The value must be in range 0 <= value <= 100. Only one of PaddingRight or PaddingRightPercent can be specified.
func PaddingTop ¶ added in v0.8.0
PaddingTop sets reserved space between container and the top side of its widget. The widget's area size is decreased to accommodate the padding. The provided number is the absolute padding in cells and must be zero or a positive integer. Only one of PaddingTop or PaddingTopPercent can be specified.
func PaddingTopPercent ¶ added in v0.8.0
PaddingTopPercent sets reserved space between container and the top side of its widget. The widget's area size is decreased to accommodate the padding. The provided number is a relative padding defined as percentage of the container's height. The value must be in range 0 <= value <= 100. Only one of PaddingTop or PaddingTopPercent can be specified.
func PlaceWidget ¶
PlaceWidget places the provided widget into the container. The use of this option removes any sub containers. Containers with sub containers cannot have widgets.
func SplitHorizontal ¶
func SplitHorizontal(t TopOption, b BottomOption, opts ...SplitOption) Option
SplitHorizontal splits the container along the horizontal axis into two sub containers. The use of this option removes any widget placed at this container, containers with sub containers cannot contain widgets.
func SplitVertical ¶
func SplitVertical(l LeftOption, r RightOption, opts ...SplitOption) Option
SplitVertical splits the container along the vertical axis into two sub containers. The use of this option removes any widget placed at this container, containers with sub containers cannot contain widgets.
type RightOption ¶
type RightOption interface {
// contains filtered or unexported methods
}
RightOption is used to provide options to the right sub container after a vertical split of the parent.
func Right ¶
func Right(opts ...Option) RightOption
Right applies options to the right sub container after a vertical split of the parent.
type SplitOption ¶ added in v0.4.0
type SplitOption interface {
// contains filtered or unexported methods
}
SplitOption is used when splitting containers.
func SplitFixed ¶ added in v0.10.0
func SplitFixed(cells int) SplitOption
SplitFixed sets the size of the first container to be a fixed value and makes the second container take up the remaining space. When using SplitVertical, the provided size is applied to the new left container, the new right container gets the reminder of the size. When using SplitHorizontal, the provided size is applied to the new top container, the new bottom container gets the reminder of the size. The provided value must be a positive number in the range 0 <= cells. If SplitFixed() is not specified, it defaults to SplitPercent() and its given value. Only one of SplitFixed() and SplitPercent() can be specified per container.
func SplitPercent ¶ added in v0.4.0
func SplitPercent(p int) SplitOption
SplitPercent sets the relative size of the split as percentage of the available space. When using SplitVertical, the provided size is applied to the new left container, the new right container gets the reminder of the size. When using SplitHorizontal, the provided size is applied to the new top container, the new bottom container gets the reminder of the size. The provided value must be a positive number in the range 0 < p < 100. If not provided, defaults to DefaultSplitPercent.