### Installation Source: https://context7.com/daltonsw/bubbleup/llms.txt Install the BubbleUp library using go get. ```APIDOC ## Installation ### Description Install the BubbleUp library using the go get command. ### Method `go get` ### Endpoint go get go.dalton.dog/bubbleup ### Parameters None ### Request Example ```bash go get go.dalton.dog/bubbleup ``` ### Response None ``` -------------------------------- ### Complete BubbleTea Integration Example Source: https://context7.com/daltonsw/bubbleup/llms.txt This Go code provides a full example of integrating BubbleUp into a BubbleTea application. It demonstrates how to initialize the AlertModel, handle user input to trigger alerts, and render the alerts within the application's view. ```APIDOC ## Complete BubbleTea Integration Example ### Description A full example showing all BubbleUp features integrated into a BubbleTea application with proper Init, Update, and View method implementations. ### Method N/A (This is a full application example, not a specific API endpoint) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ### Code Example (Go) ```go package main import ( "fmt" "time" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" "go.dalton.dog/bubbleup" ) type model struct { alert bubbleup.AlertModel count int } func initialModel() model { // Configure alert with all options alert := bubbleup.NewAlertModel(50, false, 5*time.Second). WithMinWidth(20). WithPosition(bubbleup.TopRightPosition). WithUnicodePrefix(). WithAllowEscToClose() // Register custom alert type alert.RegisterNewAlertType(bubbleup.AlertDefinition{ Key: "Counter", ForeColor: "#FF69B4", // Hot pink Prefix: "#", }) return model{alert: *alert, count: 0} } func (m model) Init() tea.Cmd { return m.alert.Init() } func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { var alertCmd tea.Cmd switch msg := msg.(type) { case tea.KeyMsg: switch msg.String() { case "q": return m, tea.Quit case "esc": if !m.alert.HasActiveAlert() { return m, tea.Quit } case "+", "=": m.count++ m.alert = m.alert.WithPosition(bubbleup.TopRightPosition) alertCmd = m.alert.NewAlertCmd("Counter", fmt.Sprintf("Count: %d", m.count)) case "-": m.count-- m.alert = m.alert.WithPosition(bubbleup.BottomRightPosition) alertCmd = m.alert.NewAlertCmd(bubbleup.WarnKey, fmt.Sprintf("Decreased to %d", m.count)) case "r": m.count = 0 m.alert = m.alert.WithPosition(bubbleup.TopCenterPosition) alertCmd = m.alert.NewAlertCmd(bubbleup.InfoKey, "Counter reset!") case "e": m.alert = m.alert.WithPosition(bubbleup.BottomCenterPosition) alertCmd = m.alert.NewAlertCmd(bubbleup.ErrorKey, "This is an error demonstration with a longer message to show text wrapping") } } outAlert, outCmd := m.alert.Update(msg) m.alert = outAlert.(bubbleup.AlertModel) return m, tea.Batch(alertCmd, outCmd) } func (m model) View() string { style := lipgloss.NewStyle(). Width(60). Height(15). Padding(2). Border(lipgloss.RoundedBorder()). BorderForeground(lipgloss.Color("#00FFFF")) content := fmt.Sprintf(`BubbleUp Demo Current Count: %d Keys: +/- : Increment/Decrement (shows alert) r : Reset counter e : Show error alert esc : Dismiss alert or quit q : Quit`, m.count) view := style.Render(content) // Always render alert overlay last return m.alert.Render(view) } func main() { p := tea.NewProgram(initialModel(), tea.WithAltScreen()) if _, err := p.Run(); err != nil { fmt.Printf("Error: %v\n", err) } } ``` ``` -------------------------------- ### Install BubbleUp Module Source: https://github.com/daltonsw/bubbleup/blob/main/README.md Command to download the BubbleUp module using Go's package management. This is the first step to integrating BubbleUp into your project. ```sh go get go.dalton.dog/bubbleup ``` -------------------------------- ### Initialize Basic Alert Model Source: https://github.com/daltonsw/bubbleup/blob/main/README.md Go code example for creating a new BubbleUp alert model. It shows how to set the maximum width, whether to use NerdFont symbols, and the duration for alerts before they auto-dismiss. ```go // Create alert model: max width=50, use NerdFont, 10 second duration alertModel := bubbleup.NewAlertModel(50, true, 10*time.Second) m := myModel{ alert: alertModel, } ``` -------------------------------- ### BubbleTea Application with BubbleUp Notifications (Go) Source: https://context7.com/daltonsw/bubbleup/llms.txt This Go code provides a full example of integrating BubbleUp into a BubbleTea application. It demonstrates initializing the AlertModel with various configurations, handling user input to trigger different alert types and positions, and rendering the main application view with the alert overlay. Dependencies include the 'bubbletea' and 'bubbleup' libraries. ```go package main import ( "fmt" "time" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" "go.dalton.dog/bubbleup" ) type model struct { alert bubbleup.AlertModel count int } func initialModel() model { // Configure alert with all options alert := bubbleup.NewAlertModel(50, false, 5*time.Second). WithMinWidth(20). WithPosition(bubbleup.TopRightPosition). WithUnicodePrefix(). WithAllowEscToClose() // Register custom alert type alert.RegisterNewAlertType(bubbleup.AlertDefinition{ Key: "Counter", ForeColor: "#FF69B4", // Hot pink Prefix: "#", }) return model{alert: *alert, count: 0} } func (m model) Init() tea.Cmd { return m.alert.Init() } func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { var alertCmd tea.Cmd switch msg := msg.(type) { case tea.KeyMsg: switch msg.String() { case "q": return m, tea.Quit case "esc": if !m.alert.HasActiveAlert() { return m, tea.Quit } case "+", "=": m.count++ m.alert = m.alert.WithPosition(bubbleup.TopRightPosition) alertCmd = m.alert.NewAlertCmd("Counter", fmt.Sprintf("Count: %d", m.count)) case "-": m.count-- m.alert = m.alert.WithPosition(bubbleup.BottomRightPosition) alertCmd = m.alert.NewAlertCmd(bubbleup.WarnKey, fmt.Sprintf("Decreased to %d", m.count)) case "r": m.count = 0 m.alert = m.alert.WithPosition(bubbleup.TopCenterPosition) alertCmd = m.alert.NewAlertCmd(bubbleup.InfoKey, "Counter reset!") case "e": m.alert = m.alert.WithPosition(bubbleup.BottomCenterPosition) alertCmd = m.alert.NewAlertCmd(bubbleup.ErrorKey, "This is an error demonstration with a longer message to show text wrapping") } } outAlert, outCmd := m.alert.Update(msg) m.alert = outAlert.(bubbleup.AlertModel) return m, tea.Batch(alertCmd, outCmd) } func (m model) View() string { style := lipgloss.NewStyle(). Width(60). Height(15). Padding(2). Border(lipgloss.RoundedBorder()). BorderForeground(lipgloss.Color("#00FFFF")) content := fmt.Sprintf(`BubbleUp Demo Current Count: %d Keys: +/- : Increment/Decrement (shows alert) r : Reset counter e : Show error alert esc : Dismiss alert or quit q : Quit`, m.count) view := style.Render(content) // Always render alert overlay last return m.alert.Render(view) } func main() { p := tea.NewProgram(initialModel(), tea.WithAltScreen()) if _, err := p.Run(); err != nil { fmt.Printf("Error: %v\n", err) } } ``` -------------------------------- ### Set Alert Position Source: https://github.com/daltonsw/bubbleup/blob/main/README.md Go code examples showing how to dynamically set the position of alerts using `WithPosition()`. This allows alerts to appear in different locations on the screen, such as top-right or bottom-center. ```go // Show error at top-right m.alert = m.alert.WithPosition(bubbleup.TopRightPosition) alertCmd = m.alert.NewAlertCmd(bubbleup.ErrorKey, "Connection failed") // Show success at bottom-center m.alert = m.alert.WithPosition(bubbleup.BottomCenterPosition) alertCmd = m.alert.NewAlertCmd(bubbleup.InfoKey, "File saved") ``` -------------------------------- ### Integrating Alerts in Update Method Source: https://github.com/daltonsw/bubbleup/blob/main/README.md Demonstrates how to initialize an alert command, process messages within the update cycle, and reassign the alert model state. ```go alertCmd = m.alert.NewAlertCmd(bubbleup.InfoKey, "New info alert.") outAlert, outCmd := m.alert.Update(msg) m.alert = outAlert.(bubbleup.AlertModel) return m, tea.Batch(alertCmd, outCmd) ``` -------------------------------- ### Configure Dynamic Alert Widths Source: https://github.com/daltonsw/bubbleup/blob/main/README.md Demonstrates how to enable dynamic alert sizing by using the WithMinWidth method. This allows alerts to resize based on message content within a defined range. ```go m.alert = bubbleup.NewAlertModel(50, true, 10*time.Second).WithMinWidth(15) alertCmd = m.alert.NewAlertCmd(bubbleup.InfoKey, "Done") alertCmd = m.alert.NewAlertCmd(bubbleup.ErrorKey, "This is a longer error message") alertCmd = m.alert.NewAlertCmd(bubbleup.ErrorKey, "This is a super, extra longer error message that will wrap") ``` -------------------------------- ### Import BubbleUp and BubbleTea Source: https://github.com/daltonsw/bubbleup/blob/main/README.md Go code snippet demonstrating how to import the BubbleUp module and the BubbleTea framework into your project. This is necessary for using BubbleUp's features. ```go import ( "go.dalton.dog/bubbleup" tea "github.com/charmbracelet/bubbletea" ) ``` -------------------------------- ### Configure Alert Prefixes and Fonts Source: https://context7.com/daltonsw/bubbleup/llms.txt Shows how to toggle between ASCII, Unicode, and NerdFont prefixes to ensure compatibility and visual preference in different terminal environments. ```go asciiAlert := bubbleup.NewAlertModel(50, false, 10*time.Second) unicodeAlert := bubbleup.NewAlertModel(50, false, 10*time.Second).WithUnicodePrefix() nerdFontAlert := bubbleup.NewAlertModel(50, true, 10*time.Second) ``` -------------------------------- ### Configure Alert Model with Method Chaining Source: https://github.com/daltonsw/bubbleup/blob/main/README.md Demonstrates advanced configuration of a BubbleUp alert model using method chaining. This allows for setting minimum width, position, Unicode prefixes, and enabling ESC key dismissal. ```go m.alert = bubbleup.NewAlertModel(50, false, 10*time.Second). WithMinWidth(15). // Enable dynamic width (15-50 chars) WithPosition(bubbleup.TopRightPosition). // Position at top-right WithUnicodePrefix(). // Use Unicode symbols WithAllowEscToClose() // Allow ESC to dismiss alerts ``` -------------------------------- ### Configure Alert Positioning Source: https://context7.com/daltonsw/bubbleup/llms.txt Demonstrates how to set the screen position for alerts using the WithPosition method. Supports six distinct screen locations and allows for method chaining. ```go alert = alert.WithPosition(bubbleup.TopLeftPosition) alert = alert.WithPosition(bubbleup.TopCenterPosition) alert = alert.WithPosition(bubbleup.TopRightPosition) alert = alert.WithPosition(bubbleup.BottomLeftPosition) alert = alert.WithPosition(bubbleup.BottomCenterPosition) alert = alert.WithPosition(bubbleup.BottomRightPosition) ``` -------------------------------- ### Registering Custom Alert Types Source: https://github.com/daltonsw/bubbleup/blob/main/README.md Shows how to define a custom alert using the AlertDefinition struct and register it with the alert model. ```go myCustomAlert := AlertDefinition{ Key: "CoolAlert", ForeColor: "#123456", Prefix: ":)" } m.alertModel.RegisterNewAlertType(myCustomAlert) outAlertCmd := m.alert.NewAlertCmd("CoolAlert", "My really cool alert message") ``` -------------------------------- ### Enable and Handle Keyboard Dismissal Source: https://github.com/daltonsw/bubbleup/blob/main/README.md Shows how to enable the Escape key to close alerts and how to properly check for active alerts in the Update loop to prevent conflicts with application-level key bindings. ```go m.alert = bubbleup.NewAlertModel(50, true, 10*time.Second).WithAllowEscToClose() func (m myModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { var alertCmd tea.Cmd switch msg := msg.(type) { case tea.KeyMsg: switch msg.String() { case "esc": if !m.alert.HasActiveAlert() { return m, tea.Quit } case "q": return m, tea.Quit case "s": alertCmd = m.alert.NewAlertCmd(bubbleup.InfoKey, "File saved") } } outAlert, outCmd := m.alert.Update(msg) m.alert = outAlert.(bubbleup.AlertModel) return m, tea.Batch(alertCmd, outCmd) } ``` -------------------------------- ### Render Alert Overlay in Bubbletea View Source: https://context7.com/daltonsw/bubbleup/llms.txt Demonstrates how to integrate the bubbleup alert model into a Bubbletea application. The Render method should be called as the final step in the View function to ensure the alert is correctly layered over existing content. ```go func (m myModel) View() string { style := lipgloss.NewStyle(). Width(80). Height(24). Border(lipgloss.RoundedBorder()) content := style.Render(m.content) // Render alert overlay as the LAST step return m.alert.Render(content) } ``` -------------------------------- ### Initialize AlertModel in BubbleTea Source: https://context7.com/daltonsw/bubbleup/llms.txt Creates and configures a new AlertModel instance. This model manages the state, timing, and rendering of alerts within a BubbleTea application. ```go package main import ( "time" tea "github.com/charmbracelet/bubbletea" "go.dalton.dog/bubbleup" ) type myModel struct { alert bubbleup.AlertModel } func main() { alertModel := bubbleup.NewAlertModel(50, true, 10*time.Second) m := myModel{alert: *alertModel} p := tea.NewProgram(m, tea.WithAltScreen()) p.Run() } ``` -------------------------------- ### Set Alert Font and Symbol Prefixes Source: https://github.com/daltonsw/bubbleup/blob/main/README.md Configures the alert model to use different icon sets, ranging from NerdFonts for aesthetic appeal to ASCII for maximum compatibility. ```go // Unicode fonts (recommended for portability) m.alert = bubbleup.NewAlertModel(50, false, 10*time.Second).WithUnicodePrefix() // NerdFont (requires NerdFont installation on user's system) m.alert = bubbleup.NewAlertModel(50, true, 10*time.Second) // ASCII (maximum compatibility) m.alert = bubbleup.NewAlertModel(50, false, 10*time.Second) ``` -------------------------------- ### Create Alert Command Source: https://context7.com/daltonsw/bubbleup/llms.txt Generates a tea.Cmd to display an alert with a specific type and message. This command should be returned from the Update() method and batched with other commands. Built-in types include InfoKey, WarnKey, ErrorKey, and DebugKey. ```go package main import ( "time" tea "github.com/charmbracelet/bubbletea" "go.dalton.dog/bubbleup" ) type myModel struct { alert bubbleup.AlertModel } func (m myModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { var alertCmd tea.Cmd switch msg := msg.(type) { case tea.KeyMsg: switch msg.String() { case "i": // Trigger info alert (green) alertCmd = m.alert.NewAlertCmd(bubbleup.InfoKey, "Operation completed successfully") case "w": // Trigger warning alert (yellow) alertCmd = m.alert.NewAlertCmd(bubbleup.WarnKey, "Disk space running low") case "e": // Trigger error alert (red) alertCmd = m.alert.NewAlertCmd(bubbleup.ErrorKey, "Connection failed") case "d": // Trigger debug alert (magenta) alertCmd = m.alert.NewAlertCmd(bubbleup.DebugKey, "Debug: value=42") } } outAlert, outCmd := m.alert.Update(msg) m.alert = outAlert.(bubbleup.AlertModel) return m, tea.Batch(alertCmd, outCmd) } ``` -------------------------------- ### WithMinWidth Source: https://context7.com/daltonsw/bubbleup/llms.txt Configures dynamic width for alerts, adjusting size based on message length. ```APIDOC ## WithMinWidth ### Description Enables dynamic width mode where alert width varies between `minWidth` and the maximum width based on message length. Short messages produce narrow alerts, long messages produce wider alerts up to the maximum. ### Method `WithMinWidth(minWidth int)` ### Endpoint `AlertModel.WithMinWidth` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```go package main import ( "time" "go.dalton.dog/bubbleup" ) func configureDynamicWidth() { // Fixed width mode (default): all alerts are exactly 50 chars wide fixedAlert := bubbleup.NewAlertModel(50, false, 10*time.Second) // Dynamic width mode: alerts size between 15-50 chars based on message dynamicAlert := bubbleup.NewAlertModel(50, false, 10*time.Second). WithMinWidth(15) // Short message -> ~15-20 char wide alert // alertCmd = dynamicAlert.NewAlertCmd(bubbleup.InfoKey, "Done") // Long message -> ~45-50 char wide alert with text wrapping // alertCmd = dynamicAlert.NewAlertCmd(bubbleup.ErrorKey, "This is a longer error message that will wrap") } ``` ### Response #### Success Response (200) - **AlertModel** (*bubbleup.AlertModel) - A new AlertModel instance with the updated minimum width. #### Response Example ```json { "example": "// AlertModel configured for dynamic width." } ``` ``` -------------------------------- ### WithUnicodePrefix Source: https://context7.com/daltonsw/bubbleup/llms.txt Switches alert prefixes to use Unicode symbols. ```APIDOC ## WithUnicodePrefix ### Description Switches alert prefixes to use Unicode symbols instead of ASCII or NerdFont icons. Unicode symbols work in most modern terminals without requiring special font installation. ### Method `WithUnicodePrefix()` ### Endpoint `AlertModel.WithUnicodePrefix` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```go package main import ( "time" "go.dalton.dog/bubbleup" ) func configureFonts() { // ASCII mode (maximum compatibility): (i), (!), [!!], (?) asciiAlert := bubbleup.NewAlertModel(50, false, 10*time.Second) // Unicode mode (works ~everywhere): Unicode symbols unicodeAlert := bubbleup.NewAlertModel(50, false, 10*time.Second). WithUnicodePrefix() // NerdFont mode (requires NerdFont installation): Beautiful icons nerdFontAlert := bubbleup.NewAlertModel(50, true, 10*time.Second) } ``` ### Response #### Success Response (200) - **AlertModel** (*bubbleup.AlertModel) - A new AlertModel instance with Unicode prefixes enabled. #### Response Example ```json { "example": "// AlertModel configured to use Unicode prefixes." } ``` ``` -------------------------------- ### Enable Dynamic Alert Width Source: https://context7.com/daltonsw/bubbleup/llms.txt Configures the alert model to use dynamic width, allowing alerts to resize between a minimum and maximum width based on the message content length. ```go dynamicAlert := bubbleup.NewAlertModel(50, false, 10*time.Second).WithMinWidth(15) ``` -------------------------------- ### WithPosition Source: https://context7.com/daltonsw/bubbleup/llms.txt Configures the screen position for alerts, supporting chaining. ```APIDOC ## WithPosition ### Description Sets the screen position where alerts will appear. Returns a new AlertModel with the updated position, allowing method chaining. Position can be changed dynamically between alerts. ### Method `WithPosition(position string)` ### Endpoint `AlertModel.WithPosition` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```go package main import ( "time" "go.dalton.dog/bubbleup" ) func configurePositions() { alert := bubbleup.NewAlertModel(50, false, 10*time.Second) // Available positions: alert = alert.WithPosition(bubbleup.TopLeftPosition) // Default alert = alert.WithPosition(bubbleup.TopCenterPosition) // Top center alert = alert.WithPosition(bubbleup.TopRightPosition) // Top right corner alert = alert.WithPosition(bubbleup.BottomLeftPosition) // Bottom left alert = alert.WithPosition(bubbleup.BottomCenterPosition) // Bottom center alert = alert.WithPosition(bubbleup.BottomRightPosition) // Bottom right corner // Chain with other configuration methods alert = bubbleup.NewAlertModel(50, false, 10*time.Second). WithPosition(bubbleup.TopRightPosition). WithMinWidth(15). WithUnicodePrefix() } ``` ### Response #### Success Response (200) - **AlertModel** (*bubbleup.AlertModel) - A new AlertModel instance with the updated position. #### Response Example ```json { "example": "// AlertModel with updated position." } ``` ``` -------------------------------- ### NewAlertCmd Source: https://context7.com/daltonsw/bubbleup/llms.txt Creates a tea.Cmd that triggers an alert with the specified type and message. The command should be returned from your Update() method and batched with other commands. Built-in alert types are InfoKey, WarnKey, ErrorKey, and DebugKey. ```APIDOC ## NewAlertCmd ### Description Creates a tea.Cmd that triggers an alert with the specified type and message. The command should be returned from your Update() method and batched with other commands. Built-in alert types are InfoKey, WarnKey, ErrorKey, and DebugKey. ### Method This is a method on the AlertModel. ### Endpoint N/A (Method on a model) ### Parameters - **alertType** (string) - Required - The key for the alert type (e.g., bubbleup.InfoKey, bubbleup.WarnKey). - **message** (string) - Required - The message to display in the alert. ### Request Example ```go // Inside your Update function: var alertCmd tea.Cmd // Trigger an info alert alertCmd = m.alert.NewAlertCmd(bubbleup.InfoKey, "File saved!") // Batch with other commands return m, tea.Batch(alertCmd, otherCmd) ``` ### Response Returns a tea.Cmd that, when executed, displays the alert. ``` -------------------------------- ### NewAlertModel Source: https://context7.com/daltonsw/bubbleup/llms.txt Initializes a new AlertModel with customizable parameters for width, font, and duration. ```APIDOC ## NewAlertModel ### Description Creates and initializes a new AlertModel with default alert types. Parameters control maximum width, font style preference, and auto-dismiss duration. ### Method `NewAlertModel(maxWidth int, useNerdFonts bool, defaultDuration time.Duration)` ### Endpoint `bubbleup.NewAlertModel` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```go package main import ( "time" tea "github.com/charmbracelet/bubbletea" "go.dalton.dog/bubbleup" ) type myModel struct { alert bubbleup.AlertModel } func main() { // Create alert model: max width 50 chars, use NerdFont icons, 10 second duration alertModel := bubbleup.NewAlertModel(50, true, 10*time.Second) // Or with ASCII fallback (no special fonts required) alertModel = bubbleup.NewAlertModel(50, false, 10*time.Second) m := myModel{alert: *alertModel} p := tea.NewProgram(m, tea.WithAltScreen()) p.Run() } ``` ### Response #### Success Response (200) - **AlertModel** (*bubbleup.AlertModel) - An initialized AlertModel. #### Response Example ```json { "example": "// AlertModel is initialized and ready to be used." } ``` ``` -------------------------------- ### Check Active Alert State for Input Handling Source: https://context7.com/daltonsw/bubbleup/llms.txt Shows how to use the HasActiveAlert method to conditionally process keyboard inputs. This is useful for preventing application-level actions like quitting when an alert is currently visible to the user. ```go func (m myModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyMsg: if msg.String() == "esc" { if m.alert.HasActiveAlert() { // Alert is active, do not quit } else { return m, tea.Quit } } } // ... rest of update logic } ``` -------------------------------- ### Register Custom Alert Source: https://github.com/daltonsw/bubbleup/blob/main/README.md How to define and register a new alert type in the BubbleUp system. ```APIDOC ## Register Custom Alert ### Description Defines a custom alert structure and registers it with the alert model. ### Parameters - **Key** (string) - Required - Unique identifier for the alert. - **ForeColor** (string) - Required - Hex color string for the alert foreground. - **Prefix** (string) - Optional - Symbol or string prefix for message contents. ### Request Example ```go myCustomAlert := AlertDefinition{ Key: "CoolAlert", ForeColor: "#123456", Prefix: ":)" } m.alertModel.RegisterNewAlertType(myCustomAlert) ``` ``` -------------------------------- ### Render Method Source: https://context7.com/daltonsw/bubbleup/llms.txt The Render method overlays the active alert onto your view content. It should be called as the final step in your View() method to ensure the alert appears on top of all other content. ```APIDOC ## Render ### Description Overlays the active alert onto your view content. This method should be called as the final step in your View() method after composing all other content. ### Method N/A (Method Call) ### Endpoint `bubbleup.AlertModel.Render(content string) string` ### Parameters #### Request Body - **content** (string) - Required - The base view content string to which the alert will be applied. ### Response - **Returns** (string) - The final rendered content string with the alert overlay applied at the configured position. ``` -------------------------------- ### Update Alert State Source: https://github.com/daltonsw/bubbleup/blob/main/README.md How to handle alert updates within the BubbleTea Update method. ```APIDOC ## Update Alert State ### Description Passes messages to the alert model and handles the resulting command batching. ### Method Internal Update Loop ### Parameters - **msg** (tea.Msg) - Required - The message received by the BubbleTea update loop. ### Request Example ```go alertCmd = m.alert.NewAlertCmd(bubbleup.InfoKey, "New info alert.") outAlert, outCmd := m.alert.Update(msg) m.alert = outAlert.(bubbleup.AlertModel) return m, tea.Batch(alertCmd, outCmd) ``` ``` -------------------------------- ### Register Custom Alert Type Source: https://context7.com/daltonsw/bubbleup/llms.txt Allows the registration of custom alert types with unique keys, foreground colors, prefixes, and optional styling. This extends BubbleUp's alert capabilities beyond the default types. ```go package main import ( "time" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" "go.dalton.dog/bubbleup" ) type myModel struct { alert bubbleup.AlertModel } func setupCustomAlerts() myModel { alert := bubbleup.NewAlertModel(50, false, 10*time.Second) // Register a custom "Success" alert type successAlert := bubbleup.AlertDefinition{ Key: "Success", ForeColor: "#00FF7F", // Spring green Prefix: "✓", } alert.RegisterNewAlertType(successAlert) // Register a custom "Network" alert with custom style networkAlert := bubbleup.AlertDefinition{ Key: "Network", ForeColor: "#00BFFF", // Deep sky blue Prefix: "⚡", Style: lipgloss.NewStyle().Bold(true).BorderStyle(lipgloss.DoubleBorder()), } alert.RegisterNewAlertType(networkAlert) return myModel{alert: *alert} } func (m myModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { var alertCmd tea.Cmd switch msg := msg.(type) { case tea.KeyMsg: switch msg.String() { case "s": // Use custom alert type alertCmd = m.alert.NewAlertCmd("Success", "Upload complete!") case "n": alertCmd = m.alert.NewAlertCmd("Network", "Connected to server") } } outAlert, outCmd := m.alert.Update(msg) m.alert = outAlert.(bubbleup.AlertModel) return m, tea.Batch(alertCmd, outCmd) } ``` -------------------------------- ### WithAllowEscToClose Source: https://context7.com/daltonsw/bubbleup/llms.txt Enables the ESC key to dismiss alerts before their timeout expires. When enabled, use HasActiveAlert() to check if an alert is displayed before handling ESC in your own Update() logic. ```APIDOC ## WithAllowEscToClose ### Description Enables the ESC key to dismiss alerts before their timeout expires. When enabled, use HasActiveAlert() to check if an alert is displayed before handling ESC in your own Update() logic. ### Method This is a method chaining function on the AlertModel. ### Endpoint N/A (Method on a model) ### Parameters None directly for this method, it modifies the AlertModel's behavior. ### Request Example ```go // Assuming 'alert' is an instance of bubbleup.AlertModel alert = alert.WithAllowEscToClose() ``` ### Response Returns the modified AlertModel instance. ``` -------------------------------- ### Enable ESC to Close Alerts Source: https://context7.com/daltonsw/bubbleup/llms.txt Configures the alert system to allow the ESC key to dismiss active alerts before their timeout expires. It's recommended to check for active alerts using HasActiveAlert() before handling ESC in your own update logic to prevent conflicts. ```go package main import ( "time" tea "github.com/charmbracelet/bubbletea" "go.dalton.dog/bubbleup" ) type myModel struct { alert bubbleup.AlertModel } func (m myModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { var alertCmd tea.Cmd switch msg := msg.(type) { case tea.KeyMsg: switch msg.String() { case "esc": // Only quit if no alert is active (let alert handle ESC first) if !m.alert.HasActiveAlert() { return m, tea.Quit } case "q": return m, tea.Quit case "s": alertCmd = m.alert.NewAlertCmd(bubbleup.InfoKey, "File saved!") } } // Always pass messages to alert model outAlert, outCmd := m.alert.Update(msg) m.alert = outAlert.(bubbleup.AlertModel) return m, tea.Batch(alertCmd, outCmd) } func setupEscClose() { alert := bubbleup.NewAlertModel(50, false, 10*time.Second). WithAllowEscToClose() } ``` -------------------------------- ### RegisterNewAlertType Source: https://context7.com/daltonsw/bubbleup/llms.txt Registers a custom alert type with its own key, color, prefix, and optional style. Use this to create domain-specific alerts beyond the built-in Info, Warn, Error, and Debug types. ```APIDOC ## RegisterNewAlertType ### Description Registers a custom alert type with its own key, color, prefix, and optional style. Use this to create domain-specific alerts beyond the built-in Info, Warn, Error, and Debug types. ### Method This is a method on the AlertModel. ### Endpoint N/A (Method on a model) ### Parameters - **definition** (bubbleup.AlertDefinition) - Required - An object defining the custom alert type. - **Key** (string) - Required - The unique identifier for the alert type. - **ForeColor** (string) - Optional - The foreground color of the alert message (e.g., hex code). - **Prefix** (string) - Optional - A prefix character or string for the alert. - **Style** (lipgloss.Style) - Optional - Custom styling for the alert. ### Request Example ```go // Assuming 'alert' is an instance of bubbleup.AlertModel // Define a custom success alert successAlert := bubbleup.AlertDefinition{ Key: "Success", ForeColor: "#00FF7F", // Spring green Prefix: "✓", } alert.RegisterNewAlertType(successAlert) // Use the custom alert type alertCmd = alert.NewAlertCmd("Success", "Upload complete!") ``` ### Response This method modifies the AlertModel in place and does not return a value. ``` -------------------------------- ### HasActiveAlert Method Source: https://context7.com/daltonsw/bubbleup/llms.txt The HasActiveAlert method returns a boolean indicating if an alert is currently being displayed. This is useful for conditional logic, such as preventing app-wide key bindings when an alert is active. ```APIDOC ## HasActiveAlert ### Description Returns true if an alert is currently being displayed. Use this to conditionally handle keyboard input when alerts might capture certain keys. ### Method N/A (Method Call) ### Endpoint `bubbleup.AlertModel.HasActiveAlert() bool` ### Response - **Returns** (bool) - True if an alert is currently visible, false otherwise. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.