Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pkg/gui/keybindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,13 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
}

setUpDownClickBindings("main", gui.scrollUpMain, gui.scrollDownMain, gui.handleMainClick)
bindings = append(bindings, &Binding{
ViewName: "main",
Key: 'c',
Modifier: gocui.ModNone,
Handler: gui.clearMainLogs,
Description: gui.Tr.ClearLogs,
})

for _, panel := range gui.allSidePanels() {
bindings = append(bindings,
Expand Down
21 changes: 21 additions & 0 deletions pkg/gui/main_panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ func (gui *Gui) autoScrollMain(g *gocui.Gui, v *gocui.View) error {
return nil
}

func (gui *Gui) clearMainLogs(g *gocui.Gui, v *gocui.View) error {
if !gui.currentMainTabIsLogs() {
return nil
}

gui.clearMainView()
return nil
}

func (gui *Gui) jumpToTopMain(g *gocui.Gui, v *gocui.View) error {
gui.Views.Main.Autoscroll = false
_ = gui.Views.Main.SetOrigin(0, 0)
Expand Down Expand Up @@ -111,3 +120,15 @@ func (gui *Gui) handleMainClick() error {

return gui.switchFocus(gui.Views.Main)
}

func (gui *Gui) currentMainTabIsLogs() bool {
mainView := gui.Views.Main
if mainView == nil {
return false
}
if mainView.TabIndex < 0 || mainView.TabIndex >= len(mainView.Tabs) {
return false
}

return mainView.Tabs[mainView.TabIndex] == gui.Tr.LogsTitle
}
44 changes: 44 additions & 0 deletions pkg/gui/main_panel_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package gui

import (
"testing"

"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazydocker/pkg/i18n"
)

func TestCurrentMainTabIsLogs(t *testing.T) {
gui := &Gui{
Views: Views{
Main: &gocui.View{
Tabs: []string{"Logs", "Stats"},
TabIndex: 0,
},
},
Tr: &i18n.TranslationSet{
LogsTitle: "Logs",
},
}

if !gui.currentMainTabIsLogs() {
t.Fatalf("expected logs tab to be detected")
}
}

func TestCurrentMainTabIsLogsFalseWhenOtherTabSelected(t *testing.T) {
gui := &Gui{
Views: Views{
Main: &gocui.View{
Tabs: []string{"Logs", "Stats"},
TabIndex: 1,
},
},
Tr: &i18n.TranslationSet{
LogsTitle: "Logs",
},
}

if gui.currentMainTabIsLogs() {
t.Fatalf("expected non-logs tab to return false")
}
}
2 changes: 2 additions & 0 deletions pkg/i18n/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ type TranslationSet struct {
ExecShell string
RunCustomCommand string
ViewBulkCommands string
ClearLogs string
FilterList string
OpenInBrowser string
SortContainersByState string
Expand Down Expand Up @@ -214,6 +215,7 @@ func englishSet() TranslationSet {
ExecShell: "exec shell",
RunCustomCommand: "run predefined custom command",
ViewBulkCommands: "view bulk commands",
ClearLogs: "clear logs",
FilterList: "filter list",
OpenInBrowser: "open in browser (first port is http)",
SortContainersByState: "sort containers by state",
Expand Down