Skip to content

Commit d371e3e

Browse files
Improved Log Management in the TUI (#71)
* Splitted TUI Split the TUI into focused files so pkg/tui/app.go is now mostly the UI wiring/entrypoint while helpers live alongside it: + pkg/tui/state.go holds constants/enums and uiState/bucket object structs; formatters.go and table_helpers.go hold pure helpers. + View/controller logic now lives in services_view.go, buckets_view.go, and bucket_objects.go; + cross-cutting UI helpers went to dialogs.go, search.go, and auto_refresh.go. + app.go cleaned up accordingly, with redundant definitions removed and imports trimmed. * Improved search functionality + Implemented support for search via "/" across Services, Buckets, Clusters and Details panels, including substrings. * Improved log management in the TUI --------- Co-authored-by: SergioLangaritaBenitez <[email protected]>
1 parent 943cb8c commit d371e3e

File tree

6 files changed

+529
-83
lines changed

6 files changed

+529
-83
lines changed

pkg/tui/app.go

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func Run(ctx context.Context, conf *config.Config) error {
4242
mode: modeServices,
4343
bucketObjects: make(map[string]*bucketObjectState),
4444
serviceDefinitions: make(map[string]string),
45+
logDetails: make(map[string]string),
4546
}
4647

4748
state.statusView.SetBorder(false)
@@ -177,6 +178,20 @@ func Run(ctx context.Context, conf *config.Config) error {
177178
app.SetFocus(state.serviceTable)
178179
return nil
179180
}
181+
case tcell.KeyBackspace, tcell.KeyBackspace2:
182+
if app.GetFocus() == state.detailsView {
183+
app.SetFocus(state.serviceTable)
184+
return nil
185+
}
186+
if app.GetFocus() == state.serviceTable {
187+
state.switchToServices(ctx)
188+
return nil
189+
}
190+
case tcell.KeyEnter:
191+
if app.GetFocus() == state.serviceTable {
192+
state.switchToLogs(ctx)
193+
return nil
194+
}
180195
}
181196

182197
switch event.Rune() {
@@ -217,16 +232,22 @@ func Run(ctx context.Context, conf *config.Config) error {
217232
return nil
218233
}
219234
case 'd', 'D':
220-
if app.GetFocus() == state.serviceTable {
235+
if app.GetFocus() == state.serviceTable && state.modeIsServices() {
221236
state.requestDeletion()
222237
return nil
223238
}
224239
case 'v', 'V':
225-
state.focusDetailsPane()
240+
state.queueUpdate(func() {
241+
if state.app.GetFocus() != state.detailsView {
242+
state.app.SetFocus(state.detailsView)
243+
} else {
244+
state.app.SetFocus(state.serviceTable)
245+
}
246+
})
226247
return nil
227248
case 'l', 'L':
228249
if app.GetFocus() == state.serviceTable {
229-
state.showServiceLogs()
250+
state.switchToLogs(ctx)
230251
return nil
231252
}
232253
case '?':
@@ -303,6 +324,14 @@ func (s *uiState) selectCluster(ctx context.Context, name string) {
303324
}
304325
s.lastSelection = ""
305326
s.currentBucketObjectsKey = ""
327+
s.logEntries = nil
328+
s.currentLogsKey = ""
329+
s.currentLogJobKey = ""
330+
s.currentLogService = ""
331+
s.currentLogCluster = ""
332+
if s.mode == modeLogs {
333+
s.mode = modeServices
334+
}
306335
s.currentCluster = name
307336
mode := s.mode
308337
errMsg, blocked := s.failedClusters[name]
@@ -355,6 +384,8 @@ func (s *uiState) refreshCurrent(ctx context.Context) {
355384
}
356385
if mode == modeBuckets {
357386
go s.loadBuckets(ctx, name, true)
387+
} else if mode == modeLogs {
388+
go s.loadLogs(ctx, name, s.currentLogService, true)
358389
} else {
359390
go s.loadServices(ctx, name, true)
360391
}
@@ -390,6 +421,13 @@ func (s *uiState) modeIsBuckets() bool {
390421
return mode == modeBuckets
391422
}
392423

424+
func (s *uiState) modeIsLogs() bool {
425+
s.mutex.Lock()
426+
mode := s.mode
427+
s.mutex.Unlock()
428+
return mode == modeLogs
429+
}
430+
393431
func (s *uiState) focusDetailsPane() {
394432
s.queueUpdate(func() {
395433
s.app.SetFocus(s.detailsView)
@@ -433,6 +471,10 @@ func (s *uiState) handleSelection(row int, immediate bool) {
433471
s.handleBucketSelection(row, immediate)
434472
return
435473
}
474+
if mode == modeLogs {
475+
s.handleLogSelection(row, immediate)
476+
return
477+
}
436478
s.handleServiceSelection(row, immediate)
437479
}
438480

0 commit comments

Comments
 (0)