Documentation ¶
Index ¶
- func AnyInBounds(model tea.Model, mouse tea.MouseMsg)
- func AnyInBoundsAndUpdate(model tea.Model, mouse tea.MouseMsg) (tea.Model, tea.Cmd)
- func Clear(id string)
- func Close()
- func Enabled() bool
- func Mark(id, v string) string
- func NewGlobal()
- func NewPrefix() string
- func Scan(v string) string
- func SetEnabled(v bool)
- type Manager
- func (m *Manager) AnyInBounds(model tea.Model, mouse tea.MouseMsg)
- func (m *Manager) AnyInBoundsAndUpdate(model tea.Model, mouse tea.MouseMsg) (tea.Model, tea.Cmd)
- func (m *Manager) Clear(id string)
- func (m *Manager) Close()
- func (m *Manager) Enabled() bool
- func (m *Manager) Get(id string) (zone *ZoneInfo)
- func (m *Manager) Mark(id, v string) string
- func (m *Manager) NewPrefix() string
- func (m *Manager) Scan(v string) string
- func (m *Manager) SetEnabled(enabled bool)
- type MsgZoneInBounds
- type ZoneInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AnyInBounds ¶
AnyInBounds sends a MsgZoneInBounds message to the provided model for each zone that is in the bounds of the provided mouse event. The results of the call to Update() are discarded.
Note that if multiple zones are within bounds, each one will be sent as an event in alphabetical sorted order of the ID.
func AnyInBoundsAndUpdate ¶
AnyInBoundsAndUpdate is the same as AnyInBounds; except the results of the calls to Update() are carried through and returned.
The tea.Cmd's that comd off the calls to Update() are wrapped in tea.Batch().
func Enabled ¶
func Enabled() bool
Enabled returns whether the zone manager is enabled or not. When disabled, the zone manager will still parse zone information, however it will immediately drop it and remove zone markers from the resulting output.
The zone manager is enabled by default.
func Mark ¶
Mark returns v wrapped with a start and end ANSI sequence to allow the zone manager to determine where the zone is, including its window offsets. The ANSI sequences used should be ignored by lipgloss width methods, to prevent incorrect width calculations.
When the zone manager is disabled, Mark() will return v without any changes.
func NewGlobal ¶
func NewGlobal()
NewGlobal initializes a global manager, so you don't have to pass the manager between all components. This is primarily only useful if you have full control of the zones you want to monitor, however if developing a library using this, make sure you allow users to pass in their own manager.
The zone manager is enabled by default, and can be toggled by calling SetEnabled().
func NewPrefix ¶
func NewPrefix() string
NewPrefix generates a zone marker ID prefix, which can help prevent overlapping zone markers between multiple components. Each call to NewPrefix() returns a new unique prefix.
Usage example:
func NewModel() tea.Model { return &model{ id: zone.NewPrefix(), } } type model struct { id string active int items []string } func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg := msg.(type) { // [...] case tea.MouseMsg: // [...] for i, item := range m.items { if zone.Get(m.id + item.name).InBounds(msg) { m.active = i break } } } return m, nil } func (m model) View() string { return zone.Mark(m.id+"some-other-id", "rendered stuff here") }
func Scan ¶
Scan will scan the view output, searching for zone markers, returning the original view output with the zone markers stripped. Scan() should be used by the outer most model/component of your application, and not inside of a model/component child.
Scan buffers the zone info to be stored, so an immediate call to Get(id) may not return the correct information. Thus it's recommended to primarily use Get(id) for actions like mouse events, which don't occur immediately after a view shift (where the previously stored zone info might be different).
When the zone manager is disabled (via SetEnabled(false)), Scan() will return the original view output with all zone markers stripped. It will still parse the input for zone markers, as some users may cache generated views. In most situations when the zone manager is disabled (and thus Mark() returns input unchanged), Scan() will not need to do any work.
func SetEnabled ¶
func SetEnabled(v bool)
SetEnabled enables or disables the zone manager. When disabled, the zone manager will still parse zone information, however it will immediately drop it and remove zone markers from the resulting output.
The zone manager is enabled by default.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager holds the state of the zone manager, including ID zones and zones of components.
var DefaultManager *Manager
DefaultManager is an app-wide manager. To initialize it, call NewGlobal().
func New ¶
func New() (m *Manager)
New creates a new (non-global) zone manager. The zone manager is responsible for parsing zone information from the output of a component, and storing it for later retrieval/bounds checks.
The zone manager is enabled by default, and can be toggled by calling SetEnabled().
func (*Manager) AnyInBounds ¶
AnyInBounds sends a MsgZoneInBounds message to the provided model for each zone that is in the bounds of the provided mouse event. The results of the call to Update() are discarded.
Note that if multiple zones are within bounds, each one will be sent as an event in alphabetical sorted order of the ID.
func (*Manager) AnyInBoundsAndUpdate ¶
AnyInBoundsAndUpdate is the same as AnyInBounds; except the results of the calls to Update() are carried through and returned.
The tea.Cmd's that comd off the calls to Update() are wrapped in tea.Batch().
func (*Manager) Enabled ¶
Enabled returns whether the zone manager is enabled or not. When disabled, the zone manager will still parse zone information, however it will immediately drop it and remove zone markers from the resulting output.
The zone manager is enabled by default.
func (*Manager) Get ¶
Get returns the zone info of the given ID. If the ID is not known (yet), Get() returns nil.
func (*Manager) Mark ¶
Mark returns v wrapped with a start and end ANSI sequence to allow the zone manager to determine where the zone is, including its window offsets. The ANSI sequences used should be ignored by lipgloss width methods, to prevent incorrect width calculations.
When the zone manager is disabled, Mark() will return v without any changes.
func (*Manager) NewPrefix ¶
NewPrefix generates a zone marker ID prefix, which can help prevent overlapping zone markers between multiple components. Each call to NewPrefix() returns a new unique prefix.
Usage example:
func NewModel() tea.Model { return &model{ id: zone.NewPrefix(), } } type model struct { id string active int items []string } func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg := msg.(type) { // [...] case tea.MouseMsg: // [...] for i, item := range m.items { if zone.Get(m.id + item.name).InBounds(msg) { m.active = i break } } } return m, nil } func (m model) View() string { return zone.Mark(m.id+"some-other-id", "rendered stuff here") }
func (*Manager) Scan ¶
Scan will scan the view output, searching for zone markers, returning the original view output with the zone markers stripped. Scan() should be used by the outer most model/component of your application, and not inside of a model/component child.
Scan buffers the zone info to be stored, so an immediate call to Get(id) may not return the correct information. Thus it's recommended to primarily use Get(id) for actions like mouse events, which don't occur immediately after a view shift (where the previously stored zone info might be different).
When the zone manager is disabled (via SetEnabled(false)), Scan() will return the original view output with all zone markers stripped. It will still parse the input for zone markers, as some users may cache generated views. In most situations when the zone manager is disabled (and thus Mark() returns input unchanged), Scan() will not need to do any work.
func (*Manager) SetEnabled ¶
SetEnabled enables or disables the zone manager. When disabled, the zone manager will still parse zone information, however it will immediately drop it and remove zone markers from the resulting output.
The zone manager is enabled by default.
type MsgZoneInBounds ¶
type MsgZoneInBounds struct { Zone *ZoneInfo // The zone that is in bounds. Event tea.MouseMsg // The mouse event that caused the zone to be in bounds. }
MsgZoneInBounds is a message sent when the manager detects that a zone is within bounds of a mouse event.
type ZoneInfo ¶
type ZoneInfo struct { StartX int // StartX is the x coordinate of the top left cell of the zone (with 0 basis). StartY int // StartY is the y coordinate of the top left cell of the zone (with 0 basis). EndX int // EndX is the x coordinate of the bottom right cell of the zone (with 0 basis). EndY int // EndY is the y coordinate of the bottom right cell of the zone (with 0 basis). // contains filtered or unexported fields }
ZoneInfo holds information about the start and end positions of a zone.
func Get ¶
Get returns the zone info of the given ID. If the ID is not known (yet), Get() returns nil.
func (*ZoneInfo) InBounds ¶
InBounds returns true if the mouse event was in the bounds of the zones coordinates. If the zone is not known, it returns false. It calculates this using a box between the start and end coordinates. If you're looking to check for abnormal shapes (e.g. something that might wrap a line, but can't be determined using a box), you'll likely have to implement this yourself.