Skip to content

Commit

Permalink
Merge pull request #287 from kaytu-io/feat-add-auto-install
Browse files Browse the repository at this point in the history
fix: Fixes styling
  • Loading branch information
salehkhazaei committed Jul 15, 2024
2 parents 9075b7e + db5fa46 commit f7b4e87
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 33 deletions.
15 changes: 12 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/spf13/cobra"
"gopkg.in/yaml.v3"
"os"
"strings"
"time"
)

Expand Down Expand Up @@ -93,7 +94,7 @@ func Execute() {
func ExecuteContext(ctx context.Context) {
err := server.CheckForUpdate()
if err != nil {
panic(err)
os.Stderr.WriteString("failed to check for kaytu update due to " + err.Error())
}

plugins, err := server.GetPlugins()
Expand All @@ -116,7 +117,15 @@ func ExecuteContext(ctx context.Context) {

autoInstallList := []string{"aws", "kubernetes"}
for _, autoInstall := range autoInstallList {
if _, ok := foundMap[autoInstall]; !ok {
pluginName := autoInstall
if !strings.HasPrefix(pluginName, "github.com") {
pluginName = fmt.Sprintf("github.com/kaytu-io/plugin-%s", pluginName)
}
pluginName = strings.TrimPrefix(pluginName, "github.com/")
owner, repository, _ := strings.Cut(pluginName, "/")
pluginName = owner + "/" + repository

if _, ok := foundMap[pluginName]; !ok {
manager := plugin2.New()
err := manager.StartServer()
if err != nil {
Expand Down Expand Up @@ -188,7 +197,7 @@ func ExecuteContext(ctx context.Context) {
}
err = manager.Install(ctx, repoAddr, "", false, false)
if err != nil {
os.Stderr.WriteString(fmt.Sprintf("failed due to %s\n", err))
os.Stderr.WriteString(fmt.Sprintf("plugin auto-update check failed due to %s\n", err))
}

runningPlg := manager.GetPlugin(plg.Config.Name)
Expand Down
1 change: 1 addition & 0 deletions pkg/style/style.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var (
ErrorStatusStyle = lipgloss.NewStyle().Background(lipgloss.Color("#aa2222")).Foreground(lipgloss.Color("#ffffff"))

HighlightStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#d6e6f4")).Background(lipgloss.Color("#3a5369"))
SortedStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#dd5200"))

InfoStatusStyle = lipgloss.NewStyle().Background(lipgloss.Color("#3a3835")).Foreground(lipgloss.Color("#ffffff"))
InfoStatusStyle2 = lipgloss.NewStyle().Background(lipgloss.Color("#006d69")).Foreground(lipgloss.Color("#ffffff"))
Expand Down
2 changes: 1 addition & 1 deletion view/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (m *App) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
m.pages[currentPageIdx] = model.(Page)

return m, tea.Batch(cmd, TickCmdWithDuration(100*time.Microsecond))
return m, tea.Batch(cmd, TickCmdWithDuration(200*time.Microsecond))
}

func (m *App) View() string {
Expand Down
7 changes: 1 addition & 6 deletions view/page_overview.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,13 @@ func (m OverviewPage) OnClose() Page {
func (m OverviewPage) OnOpen() Page {
m.helpController.SetKeyMap([]string{
"↑/↓: move",
"pgdown/pgup/shift+↑/↓: next/prev page",
"home/end/shift+h/shift+e: first/last page",
"←/→: scroll in the table",
"enter: see resource details",
"p: change preferences",
"P: change preferences for all resources",
"r: load all items in current page",
"shift+r: load all items",
"/: filter results",
"s: sort by next column",
"shift+r: load all items in all pages",
"ctrl+j: list of jobs",
"s: change sort",
"q/ctrl+c: exit",
})
return m
Expand Down
34 changes: 20 additions & 14 deletions view/page_overview_plugin_custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type PluginCustomOverviewPage struct {
chartDefinitionDirty bool

responsive.ResponsiveView
filterPlaceHolder string
}

func NewPluginCustomOverviewPageView(
Expand Down Expand Up @@ -91,18 +92,13 @@ func (m *PluginCustomOverviewPage) OnClose() Page {
func (m *PluginCustomOverviewPage) OnOpen() Page {
m.helpController.SetKeyMap([]string{
"↑/↓: move",
"pgdown/pgup/shift+↑/↓: next/prev page",
"home/end/shift+h/shift+e: first/last page",
"←/→: scroll in the table",
"enter: see resource details",
"p: change preferences",
"P: change preferences for all resources",
"r: load all items in current page",
"shift+r: load all items",
"/: filter results",
"s: sort by next column",
"shift+r: load all items in all pages",
"ctrl+j: list of jobs",
"s: change sort",
"q/ctrl+c: exit",
})
return m
Expand All @@ -114,8 +110,14 @@ func (m *PluginCustomOverviewPage) Init() tea.Cmd {

func (m *PluginCustomOverviewPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
dontSendUpdateToTable := false
m.table = m.table.WithStaticFooter(
fmt.Sprintf("%d/%d ", m.table.CurrentPage(), m.table.MaxPages()) +
style.HelpStyle.Render("- pgdown | pgup | shift+↑/↓ | home | end | shift+h/e"),
)

if m.focusOnFilter {
m.filterPlaceHolder = style.HelpStyle.Render("Press enter to apply")

var filterCmd tea.Cmd
m.filterInput, filterCmd = m.filterInput.Update(msg)
switch msg := msg.(type) {
Expand All @@ -131,6 +133,7 @@ func (m *PluginCustomOverviewPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.table = m.table.WithFilterInputValue(m.filterInput.Value())
return m, filterCmd
}
m.filterPlaceHolder = style.HelpStyle.Render("Press / to filter")

var rows RowsWithId

Expand All @@ -140,20 +143,21 @@ func (m *PluginCustomOverviewPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
name := column.GetName()
if idx == m.sortColumnIdx {
if m.sortDesc {
name = name + " ↓"
name = style.SortedStyle.Render(name + " ↓")
} else {
name = name + " ↑"
name = style.SortedStyle.Render(name + " ↑")
}
}
width := len(name)
width := len(style.StyleSelector.ReplaceAllString(name, ""))
for _, row := range m.rows {
cell := row.Data[column.GetId()]
cellContent := ""
if cell != nil {
cellContent = strings.TrimSpace(style.StyleSelector.ReplaceAllString(cell.(string), ""))
}
if len(cellContent) > width {
width = len(cellContent)
cellLength := len(style.StyleSelector.ReplaceAllString(cellContent, ""))
if cellLength > width {
width = cellLength
}
}
columns = append(columns, table.NewColumn(column.GetId(), name, width).WithFiltered(true))
Expand Down Expand Up @@ -218,8 +222,9 @@ func (m *PluginCustomOverviewPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
rowData := table.RowData{}
for idx, c := range row.Cells {
rowData[fmt.Sprintf("%d", idx)] = c
if len(c) > columns[idx].Width() {
columns[idx] = table.NewColumn(fmt.Sprintf("%d", idx), columns[idx].Title(), len(c))
rowLength := len(style.StyleSelector.ReplaceAllString(c, ""))
if rowLength > columns[idx].Width() {
columns[idx] = table.NewColumn(fmt.Sprintf("%d", idx), columns[idx].Title(), rowLength)
}
}
rows = append(rows, table.NewRow(rowData))
Expand Down Expand Up @@ -375,10 +380,11 @@ func (m *PluginCustomOverviewPage) View() string {
summaryView = m.summaryTable.View()
}

return fmt.Sprintf("%s\n%s\nFilter: %s\n%s",
return fmt.Sprintf("%s\n%s\n Filter: %s%s\n%s",
summaryView,
m.table.View(),
m.filterInput.View(),
m.filterPlaceHolder,
m.statusBar.View(),
)
}
Expand Down
30 changes: 21 additions & 9 deletions view/view_statusbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package view

import (
"fmt"
"github.com/charmbracelet/bubbles/spinner"
tea "github.com/charmbracelet/bubbletea"
"github.com/kaytu-io/kaytu/controller"
"github.com/kaytu-io/kaytu/pkg/style"
Expand All @@ -14,13 +15,17 @@ type StatusBarView struct {
initialization bool
content string
width int
spinner spinner.Model
}

func NewStatusBarView(JobsController *controller.Jobs, helpController *controller.Help) StatusBarView {
return StatusBarView{jobsController: JobsController, helpController: helpController}
return StatusBarView{jobsController: JobsController, helpController: helpController,
spinner: spinner.New(spinner.WithSpinner(spinner.MiniDot))}
}

func (v StatusBarView) Init() tea.Cmd { return nil }
func (v StatusBarView) Init() tea.Cmd {
return nil
}
func (v StatusBarView) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.WindowSizeMsg:
Expand All @@ -35,14 +40,13 @@ func (v StatusBarView) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var helpLines []string
w := 0

if v.initialization {
line := " initializing "
if runningCount > 0 {

line := " " + v.spinner.View() + fmt.Sprintf(" running %d jobs, press ctrl+j to see list of jobs ", runningCount)
w += len(line)
helpLines = append(helpLines, style.JobsStatusStyle.Render(line))
}

if runningCount > 0 {
line := fmt.Sprintf(" running jobs: %d ", runningCount)
} else if v.initialization {
line := " " + v.spinner.View() + " initializing "
w += len(line)
helpLines = append(helpLines, style.JobsStatusStyle.Render(line))
}
Expand Down Expand Up @@ -70,7 +74,15 @@ func (v StatusBarView) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
status = append(status, style.ErrorStatusStyle.Render(fmt.Sprintf("failed job: %s, press ctrl+j to see more", failedJobs[0]))+"\n")
}
v.content = strings.Join(status, "")
return v, nil

var spinnerCmd tea.Cmd
if _, ok := msg.(tickMsg); ok {
v.spinner, spinnerCmd = v.spinner.Update(v.spinner.Tick())
} else {
v.spinner, spinnerCmd = v.spinner.Update(msg)
}

return v, tea.Batch(spinnerCmd)
}
func (v StatusBarView) View() string {
return v.content
Expand Down

0 comments on commit f7b4e87

Please sign in to comment.