Documentation
¶
Index ¶
- Constants
- func Clear()
- func CursorTo(row, col int)
- func HandleShellSignals()
- func HideCursor()
- func ShowCursor()
- type Box
- type Component
- func (c *Component) AddChild(child *Component)
- func (c *Component) AddEventListener(event int, listener *func(*Component))
- func (c *Component) Box() *Box
- func (c *Component) Children() []*Component
- func (c *Component) Content() *string
- func (c *Component) Grow() float64
- func (c *Component) IsVertical() bool
- func (c *Component) Length() int
- func (c *Component) RemoveAllChildren()
- func (c *Component) RemoveEventListener(event int, listener *func(*Component))
- func (c *Component) Render()
- func (c *Component) SetColorFunc(colorFunc func(a ...any) string)
- func (c *Component) SetContent(content string)
- func (c *Component) SetContentFunc(updateFunc func(*Box) string)
- func (c *Component) SetGrow(grow float64)
- func (c *Component) SetIsVertical(isVertical bool)
- func (c *Component) SetLength(length int)
- func (c *Component) UpdateLayout()
- type Scroll
Constants ¶
const BLANK_CHAR = " "
const (
Event_LayoutUpdated = iota // Triggered at the very end of UpdateLayout()
)
Variables ¶
This section is empty.
Functions ¶
func HandleShellSignals ¶
func HandleShellSignals()
Handles SIGINT, SIGTERM, and SIGWINCH signals.
- SIGINT/SIGTERM : shows the cursor and exits the current process
- SIGWINCH : updates the screen layout and re-renders the whole screen
func HideCursor ¶
func HideCursor()
func ShowCursor ¶
func ShowCursor()
Types ¶
type Component ¶
type Component struct {
Scroll Scroll
// contains filtered or unexported fields
}
A Component represents a rectangular area on the screen that can have a parent Component and children Components. Components are laid out according to simple rules inspired by CSS Flex. By default, Components lay out their children horizontally and space them evenly. When properties are changed on this Component, parent Components, or child Components, they will update each others properties in order to lay themselves out correctly. After changing any properties of a Component, the UpdateLayout() function must be called to apply them before the next Render().
For pre-built Components that are more advanced, see the github.com/computerdane/flextui/components library.
var CursorOwner *Component
The Component that is currently allowed to modify the cursor position.
var Screen *Component
Parent of all components. Fills the entire terminal window.
func NewComponent ¶
func NewComponent() *Component
func (*Component) AddChild ¶
Adds a child Component to this Component. The order in which AddChild() is called will determine the order of the child Components' layout.
func (*Component) AddEventListener ¶ added in v0.0.8
Attach an event listener to this component. Use the flextui.Event_* constants to choose an event.
func (*Component) IsVertical ¶
func (*Component) RemoveAllChildren ¶
func (c *Component) RemoveAllChildren()
Removes all child Components from this Component.
func (*Component) RemoveEventListener ¶ added in v0.0.8
Remove an event listener from this component. Use the flextui.Event_* constants to choose an event.
func (*Component) Render ¶
func (c *Component) Render()
Render this Component's content to the screen, and render all child Components as well.
func (*Component) SetColorFunc ¶
Set the Component's style using a function that can be called to add ANSI color codes before rendering the Component's content. Pairs well with the library github.com/fatih/color using a color's github.com/fatih/color.Color.SprintFunc.
func (*Component) SetContent ¶
Set this Component's text content.
func (*Component) SetContentFunc ¶
Set the Component's content based on its Box's dimensions. Useful for creating responsive Components that fill their content depending on the width/height of the Component.
func (*Component) SetGrow ¶
Set the Component's grow property. All Components have a default grow of 1. If a Component's grow is larger than others, it will take up more space proportional to the total grow of its neighbors.
func (*Component) SetIsVertical ¶
Change whether child Components are laid out vertically or horizontally.
func (*Component) SetLength ¶
Set a custom length for a Component. Overrides the grow property and disables flex-based layout for this Component only. Neighbor Components will still use their grow properties for their layouts.
func (*Component) UpdateLayout ¶
func (c *Component) UpdateLayout()
Updates the Box positions of this Component and all child Components.
Useful for responding to layout changes triggered by screen resizing or user actions.