()
| 190 | } |
| 191 | |
| 192 | func (m *Logs) rebuildContent() { |
| 193 | m.wasAtBottom = m.viewport.AtBottom() || m.lastVersion == 0 |
| 194 | |
| 195 | lines := m.streamer.Fetch(docker.DefaultLogBufferSize) |
| 196 | m.lastVersion = m.streamer.Version() |
| 197 | m.lastFilterText = m.filterText |
| 198 | |
| 199 | if len(lines) == 0 { |
| 200 | if !m.streamer.Ready() { |
| 201 | return |
| 202 | } |
| 203 | if m.filterText != "" { |
| 204 | m.viewport.SetContent(m.centeredMessage("No logs match the filter")) |
| 205 | } else { |
| 206 | m.viewport.SetContent(m.centeredMessage("No logs yet...")) |
| 207 | } |
| 208 | return |
| 209 | } |
| 210 | |
| 211 | var filtered []string |
| 212 | filterLower := strings.ToLower(m.filterText) |
| 213 | for _, line := range lines { |
| 214 | if filterLower == "" || strings.Contains(strings.ToLower(line.Content), filterLower) { |
| 215 | filtered = append(filtered, line.Content) |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | if len(filtered) == 0 { |
| 220 | m.viewport.SetContent(m.centeredMessage("No logs match the filter")) |
| 221 | return |
| 222 | } |
| 223 | |
| 224 | m.viewport.SetContent(strings.Join(filtered, "\n")) |
| 225 | |
| 226 | if m.wasAtBottom { |
| 227 | m.viewport.GotoBottom() |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | func (m Logs) centeredMessage(msg string) string { |
| 232 | return lipgloss.Place(m.viewport.Width(), m.viewport.Height(), lipgloss.Center, lipgloss.Center, msg) |
no test coverage detected