mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-25 08:31:03 +00:00
better search logic
This commit is contained in:
parent
702361559f
commit
e6d4a97545
10 changed files with 13 additions and 32 deletions
|
|
@ -71,10 +71,6 @@ func (gui *Gui) getContainersPanel() *SideListPanel[*commands.Container] {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getSearchStrings: func(container *commands.Container) []string {
|
|
||||||
// TODO: think about more things to search on
|
|
||||||
return []string{container.Name}
|
|
||||||
},
|
|
||||||
getContextCacheKey: func(container *commands.Container) string {
|
getContextCacheKey: func(container *commands.Container) string {
|
||||||
return container.ID + "-" + container.Container.State
|
return container.ID + "-" + container.Container.State
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,6 @@ type guiState struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type searchingState struct {
|
type searchingState struct {
|
||||||
view *gocui.View
|
|
||||||
panel ISideListPanel
|
panel ISideListPanel
|
||||||
isSearching bool
|
isSearching bool
|
||||||
searchString string
|
searchString string
|
||||||
|
|
|
||||||
|
|
@ -37,9 +37,6 @@ func (gui *Gui) getImagesPanel() *SideListPanel[*commands.Image] {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getSearchStrings: func(image *commands.Image) []string {
|
|
||||||
return []string{image.Name, image.Tag}
|
|
||||||
},
|
|
||||||
getContextCacheKey: func(image *commands.Image) string {
|
getContextCacheKey: func(image *commands.Image) string {
|
||||||
return image.ID
|
return image.ID
|
||||||
},
|
},
|
||||||
|
|
@ -113,7 +110,7 @@ func (gui *Gui) refreshStateImages() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) filterString(view *gocui.View) string {
|
func (gui *Gui) filterString(view *gocui.View) string {
|
||||||
if gui.State.Searching.view != view {
|
if gui.State.Searching.panel != nil && gui.State.Searching.panel.View() != view {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -63,9 +63,6 @@ type SideListPanel[T comparable] struct {
|
||||||
|
|
||||||
gui IGui
|
gui IGui
|
||||||
|
|
||||||
// returns strings that can be filtered on
|
|
||||||
getSearchStrings func(item T) []string
|
|
||||||
|
|
||||||
// this filter is applied on top of additional default filters
|
// this filter is applied on top of additional default filters
|
||||||
filter func(T) bool
|
filter func(T) bool
|
||||||
sort func(a, b T) bool
|
sort func(a, b T) bool
|
||||||
|
|
@ -244,7 +241,7 @@ func (self *SideListPanel[T]) FilterAndSort() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if lo.SomeBy(self.gui.IgnoreStrings(), func(ignore string) bool {
|
if lo.SomeBy(self.gui.IgnoreStrings(), func(ignore string) bool {
|
||||||
return lo.SomeBy(self.getSearchStrings(item), func(searchString string) bool {
|
return lo.SomeBy(self.getDisplayStrings(item), func(searchString string) bool {
|
||||||
return strings.Contains(searchString, ignore)
|
return strings.Contains(searchString, ignore)
|
||||||
})
|
})
|
||||||
}) {
|
}) {
|
||||||
|
|
@ -252,7 +249,7 @@ func (self *SideListPanel[T]) FilterAndSort() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if filterString != "" {
|
if filterString != "" {
|
||||||
return lo.SomeBy(self.getSearchStrings(item), func(searchString string) bool {
|
return lo.SomeBy(self.getDisplayStrings(item), func(searchString string) bool {
|
||||||
return strings.Contains(searchString, filterString)
|
return strings.Contains(searchString, filterString)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,11 +31,8 @@ func (gui *Gui) getMenuPanel() *SideListPanel[*MenuItem] {
|
||||||
},
|
},
|
||||||
noItemsMessage: "",
|
noItemsMessage: "",
|
||||||
gui: gui.intoInterface(),
|
gui: gui.intoInterface(),
|
||||||
getSearchStrings: func(menuItem *MenuItem) []string {
|
onClick: gui.onMenuPress,
|
||||||
return menuItem.LabelColumns
|
sort: nil,
|
||||||
},
|
|
||||||
onClick: gui.onMenuPress,
|
|
||||||
sort: nil,
|
|
||||||
getDisplayStrings: func(menuItem *MenuItem) []string {
|
getDisplayStrings: func(menuItem *MenuItem) []string {
|
||||||
return menuItem.LabelColumns
|
return menuItem.LabelColumns
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -54,9 +54,6 @@ func (gui *Gui) getProjectPanel() *SideListPanel[*commands.Project] {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getSearchStrings: func(project *commands.Project) []string {
|
|
||||||
return []string{project.Name}
|
|
||||||
},
|
|
||||||
getContextCacheKey: func(project *commands.Project) string {
|
getContextCacheKey: func(project *commands.Project) string {
|
||||||
return project.Name
|
return project.Name
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ func (gui *Gui) handleOpenSearch() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
gui.State.Searching.isSearching = true
|
gui.State.Searching.isSearching = true
|
||||||
gui.State.Searching.view = panel.View()
|
|
||||||
gui.State.Searching.panel = panel
|
gui.State.Searching.panel = panel
|
||||||
|
|
||||||
return gui.switchFocus(gui.Views.Search)
|
return gui.switchFocus(gui.Views.Search)
|
||||||
|
|
@ -20,6 +19,7 @@ func (gui *Gui) handleOpenSearch() error {
|
||||||
func (gui *Gui) onNewSearchString(value string) error {
|
func (gui *Gui) onNewSearchString(value string) error {
|
||||||
// need to refresh the right list panel.
|
// need to refresh the right list panel.
|
||||||
gui.State.Searching.searchString = value
|
gui.State.Searching.searchString = value
|
||||||
|
gui.ResetOrigin(gui.State.Searching.panel.View())
|
||||||
return gui.State.Searching.panel.RerenderList()
|
return gui.State.Searching.panel.RerenderList()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -45,11 +45,12 @@ func (gui *Gui) escapeSearchPrompt() error {
|
||||||
func (gui *Gui) clearSearch() error {
|
func (gui *Gui) clearSearch() error {
|
||||||
gui.State.Searching.searchString = ""
|
gui.State.Searching.searchString = ""
|
||||||
gui.State.Searching.isSearching = false
|
gui.State.Searching.isSearching = false
|
||||||
gui.State.Searching.view = nil
|
|
||||||
panel := gui.State.Searching.panel
|
panel := gui.State.Searching.panel
|
||||||
gui.State.Searching.panel = nil
|
gui.State.Searching.panel = nil
|
||||||
gui.Views.Search.ClearTextArea()
|
gui.Views.Search.ClearTextArea()
|
||||||
|
|
||||||
|
gui.ResetOrigin(panel.View())
|
||||||
|
|
||||||
return panel.RerenderList()
|
return panel.RerenderList()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,10 +52,6 @@ func (gui *Gui) getServicesPanel() *SideListPanel[*commands.Service] {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getSearchStrings: func(service *commands.Service) []string {
|
|
||||||
// TODO: think about more things to search on
|
|
||||||
return []string{service.Name}
|
|
||||||
},
|
|
||||||
getContextCacheKey: func(service *commands.Service) string {
|
getContextCacheKey: func(service *commands.Service) string {
|
||||||
if service.Container == nil {
|
if service.Container == nil {
|
||||||
return service.ID
|
return service.ID
|
||||||
|
|
|
||||||
|
|
@ -230,6 +230,11 @@ func (gui *Gui) FocusY(selectedY int, lineCount int, v *gocui.View) {
|
||||||
gui.focusY(selectedY, lineCount, v)
|
gui.focusY(selectedY, lineCount, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) ResetOrigin(v *gocui.View) {
|
||||||
|
_ = v.SetOrigin(0, 0)
|
||||||
|
_ = v.SetCursor(0, 0)
|
||||||
|
}
|
||||||
|
|
||||||
func (gui *Gui) cleanString(s string) string {
|
func (gui *Gui) cleanString(s string) string {
|
||||||
output := string(bom.Clean([]byte(s)))
|
output := string(bom.Clean([]byte(s)))
|
||||||
return utils.NormalizeLinefeeds(output)
|
return utils.NormalizeLinefeeds(output)
|
||||||
|
|
|
||||||
|
|
@ -30,10 +30,6 @@ func (gui *Gui) getVolumesPanel() *SideListPanel[*commands.Volume] {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getSearchStrings: func(volume *commands.Volume) []string {
|
|
||||||
// TODO: think about more things to search on
|
|
||||||
return []string{volume.Name}
|
|
||||||
},
|
|
||||||
getContextCacheKey: func(volume *commands.Volume) string {
|
getContextCacheKey: func(volume *commands.Volume) string {
|
||||||
return volume.Name
|
return volume.Name
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue