showMessage displays a message to the user. This simplified version sets focus directly without QueueUpdateDraw, which eliminates potential deadlocks when called from menu handlers or other UI event contexts. SetFocus will trigger a redraw automatically.
(message string)
| 11 | // which eliminates potential deadlocks when called from menu handlers |
| 12 | // or other UI event contexts. SetFocus will trigger a redraw automatically. |
| 13 | func (a *App) showMessage(message string) { |
| 14 | // Save current focus before showing modal |
| 15 | a.lastFocus = a.GetFocus() |
| 16 | |
| 17 | modal := tview.NewModal(). |
| 18 | SetText(message). |
| 19 | // SetBackgroundColor(theme.Colors.Background). |
| 20 | SetTextColor(theme.Colors.Primary). |
| 21 | AddButtons([]string{"OK"}). |
| 22 | SetDoneFunc(func(buttonIndex int, buttonLabel string) { |
| 23 | a.removePageIfPresent("message") |
| 24 | // Restore focus to the last focused element |
| 25 | if a.lastFocus != nil { |
| 26 | a.SetFocus(a.lastFocus) |
| 27 | } |
| 28 | }) |
| 29 | |
| 30 | a.pages.AddPage("message", modal, false, true) |
| 31 | // Set focus directly - this triggers a redraw without queuing |
| 32 | a.SetFocus(modal) |
| 33 | } |
| 34 | |
| 35 | // showMessageSafe is now an alias to showMessage for backwards compatibility. |
| 36 | // Both use the same safe implementation that avoids QueueUpdateDraw deadlocks. |
no test coverage detected