-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add interactive mode for run subcmd (#49)
fixes #30 --------- Signed-off-by: Mario Constanti <github@constanti.de>
- Loading branch information
1 parent
c8b129c
commit ca94b89
Showing
12 changed files
with
309 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
package command | ||
|
||
import ( | ||
bubbletable "github.com/charmbracelet/bubbles/table" | ||
tea "github.com/charmbracelet/bubbletea" | ||
"github.com/charmbracelet/lipgloss" | ||
|
||
"github.com/bavarianbidi/kubectl-dpm/pkg/profile" | ||
"github.com/bavarianbidi/kubectl-dpm/pkg/table" | ||
) | ||
|
||
type model struct { | ||
table bubbletable.Model | ||
} | ||
|
||
// initTeaModel initializes the model for the interactive mode | ||
func initTeaModel() model { | ||
// generate a list of profiles which work in interactive mode | ||
interactiveProfiles := profile.InteractiveProfiles() | ||
|
||
// generate the table with image, namespace and matchLabels columns | ||
t := table.GenerateTable(interactiveProfiles, true) | ||
|
||
// read the style config from profile and apply it | ||
profile.CompleteStyle() | ||
|
||
s := bubbletable.DefaultStyles() | ||
s.Header = s.Header. | ||
BorderStyle(lipgloss.NormalBorder()). | ||
Background(lipgloss.Color(profile.Config.Style.HeaderBackgroundColor)). | ||
Foreground(lipgloss.Color(profile.Config.Style.HeaderForegroundColor)). | ||
BorderBottom(true). | ||
Bold(true) | ||
s.Selected = s.Selected. | ||
Foreground(lipgloss.Color(profile.Config.Style.SelectedForegroundColor)). | ||
Background(lipgloss.Color(profile.Config.Style.SelectedBackgroundColor)). | ||
Bold(false) | ||
t.SetStyles(s) | ||
|
||
return model{ | ||
table: t, | ||
} | ||
} | ||
|
||
func (m model) Init() tea.Cmd { | ||
return nil | ||
} | ||
|
||
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { | ||
var cmd tea.Cmd | ||
|
||
if msg, ok := msg.(tea.KeyMsg); ok { | ||
switch msg.Type { | ||
case tea.KeyCtrlC, tea.KeyCtrlD: | ||
return m, tea.Quit | ||
case tea.KeyEnter: | ||
// set the selected profile name | ||
flagProfileName = m.table.SelectedRow()[0] | ||
|
||
return m, tea.Quit | ||
} | ||
} | ||
m.table, cmd = m.table.Update(msg) | ||
return m, cmd | ||
} | ||
|
||
func (m model) View() string { | ||
return m.table.View() + "\n " + m.table.HelpView() + "\n" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.