mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 03:27:03 -07:00
refactor: updated cache editor implementation
This commit is contained in:
parent
3bae20832f
commit
e85fd21922
6 changed files with 78 additions and 28 deletions
48
internal/cache/edit/table.go
vendored
48
internal/cache/edit/table.go
vendored
|
|
@ -1,48 +0,0 @@
|
|||
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"
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue