Skip to content

Commit 456d1dd

Browse files
committed
[feat] add key to clear all selected containers
1 parent c91d96c commit 456d1dd

File tree

5 files changed

+51
-26
lines changed

5 files changed

+51
-26
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ Press `?` in any view to see keyboard shortcuts specific to the current view and
6161

6262
| Key | Action |
6363
|----------------|-------------------------------------------------|
64+
| enter | in container selection view, toggle logs |
65+
| R | deselect all containers and clear logs |
6466
| ↓/j | down one line |
6567
| ↑/k | up one line |
6668
| d | down half page |

internal/app.go

+38-21
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,43 @@ func (m Model) handleEntitiesPageKeyMsg(msg tea.KeyMsg) (Model, tea.Cmd) {
537537
if key.Matches(msg, m.keyMap.Enter) {
538538
selected, selectionActions := m.pages[m.focusedPageType].(page.EntityPage).GetSelectionActions()
539539
if len(selectionActions) > constants.ConfirmSelectionActionsThreshold {
540-
return m.promptToConfirmSelectionActions(selected, selectionActions)
540+
// display a prompt to confirm selection actions
541+
// use the terminology select & deselect instead of activate, get log scanner, etc.
542+
var numToActivate, numToDeactivate int
543+
for _, getLogScanner := range selectionActions {
544+
if getLogScanner {
545+
numToActivate++
546+
} else {
547+
numToDeactivate++
548+
}
549+
}
550+
topLine := fmt.Sprintf("Select %d visible containers", numToActivate)
551+
if numToActivate > 0 && numToDeactivate > 0 {
552+
topLine = fmt.Sprintf("Select %d & deselect %d visible containers", numToActivate, numToDeactivate)
553+
} else if numToDeactivate > 0 {
554+
topLine = fmt.Sprintf("Deselect %d visible containers", numToDeactivate)
555+
}
556+
topLine = fmt.Sprintf("%s for %s", topLine, selected.Type())
557+
bottomLine := fmt.Sprintf("%s?", selected.Container.HumanReadable())
558+
text := []string{topLine, bottomLine}
559+
return m.promptToConfirmSelectionActions(text, selectionActions)
560+
} else {
561+
return m.doSelectionActions(selectionActions)
562+
}
563+
}
564+
565+
// handle deselecting all containers
566+
if key.Matches(msg, m.keyMap.DeselectAll) {
567+
selectionActions := make(map[model.Entity]bool)
568+
containerEntities := m.entityTree.GetContainerEntities()
569+
for i := range containerEntities {
570+
if !containerEntities[i].State.ActivatesWhenSelected() {
571+
selectionActions[containerEntities[i]] = false
572+
}
573+
}
574+
if len(selectionActions) > constants.ConfirmSelectionActionsThreshold {
575+
text := []string{fmt.Sprintf("Deselect all %d containers?", len(selectionActions))}
576+
return m.promptToConfirmSelectionActions(text, selectionActions)
541577
} else {
542578
return m.doSelectionActions(selectionActions)
543579
}
@@ -555,26 +591,7 @@ func (m Model) handleEntitiesPageKeyMsg(msg tea.KeyMsg) (Model, tea.Cmd) {
555591
return m, nil
556592
}
557593

558-
func (m Model) promptToConfirmSelectionActions(selected model.Entity, selectionActions map[model.Entity]bool) (Model, tea.Cmd) {
559-
// display a prompt to confirm selection actions
560-
// use the terminology select & deselect instead of activate, get log scanner, etc.
561-
var numToActivate, numToDeactivate int
562-
for _, getLogScanner := range selectionActions {
563-
if getLogScanner {
564-
numToActivate++
565-
} else {
566-
numToDeactivate++
567-
}
568-
}
569-
topLine := fmt.Sprintf("Select %d visible containers", numToActivate)
570-
if numToActivate > 0 && numToDeactivate > 0 {
571-
topLine = fmt.Sprintf("Select %d & deselect %d visible containers", numToActivate, numToDeactivate)
572-
} else if numToDeactivate > 0 {
573-
topLine = fmt.Sprintf("Deselect %d visible containers", numToDeactivate)
574-
}
575-
topLine = fmt.Sprintf("%s for %s", topLine, selected.Type())
576-
bottomLine := fmt.Sprintf("%s?", selected.Container.HumanReadable())
577-
text := []string{topLine, bottomLine}
594+
func (m Model) promptToConfirmSelectionActions(text []string, selectionActions map[model.Entity]bool) (Model, tea.Cmd) {
578595
m.prompt = prompt.New(true, m.width, m.height-m.topBarHeight, text, m.styles.Inverse)
579596
m.whenPromptConfirm = func() (Model, tea.Cmd) { return m.doSelectionActions(selectionActions) }
580597
return m, nil

internal/help/help.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import (
88

99
func MakeHelp(keyMap keymap.KeyMap, keyColStyle lipgloss.Style) string {
1010
title := lipgloss.NewStyle().Border(lipgloss.NormalBorder()).Padding(0, 1).Render("Help (press any key to hide)")
11-
rowsPerCol := 10
11+
rowsPerCol := 11
1212

1313
generalHelp := lipgloss.JoinVertical(
1414
lipgloss.Center,
1515
"",
16-
formatKeyBindings(keymap.GlobalKeyBindings(keyMap), rowsPerCol, keyColStyle),
16+
formatKeyBindings(keymap.DescriptiveKeyBindings(keyMap), rowsPerCol, keyColStyle),
1717
"",
1818
formatKeyBindings(keymap.LookbackKeyBindings(keyMap), 6, keyColStyle),
1919
)

internal/keymap/keymap.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ type KeyMap struct {
99
Copy key.Binding
1010
Context key.Binding
1111
Enter key.Binding
12+
DeselectAll key.Binding
1213
Filter key.Binding
1314
FilterRegex key.Binding
1415
FilterNextRow key.Binding
@@ -61,6 +62,10 @@ func DefaultKeyMap() KeyMap {
6162
key.WithKeys("enter"),
6263
key.WithHelp("enter", ""), // means different things on different pages
6364
),
65+
DeselectAll: key.NewBinding(
66+
key.WithKeys("shift+r"),
67+
key.WithHelp("R", "deselect all containers"),
68+
),
6469
Filter: key.NewBinding(
6570
key.WithKeys("/"),
6671
key.WithHelp("/", "edit filter"),
@@ -200,9 +205,10 @@ func LookbackKeyBindings(km KeyMap) []key.Binding {
200205
}
201206
}
202207

203-
func GlobalKeyBindings(km KeyMap) []key.Binding {
204-
// available from anywhere on the app
208+
func DescriptiveKeyBindings(km KeyMap) []key.Binding {
205209
return []key.Binding{
210+
WithDesc(km.Enter, "select/deselect containers"),
211+
km.DeselectAll,
206212
km.Logs,
207213
km.LogsFullScreen,
208214
km.Selection,

internal/model/entity.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func (e Entity) Type() string {
120120
} else if e.IsNamespace {
121121
return "namespace"
122122
} else if e.IsPodOwner {
123-
return "podOwner"
123+
return "pod owner"
124124
} else if e.IsPod {
125125
return "pod"
126126
} else {

0 commit comments

Comments
 (0)