magellan/internal/cache/edit/table.go
David Allen a6c445b86f
Add support for storage command and crawler output
Partially addresses issue #3 by adding a simple `magellan list devices` command to list storage devices. To close the issue, this PR still requires including storage device information in the `crawler`'s output.

Reviewed-on: towk/magellan-ng#5
2025-06-29 16:36:44 -06:00

48 lines
1,014 B
Go

package cache
import (
"github.com/charmbracelet/bubbles/table"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)
var baseStyle = lipgloss.NewStyle().
BorderStyle(lipgloss.NormalBorder()).
BorderForeground(lipgloss.Color("240"))
type Model struct {
selected int
Table table.Model
}
func (m Model) Init() tea.Cmd { return nil }
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmd tea.Cmd
switch msg := msg.(type) {
case tea.WindowSizeMsg:
// m.Table = m.Table.Width(msg.Width)
// m.Table = m.Table.Height(msg.Height)
case tea.KeyMsg:
switch msg.String() {
case "esc":
if m.Table.Focused() {
m.Table.Blur()
} else {
m.Table.Focus()
}
case "q", "ctrl+c":
return m, tea.Quit
case "enter":
return m, tea.Batch(
tea.Printf("Selected host '%s'", m.Table.SelectedRow()[0]),
)
}
}
m.Table, cmd = m.Table.Update(msg)
return m, cmd
}
func (m Model) View() string {
return baseStyle.Render(m.Table.View()) + "\n"
}