Skip to content

Commit

Permalink
refactor option
Browse files Browse the repository at this point in the history
  • Loading branch information
ernesto27 committed Jul 2, 2023
1 parent beb2f1a commit 3fda2dd
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 68 deletions.
34 changes: 0 additions & 34 deletions models/container_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ package models

import (
"fmt"
"strings"
"time"

tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)

type ContainerOptions struct {
Expand All @@ -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:
Expand Down
34 changes: 0 additions & 34 deletions models/image_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ package models

import (
"fmt"
"strings"

tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)

type ImageOptions struct {
Expand All @@ -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:
Expand Down
39 changes: 39 additions & 0 deletions models/options.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package models

import (
"fmt"
"strings"

"github.com/charmbracelet/lipgloss"
)

type Options struct {
Cursor int
Choice string
Expand All @@ -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()
}

0 comments on commit 3fda2dd

Please sign in to comment.