MCPcopy
hub / github.com/basecamp/once / rebuildContent

Method rebuildContent

internal/ui/logs.go:192–229  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

190}
191
192func (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
231func (m Logs) centeredMessage(msg string) string {
232 return lipgloss.Place(m.viewport.Width(), m.viewport.Height(), lipgloss.Center, lipgloss.Center, msg)

Callers 3

UpdateMethod · 0.95
handleFilterKeyMethod · 0.95
checkForUpdatesMethod · 0.95

Calls 4

centeredMessageMethod · 0.95
VersionMethod · 0.80
ReadyMethod · 0.80
FetchMethod · 0.45

Tested by

no test coverage detected