Documentation
¶
Index ¶
- Constants
- type AlertDefinition
- type AlertModel
- func (m AlertModel) HasActiveAlert() bool
- func (m AlertModel) Init() tea.Cmd
- func (m AlertModel) NewAlertCmd(alertType, message string) tea.Cmd
- func (m AlertModel) RegisterNewAlertType(definition AlertDefinition)
- func (m AlertModel) Render(content string) string
- func (m AlertModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)
- func (m AlertModel) View() string
- func (m AlertModel) WithAllowEscToClose() AlertModel
- func (m AlertModel) WithMinWidth(min int) AlertModel
- func (m AlertModel) WithPosition(pos Position) AlertModel
- func (m AlertModel) WithUnicodePrefix() AlertModel
- type Position
Constants ¶
const ( InfoKey = "Info" WarnKey = "Warn" ErrorKey = "Error" DebugKey = "Debug" )
Alert keys for the included alert types.
const ( InfoNerdSymbol = " " WarnNerdSymbol = " " ErrorNerdSymbol = " " DebugNerdSymbol = " " InfoASCIIPrefix = "(i)" WarningASCIIPrefix = "(!)" ErrorASCIIPrefix = "[!!]" DebugASCIIPrefix = "(?)" InfoUnicodePrefix = "\u24D8 " // Trailing space is intentional WarningUnicodePrefix = "\u26A0" ErrorUnicodePrefix = "\u2718" DebugUnicodePrefix = "\u003F" // Deprecated: use InfoASCIIPrefix instead. InfoUniPrefix = InfoASCIIPrefix // Deprecated: use WarningASCIIPrefix instead. WarningUniPrefix = WarningASCIIPrefix // Deprecated: use ErrorASCIIPrefix instead. ErrorUniPrefix = ErrorASCIIPrefix // Deprecated: use DebugASCIIPrefix instead. DebugUniPrefix = DebugASCIIPrefix )
Symbols used by the included alert types. To use the NerdFont symbols, you must be using a NerdFont, which can be obtained from https://www.nerdfonts.com/. If you want to use the default non-NerdFont symbols, pass false into the useNerdFont parameter when creating your alert model.
const ( InfoColor = "#00FF00" WarnColor = "#FFFF00" ErrorColor = "#FF0000" DebugColor = "#FF00FF" BackColor = "#000000" )
Colors used by the included alert types.
const (
DefaultLerpIncrement = 0.18
)
Defaults used by the notification rendering.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AlertDefinition ¶
type AlertDefinition struct {
// (Req) Unique key used to refer to an alert type
Key string
// (Req) Hex code of the color you want your alert to be
ForeColor string
// (Opt) lipgloss.Style used to render the alert
Style lipgloss.Style
// (Opt) String used to prefix the alert message
Prefix string
}
AlertDefinition is all the information needed to register a new alert type.
type AlertModel ¶
type AlertModel struct {
// contains filtered or unexported fields
}
AlertModel maintains a list of alert types, and facilitates the display and clearing of alerts, as well as registering custom alerts and overrides to defaults Note: duration is measured in seconds Note: width behavior depends on minWidth:
- minWidth == 0 (default): width is fixed width
- minWidth > 0: width is max width, minWidth is minimum, actual width varies with message length
func NewAlertModel ¶
func NewAlertModel(width int, useNerdFont bool, duration time.Duration) *AlertModel
NewAlertModel creates and returns a new AlertModel, initialized with default alert types
func (AlertModel) HasActiveAlert ¶ added in v1.2.0
func (m AlertModel) HasActiveAlert() bool
HasActiveAlert allows other models to tell if there is an active already and avoid processing an esc key used to clear an alert
func (AlertModel) Init ¶
func (m AlertModel) Init() tea.Cmd
Init required as part of BubbleTea Model interface
func (AlertModel) NewAlertCmd ¶
func (m AlertModel) NewAlertCmd(alertType, message string) tea.Cmd
NewAlertCmd will construct and return the tea.Cmd needed to trigger an alert. This should be called in your Update() function, and the returned tea.Cmd should be batched into your return.
func (AlertModel) RegisterNewAlertType ¶
func (m AlertModel) RegisterNewAlertType(definition AlertDefinition)
RegisterNewAlertType will registery a new alert type based on the provided AlertDefintion. This can also be used to overwrite the provided defaults by providing an AlertDefintion with one of the default keys.
func (AlertModel) Render ¶
func (m AlertModel) Render(content string) string
Render takes in the main view content and overlays the model's active alert. This function expects you build the entirety of your view's content before calling this function. It's recommended for this to be the final call of your model's View(). Returns a string representation of the content with overlayed alert.
func (AlertModel) Update ¶
Update takes in a message and returns an associated command to drive model functionality. First alertMsg starts the ticking command that causes alert refreshing Implemented as part of BubbleTea Model interface
func (AlertModel) View ¶
func (m AlertModel) View() string
View doesn't do anything, and it should never be called directly Implemented as part of BubbleTea Model interface
func (AlertModel) WithAllowEscToClose ¶ added in v1.2.0
func (m AlertModel) WithAllowEscToClose() AlertModel
func (AlertModel) WithMinWidth ¶ added in v1.2.0
func (m AlertModel) WithMinWidth(min int) AlertModel
WithMinWidth returns a new AlertModel with dynamic width enabled. When minWidth > 0, the notification width will vary between minWidth and width (max) based on the actual message length. This is an immutable operation. If min > width, it will be clamped to width.
func (AlertModel) WithPosition ¶ added in v1.2.0
func (m AlertModel) WithPosition(pos Position) AlertModel
WithPosition returns a new AlertModel with the specified position. This is an immutable operation that returns a copy with the updated position.
func (AlertModel) WithUnicodePrefix ¶ added in v1.2.0
func (m AlertModel) WithUnicodePrefix() AlertModel
WithUnicodePrefix switches the AlertModule to use Unicode fonts
