diff --git a/models/container_options.go b/models/container_options.go index 73ed57d..f86a806 100644 --- a/models/container_options.go +++ b/models/container_options.go @@ -2,11 +2,9 @@ package models import ( "fmt" - "strings" "time" tea "github.com/charmbracelet/bubbletea" - "github.com/charmbracelet/lipgloss" ) type ContainerOptions struct { @@ -27,38 +25,6 @@ func NewContainerOptions(container string, image string) ContainerOptions { } } -func (o ContainerOptions) View() string { - s := strings.Builder{} - - var style = lipgloss.NewStyle(). - Bold(true). - Foreground(lipgloss.Color("#FAFAFA")). - Background(lipgloss.Color("#3259A8")). - Padding(1). - MarginTop(1). - MarginBottom(1) - - s.WriteString("\n") - - for i := 0; i < len(o.Choices); i++ { - if o.Cursor == i { - s.WriteString("(•) ") - } else { - s.WriteString("( ) ") - } - s.WriteString(o.Choices[i]) - s.WriteString("\n") - } - s.WriteString("\n(press Esc to go back)\n") - - options := fmt.Sprintf("Options container: %s - %s", o.Container, o.Image) - if o.Container == "" { - options = fmt.Sprintf("Options image: %s", o.Image) - } - - return style.Render(options) + s.String() -} - func (o ContainerOptions) Update(msg tea.Msg, m *model) (ContainerOptions, tea.Cmd) { switch msg := msg.(type) { case tea.KeyMsg: diff --git a/models/image_options.go b/models/image_options.go index 7636c62..34a74d2 100644 --- a/models/image_options.go +++ b/models/image_options.go @@ -2,10 +2,8 @@ package models import ( "fmt" - "strings" tea "github.com/charmbracelet/bubbletea" - "github.com/charmbracelet/lipgloss" ) type ImageOptions struct { @@ -26,38 +24,6 @@ func NewImageOptions(container string, image string) ImageOptions { } } -func (o ImageOptions) View() string { - s := strings.Builder{} - - var style = lipgloss.NewStyle(). - Bold(true). - Foreground(lipgloss.Color("#FAFAFA")). - Background(lipgloss.Color("#3259A8")). - Padding(1). - MarginTop(1). - MarginBottom(1) - - s.WriteString("\n") - - for i := 0; i < len(o.Choices); i++ { - if o.Cursor == i { - s.WriteString("(•) ") - } else { - s.WriteString("( ) ") - } - s.WriteString(o.Choices[i]) - s.WriteString("\n") - } - s.WriteString("\n(press Esc to go back)\n") - - options := fmt.Sprintf("Options container: %s - %s", o.Container, o.Image) - if o.Container == "" { - options = fmt.Sprintf("Options image: %s", o.Image) - } - - return style.Render(options) + s.String() -} - func (o ImageOptions) Update(msg tea.Msg, m *model) (ImageOptions, tea.Cmd) { switch msg := msg.(type) { case tea.KeyMsg: diff --git a/models/options.go b/models/options.go index ea5b9a7..88a8e52 100644 --- a/models/options.go +++ b/models/options.go @@ -1,5 +1,12 @@ package models +import ( + "fmt" + "strings" + + "github.com/charmbracelet/lipgloss" +) + type Options struct { Cursor int Choice string @@ -14,3 +21,35 @@ const ( Remove = "Remove" Restart = "Restart" ) + +func (o Options) View() string { + s := strings.Builder{} + + var style = lipgloss.NewStyle(). + Bold(true). + Foreground(lipgloss.Color("#FAFAFA")). + Background(lipgloss.Color("#3259A8")). + Padding(1). + MarginTop(1). + MarginBottom(1) + + s.WriteString("\n") + + for i := 0; i < len(o.Choices); i++ { + if o.Cursor == i { + s.WriteString("(•) ") + } else { + s.WriteString("( ) ") + } + s.WriteString(o.Choices[i]) + s.WriteString("\n") + } + s.WriteString("\n(press Esc to go back)\n") + + options := fmt.Sprintf("Options container: %s - %s", o.Container, o.Image) + if o.Container == "" { + options = fmt.Sprintf("Options image: %s", o.Image) + } + + return style.Render(options) + s.String() +}