├── pkg ├── util │ └── utils.go ├── image │ └── image.go └── container │ └── container.go ├── .github └── dependabot.yml ├── LICENSE ├── go.mod ├── README.md ├── go.sum └── cmd └── main.go /pkg/util/utils.go: -------------------------------------------------------------------------------- 1 | package utils 2 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "gomod" 4 | directory: "/" 5 | schedule: 6 | interval: "weekly" 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 Lucas Bleme 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module lazycontainer 2 | 3 | go 1.24.4 4 | 5 | require github.com/charmbracelet/bubbles v0.21.0 6 | 7 | require ( 8 | github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect 9 | github.com/charmbracelet/bubbletea v1.3.4 // indirect 10 | github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect 11 | github.com/charmbracelet/lipgloss v1.1.0 // indirect 12 | github.com/charmbracelet/x/ansi v0.8.0 // indirect 13 | github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirect 14 | github.com/charmbracelet/x/term v0.2.1 // indirect 15 | github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect 16 | github.com/lucasb-eyer/go-colorful v1.2.0 // indirect 17 | github.com/mattn/go-isatty v0.0.20 // indirect 18 | github.com/mattn/go-localereader v0.0.1 // indirect 19 | github.com/mattn/go-runewidth v0.0.16 // indirect 20 | github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect 21 | github.com/muesli/cancelreader v0.2.2 // indirect 22 | github.com/muesli/termenv v0.16.0 // indirect 23 | github.com/rivo/uniseg v0.4.7 // indirect 24 | github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect 25 | golang.org/x/sync v0.11.0 // indirect 26 | golang.org/x/sys v0.30.0 // indirect 27 | golang.org/x/text v0.3.8 // indirect 28 | ) 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # lazycontainer 2 | 3 | A terminal UI to manage Apple Containers without stress. Written in Go with [Bubbletea](https://github.com/charmbracelet/bubbletea) 🧋 4 | 5 | ![lazycontainerdemo](https://github.com/user-attachments/assets/71220800-46e3-4932-a0c0-9e4fe55ff99b) 6 | 7 | ## Requirements 8 | 9 | - [Apple containers](https://github.com/apple/container) CLI **0.1.0** 10 | 11 | ```sh 12 | $ brew install container 13 | ``` 14 | 15 | ## Install 16 | 17 | ### Homebrew 18 | 19 | ```sh 20 | $ brew install lazycontainer 21 | ``` 22 | 23 | ## Usage 24 | 25 | Start the terminal UI: 26 | 27 | ``` 28 | $ lazycontainer 29 | ``` 30 | 31 | Press `key-up` ⬆️ / `key-down` ⬇️ to navigate across containers. 32 | 33 | Press `tab` to switch between containers and images. 34 | 35 | Press `enter` to select a resource (container or image) and see its details. 36 | 37 | Press `q` or `ctrl+c` to exit 38 | 39 | ## Features 40 | 41 | This is an alpha release, so you may find bugs and missing features. Currently, these are the supported features: 42 | 43 | - viewing the state of containers 44 | - inspecting the details of a container 45 | - vieweing the state of images 46 | - inspecting the details of an image 47 | 48 | ## Running 49 | 50 | 1. **Clone the repository:** 51 | 52 | ```bash 53 | git clone https://github.com/andreybleme/lazycontainer 54 | cd lazycontainer 55 | ``` 56 | 57 | 2. **Install dependencies:** 58 | 59 | Run the following command to install the necessary dependencies: 60 | 61 | ```bash 62 | go mod tidy 63 | ``` 64 | 65 | 3. **Run the application:** 66 | 67 | You can run the application using the following command: 68 | 69 | ```bash 70 | go run cmd/main.go 71 | ``` 72 | 73 | ## Contributing 74 | 75 | Contributions are welcome! Feel free to submit a pull request or open an issue for any suggestions or improvements. 76 | 77 | ## License 78 | 79 | This project is licensed under the MIT License. See the LICENSE file for more details. 80 | -------------------------------------------------------------------------------- /pkg/image/image.go: -------------------------------------------------------------------------------- 1 | package image 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "os/exec" 7 | "strings" 8 | ) 9 | 10 | type Image struct { 11 | Name string 12 | Tag string 13 | Digest string 14 | } 15 | 16 | type ImageDetails struct { 17 | Name string 18 | Id string 19 | Size int64 20 | Created string 21 | } 22 | 23 | type imageInspectRaw struct { 24 | Name string `json:"name"` 25 | Index struct { 26 | Digest string `json:"digest"` 27 | Size int64 `json:"size"` 28 | } `json:"index"` 29 | Variants []struct { 30 | Config struct { 31 | Created string `json:"created"` 32 | } `json:"config"` 33 | } `json:"variants"` 34 | } 35 | 36 | func ListAll() ([]Image, error) { 37 | var images []Image 38 | 39 | output, err := exec.Command("container", "images", "list").Output() 40 | if err != nil { 41 | return nil, err 42 | } 43 | 44 | // NAME, TAG, DIGEST 45 | lines := strings.Split(strings.TrimSpace(string(output)), "\n") 46 | for _, line := range lines[1:] { 47 | fields := strings.Fields(line) 48 | // skip malformed lines 49 | if len(fields) < 3 { 50 | continue 51 | } 52 | 53 | image := Image{ 54 | Name: fields[0], 55 | Tag: fields[1], 56 | Digest: fields[2], 57 | } 58 | 59 | images = append(images, image) 60 | } 61 | 62 | return images, nil 63 | } 64 | 65 | func GetDetails(name string) (ImageDetails, error) { 66 | rawJSON, err := inspect(name) 67 | if err != nil { 68 | return ImageDetails{}, err 69 | } 70 | 71 | var entries []imageInspectRaw 72 | if err := json.Unmarshal([]byte(rawJSON), &entries); err != nil { 73 | return ImageDetails{}, fmt.Errorf("failed to parse image JSON: %w", err) 74 | } 75 | if len(entries) == 0 { 76 | return ImageDetails{}, fmt.Errorf("no image entries found in inspect output") 77 | } 78 | 79 | e := entries[0] 80 | created := "" 81 | if len(e.Variants) > 0 { 82 | created = e.Variants[0].Config.Created 83 | } 84 | 85 | imageDetails := ImageDetails{ 86 | Name: e.Name, 87 | Id: e.Index.Digest, 88 | Size: e.Index.Size, 89 | Created: created, 90 | } 91 | return imageDetails, nil 92 | } 93 | 94 | func inspect(name string) (string, error) { 95 | output, err := exec.Command("container", "images", "inspect", name).Output() 96 | if err != nil { 97 | return "Error inspecting image", err 98 | } 99 | 100 | return string(output), nil 101 | } 102 | -------------------------------------------------------------------------------- /pkg/container/container.go: -------------------------------------------------------------------------------- 1 | package container 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "os/exec" 7 | "strings" 8 | ) 9 | 10 | type Container struct { 11 | ID string 12 | Name string 13 | State string 14 | Image string 15 | } 16 | 17 | type ContainerDetails struct { 18 | ID string 19 | Image string 20 | CPU int64 21 | Memory int64 22 | Networks []string 23 | Environment []string 24 | } 25 | 26 | type NetworkInfo struct { 27 | Address string `json:"address"` 28 | Network string `json:"network"` 29 | Hostname string `json:"hostname"` 30 | Gateway string `json:"gateway"` 31 | } 32 | 33 | type NetworksField []string 34 | type containerInspectRaw struct { 35 | Configuration struct { 36 | ID string `json:"id"` 37 | Image struct { 38 | Descriptor struct { 39 | Digest string `json:"digest"` 40 | } `json:"descriptor"` 41 | Reference string `json:"reference"` 42 | } `json:"image"` 43 | Resources struct { 44 | CPUs int64 `json:"cpus"` 45 | MemoryInBytes int64 `json:"memoryInBytes"` 46 | } `json:"resources"` 47 | InitProcess struct { 48 | Environment []string `json:"environment"` 49 | } `json:"initProcess"` 50 | Networks NetworksField `json:"networks"` 51 | } `json:"configuration"` 52 | Networks NetworksField `json:"networks"` 53 | } 54 | 55 | func ListAll() ([]Container, error) { 56 | var containers []Container 57 | 58 | output, err := exec.Command("container", "list", "--all").Output() 59 | if err != nil { 60 | return nil, err 61 | } 62 | 63 | lines := strings.Split(strings.TrimSpace(string(output)), "\n") 64 | for _, line := range lines[1:] { 65 | fields := strings.Fields(line) 66 | // skip malformed lines 67 | if len(fields) < 4 { 68 | continue 69 | } 70 | 71 | // ID, IMAGE, OS, ARCH, STATE, ADDR 72 | container := Container{ 73 | ID: fields[0], 74 | Name: "", 75 | State: fields[4], 76 | Image: fields[1], 77 | } 78 | containers = append(containers, container) 79 | } 80 | 81 | return containers, nil 82 | } 83 | 84 | func GetDetails(id string) (ContainerDetails, error) { 85 | rawJSON, err := inspect(id) 86 | if err != nil { 87 | return ContainerDetails{}, err 88 | } 89 | 90 | var entries []containerInspectRaw 91 | if err := json.Unmarshal([]byte(rawJSON), &entries); err != nil { 92 | return ContainerDetails{}, fmt.Errorf("failed to parse container JSON: %w", err) 93 | } 94 | if len(entries) == 0 { 95 | return ContainerDetails{}, fmt.Errorf("no container entries found in inspect output") 96 | } 97 | 98 | e := entries[0] 99 | 100 | // show base configuration.networks if not set in base struct 101 | networks := e.Networks 102 | if len(e.Networks) == 0 { 103 | networks = e.Configuration.Networks 104 | } 105 | 106 | containerDetails := ContainerDetails{ 107 | ID: e.Configuration.ID, 108 | Image: e.Configuration.Image.Reference, 109 | CPU: e.Configuration.Resources.CPUs, 110 | Memory: e.Configuration.Resources.MemoryInBytes, 111 | Networks: networks, 112 | Environment: e.Configuration.InitProcess.Environment, 113 | } 114 | return containerDetails, nil 115 | } 116 | 117 | func GetLogs(id string) (string, error) { 118 | output, err := exec.Command("container", "logs", id).Output() 119 | if err != nil { 120 | return "Error reading container logs", err 121 | } 122 | 123 | return string(output), nil 124 | } 125 | 126 | func inspect(id string) (string, error) { 127 | output, err := exec.Command("container", "inspect", id).Output() 128 | if err != nil { 129 | return "Error inspecting container", err 130 | } 131 | 132 | return string(output), nil 133 | } 134 | 135 | func (nf *NetworksField) UnmarshalJSON(data []byte) error { 136 | var strArr []string 137 | if err := json.Unmarshal(data, &strArr); err == nil { 138 | *nf = strArr 139 | return nil 140 | } 141 | 142 | var objArr []NetworkInfo 143 | if err := json.Unmarshal(data, &objArr); err == nil { 144 | var result []string 145 | for _, n := range objArr { 146 | result = append(result, n.Address) 147 | } 148 | *nf = result 149 | return nil 150 | } 151 | 152 | return fmt.Errorf("networks field is neither []string nor []NetworkInfo") 153 | } 154 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= 2 | github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= 3 | github.com/charmbracelet/bubbles v0.21.0 h1:9TdC97SdRVg/1aaXNVWfFH3nnLAwOXr8Fn6u6mfQdFs= 4 | github.com/charmbracelet/bubbles v0.21.0/go.mod h1:HF+v6QUR4HkEpz62dx7ym2xc71/KBHg+zKwJtMw+qtg= 5 | github.com/charmbracelet/bubbletea v1.3.4 h1:kCg7B+jSCFPLYRA52SDZjr51kG/fMUEoPoZrkaDHyoI= 6 | github.com/charmbracelet/bubbletea v1.3.4/go.mod h1:dtcUCyCGEX3g9tosuYiut3MXgY/Jsv9nKVdibKKRRXo= 7 | github.com/charmbracelet/bubbletea v1.3.5 h1:JAMNLTbqMOhSwoELIr0qyP4VidFq72/6E9j7HHmRKQc= 8 | github.com/charmbracelet/bubbletea v1.3.5/go.mod h1:TkCnmH+aBd4LrXhXcqrKiYwRs7qyQx5rBgH5fVY3v54= 9 | github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc h1:4pZI35227imm7yK2bGPcfpFEmuY1gc2YSTShr4iJBfs= 10 | github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc/go.mod h1:X4/0JoqgTIPSFcRA/P6INZzIuyqdFY5rm8tb41s9okk= 11 | github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY= 12 | github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30= 13 | github.com/charmbracelet/x/ansi v0.8.0 h1:9GTq3xq9caJW8ZrBTe0LIe2fvfLR/bYXKTx2llXn7xE= 14 | github.com/charmbracelet/x/ansi v0.8.0/go.mod h1:wdYl/ONOLHLIVmQaxbIYEC/cRKOQyjTkowiI4blgS9Q= 15 | github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd h1:vy0GVL4jeHEwG5YOXDmi86oYw2yuYUGqz6a8sLwg0X8= 16 | github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs= 17 | github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ= 18 | github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg= 19 | github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4= 20 | github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM= 21 | github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= 22 | github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= 23 | github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= 24 | github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= 25 | github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4= 26 | github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88= 27 | github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc= 28 | github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= 29 | github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI= 30 | github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo= 31 | github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA= 32 | github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo= 33 | github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc= 34 | github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk= 35 | github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= 36 | github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= 37 | github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= 38 | github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no= 39 | github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM= 40 | golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w= 41 | golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= 42 | golang.org/x/sync v0.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610= 43 | golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= 44 | golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 45 | golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 46 | golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= 47 | golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 48 | golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20= 49 | golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= 50 | golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY= 51 | golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= 52 | -------------------------------------------------------------------------------- /cmd/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "time" 7 | 8 | "github.com/charmbracelet/bubbles/table" 9 | tea "github.com/charmbracelet/bubbletea" 10 | "github.com/charmbracelet/lipgloss" 11 | 12 | container "lazycontainer/pkg/container" 13 | image "lazycontainer/pkg/image" 14 | ) 15 | 16 | var baseStyle = lipgloss.NewStyle(). 17 | BorderStyle(lipgloss.NormalBorder()). 18 | BorderForeground(lipgloss.Color("240")) 19 | 20 | type model struct { 21 | containersTable table.Model 22 | containers []container.Container 23 | imageTable table.Model 24 | images []image.Image 25 | infoBox string 26 | } 27 | 28 | func (m model) Init() tea.Cmd { 29 | return nil 30 | } 31 | 32 | func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { 33 | var cmd tea.Cmd 34 | 35 | switch msg := msg.(type) { 36 | case tea.KeyMsg: 37 | switch msg.String() { 38 | case "tab": 39 | if m.containersTable.Focused() { 40 | m.containersTable.Blur() 41 | m.imageTable.Focus() 42 | } else if m.imageTable.Focused() { 43 | m.imageTable.Blur() 44 | m.containersTable.Focus() 45 | } 46 | case "q", "ctrl+c": 47 | return m, tea.Quit 48 | case "enter": 49 | // containers table actions 50 | if m.containersTable.Focused() { 51 | index := m.containersTable.Cursor() 52 | containerSelected := m.containers[index] 53 | containerDetails, err := container.GetDetails(containerSelected.ID) 54 | if err != nil { 55 | m.infoBox = fmt.Sprintf("Error inspecting container %s: %v", containerSelected.ID, err) 56 | } else { 57 | m.infoBox = fmt.Sprintf("ID: %s \nImage: %s \nCPU: %d \nMemory: %d \nNetworks: %s \nEnvironment: %s", containerDetails.ID, containerDetails.Image, containerDetails.CPU, containerDetails.Memory, 58 | lipgloss.JoinVertical(lipgloss.Left, containerDetails.Networks...), 59 | lipgloss.JoinVertical(lipgloss.Left, containerDetails.Environment...), 60 | ) 61 | } 62 | } 63 | 64 | // images table actions 65 | if m.imageTable.Focused() { 66 | imageDetails, err := image.GetDetails(m.imageTable.SelectedRow()[0]) 67 | if err != nil { 68 | m.infoBox = fmt.Sprintf("Error inspecting image %s: %v", m.imageTable.SelectedRow()[0], err) 69 | } else { 70 | createdDataTime, _ := time.Parse(time.RFC3339, imageDetails.Created) 71 | // adjust to readable local date time (2025-05-29T16:02:07Z) 72 | localTime := createdDataTime.Local() 73 | formattedDateTime := localTime.Format("Mon, 02 Jan 2006 15:04:05 -07") 74 | // convert bytes to megabytes 75 | sizeMB := float64(imageDetails.Size) / (1024 * 1024) 76 | m.infoBox = fmt.Sprintf("Name: %s \nID: %s \nSize: %.2fMB \nCreated: %s", imageDetails.Name, imageDetails.Id, sizeMB, formattedDateTime) 77 | } 78 | } 79 | } 80 | } 81 | 82 | if m.containersTable.Focused() { 83 | m.containersTable, cmd = m.containersTable.Update(msg) 84 | } else if m.imageTable.Focused() { 85 | m.imageTable, cmd = m.imageTable.Update(msg) 86 | } 87 | return m, cmd 88 | } 89 | 90 | func (m model) View() string { 91 | tables := lipgloss.JoinVertical(lipgloss.Left, 92 | baseStyle.Render(m.containersTable.View()), 93 | baseStyle.Render(m.imageTable.View()), 94 | ) 95 | 96 | infoBoxStyle := lipgloss.NewStyle(). 97 | BorderStyle(lipgloss.NormalBorder()). 98 | BorderForeground(lipgloss.Color("240")). 99 | Width(60). 100 | Height(14). 101 | Padding(1, 2) 102 | 103 | return lipgloss.JoinHorizontal(lipgloss.Top, 104 | tables, 105 | infoBoxStyle.Render(m.infoBox), 106 | ) 107 | } 108 | 109 | func main() { 110 | // containers table 111 | containers, err := container.ListAll() 112 | if err != nil { 113 | fmt.Println("Error listing containers:", err) 114 | } 115 | 116 | containerRows := []table.Row{} 117 | for _, c := range containers { 118 | containerRows = append(containerRows, table.Row{c.State, c.Image}) 119 | } 120 | 121 | containerColumns := []table.Column{ 122 | {Title: "Containers", Width: 10}, 123 | {Title: "", Width: 25}, 124 | } 125 | 126 | containersTable := table.New( 127 | table.WithColumns(containerColumns), 128 | table.WithRows(containerRows), 129 | table.WithFocused(true), 130 | table.WithHeight(5), 131 | ) 132 | 133 | styleContainers := table.DefaultStyles() 134 | styleContainers.Header = styleContainers.Header. 135 | BorderStyle(lipgloss.NormalBorder()). 136 | BorderForeground(lipgloss.Color("240")). 137 | BorderBottom(true). 138 | Bold(true) 139 | styleContainers.Selected = styleContainers.Selected. 140 | Foreground(lipgloss.Color("229")). 141 | Background(lipgloss.Color("57")). 142 | Bold(false) 143 | containersTable.SetStyles(styleContainers) 144 | 145 | // Images table 146 | images, err := image.ListAll() 147 | if err != nil { 148 | fmt.Println("Error listing images:", err) 149 | } 150 | 151 | imageRows := []table.Row{} 152 | for _, image := range images { 153 | imageRows = append(imageRows, table.Row{image.Name, image.Tag}) 154 | } 155 | 156 | imageColumns := []table.Column{ 157 | {Title: "Images", Width: 10}, 158 | {Title: "", Width: 25}, 159 | } 160 | 161 | imageTable := table.New( 162 | table.WithColumns(imageColumns), 163 | table.WithRows(imageRows), 164 | table.WithFocused(false), 165 | table.WithHeight(5), 166 | ) 167 | 168 | styleImages := table.DefaultStyles() 169 | styleImages.Header = styleImages.Header. 170 | BorderStyle(lipgloss.NormalBorder()). 171 | BorderForeground(lipgloss.Color("240")). 172 | BorderBottom(true). 173 | Bold(true) 174 | styleImages.Selected = styleImages.Selected. 175 | Foreground(lipgloss.Color("229")). 176 | Background(lipgloss.Color("201")). 177 | Bold(false) 178 | imageTable.SetStyles(styleImages) 179 | 180 | m := model{containersTable, containers, imageTable, images, ""} 181 | if _, err := tea.NewProgram(m).Run(); err != nil { 182 | fmt.Println("Error running program:", err) 183 | os.Exit(1) 184 | } 185 | } 186 | --------------------------------------------------------------------------------