Skip to content

Commit

Permalink
mv component/list.go -> list/list.go
Browse files Browse the repository at this point in the history
  • Loading branch information
joshi4 committed May 14, 2024
1 parent 0950eb9 commit 5c1f3bf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
28 changes: 14 additions & 14 deletions cmd/component/list.go → cmd/component/list/list.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package component
package list

import (
"strings"
Expand All @@ -12,32 +12,32 @@ import (

var docStyle = lipgloss.NewStyle().Margin(3, 3)

type ListItem struct {
type Item struct {
Command string
DescriptionText string
}

var _ list.DefaultItem = ListItem{}
var _ list.DefaultItem = Item{}

func (i ListItem) Title() string { return i.Command }
func (i ListItem) Description() string { return i.DescriptionText }
func (i ListItem) FilterValue() string {
func (i Item) Title() string { return i.Command }
func (i Item) Description() string { return i.DescriptionText }
func (i Item) FilterValue() string {
return strings.Join([]string{i.Command, i.DescriptionText}, " ")
}

type ListModel struct {
type Model struct {
list list.Model
url string
editBinding key.Binding
}

func NewListModelWithDelegate(items []ListItem, title string, url string, delegate list.ItemDelegate) ListModel {
func NewModelWithDelegate(items []Item, title string, url string, delegate list.ItemDelegate) Model {
var listItems []list.Item
for _, i := range items {
listItems = append(listItems, i)
}

m := ListModel{
m := Model{
list: list.New(listItems, delegate, 0, 0),
}
m.list.Title = title
Expand All @@ -56,11 +56,11 @@ func NewListModelWithDelegate(items []ListItem, title string, url string, delega
return m
}

func NewListModel(items []ListItem, title string, url string) ListModel {
return NewListModelWithDelegate(items, title, url, list.NewDefaultDelegate())
func NewModel(items []Item, title string, url string) Model {
return NewModelWithDelegate(items, title, url, list.NewDefaultDelegate())
}

func (m ListModel) Init() tea.Cmd {
func (m Model) Init() tea.Cmd {
return nil
}

Expand All @@ -86,7 +86,7 @@ func OpenBrowser(url string, onComplete tea.Msg, onErr tea.Msg) tea.Cmd {

type NopMsg struct{}

func (m ListModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
if msg.String() == "ctrl+c" {
Expand All @@ -109,6 +109,6 @@ func (m ListModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, cmd
}

func (m ListModel) View() string {
func (m Model) View() string {
return docStyle.Render(m.list.View())
}
13 changes: 7 additions & 6 deletions cmd/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/creack/pty"
"github.com/getsavvyinc/savvy-cli/client"
"github.com/getsavvyinc/savvy-cli/cmd/component"
"github.com/getsavvyinc/savvy-cli/cmd/component/list"
"github.com/getsavvyinc/savvy-cli/display"
"github.com/getsavvyinc/savvy-cli/shell"
"github.com/muesli/cancelreader"
Expand Down Expand Up @@ -183,13 +184,13 @@ func startRecording() ([]*server.RecordedCommand, error) {
}

type displayCommands struct {
l component.ListModel
l list.Model
}

func toListItems(steps []component.RunbookStep) []component.ListItem {
var items []component.ListItem
func toItems(steps []component.RunbookStep) []list.Item {
var items []list.Item
for _, step := range steps {
items = append(items, component.ListItem{
items = append(items, list.Item{
Command: step.Command,
DescriptionText: step.Description,
})
Expand All @@ -202,8 +203,8 @@ func newDisplayCommandsModel(runbook *component.Runbook) (*displayCommands, erro
return nil, errors.New("runbook is empty")
}

listItems := toListItems(runbook.Steps)
l := component.NewListModel(listItems, runbook.Title, runbook.URL)
listItems := toItems(runbook.Steps)
l := list.NewModel(listItems, runbook.Title, runbook.URL)
return &displayCommands{l: l}, nil
}

Expand Down

0 comments on commit 5c1f3bf

Please sign in to comment.