Skip to content

Commit

Permalink
test ls containers in TUI
Browse files Browse the repository at this point in the history
  • Loading branch information
somnek committed Apr 2, 2023
1 parent 27a1882 commit e1e8b3d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
6 changes: 2 additions & 4 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@ func removeContainer(c *docker.Client, id string) {
fmt.Println("Container removed")
}

func listContainers(c *docker.Client) {
func listContainers(c *docker.Client) []docker.APIContainers {
containers, err := c.ListContainers(docker.ListContainersOptions{All: false})
if err != nil {
log.Fatal(err)
}
for _, container := range containers {
fmt.Println("Name", container.ID)
}
return containers
}

func listImages(c *docker.Client) {
Expand Down
17 changes: 15 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package main

import (
"fmt"
"log"
"os"

tea "github.com/charmbracelet/bubbletea"
docker "github.com/fsouza/go-dockerclient"
)

type model struct {
Expand All @@ -14,8 +16,19 @@ type model struct {
}

func initialModel() model {
client, err := docker.NewClientFromEnv()
if err != nil {
log.Fatal(err)
}
choices := []string{}
for _, c := range listContainers(client) {
name := c.Names[0][1:]
choices = append(choices, name)
}

return model{
choices: []string{"🍎 Apple", "🍐 Pear", "🍊 Orange", "🍌 Banana", "πŸ‰ Watermelon", "πŸ‡ Grape", "πŸ“ Strawberry", "🍈 Melon", "πŸ’ Cherry", "πŸ‘ Peach"},
// choices: []string{"🍎 Apple", "🍐 Pear", "🍊 Orange", "🍌 Banana", "πŸ‰ Watermelon", "πŸ‡ Grape", "πŸ“ Strawberry", "🍈 Melon", "πŸ’ Cherry", "πŸ‘ Peach"},
choices: choices,
selected: make(map[int]struct{}),
}
}
Expand Down Expand Up @@ -58,7 +71,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
func (m model) View() string {
s := "What should we order for lunch?\n\n"
for i, choice := range m.choices {
cursor := " " // default cursor
cursor := " " // default cursor
if m.cursor == i {
cursor = "πŸ‘‰"
}
Expand Down

0 comments on commit e1e8b3d

Please sign in to comment.