tree

package
v0.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package tree groups containers into projects and tracks the cursor and expand/collapse state of the project/container tree. It has no UI or Docker dependencies so it can be tested in isolation.

Index

Constants

View Source
const Standalone = "(standalone)"

Standalone is the synthetic project for containers without a compose project label. It always sorts last.

Variables

This section is empty.

Functions

This section is empty.

Types

type Container

type Container struct {
	ID      string
	Name    string
	Project string // compose project, "" for standalone containers
	Service string // compose service, "" for standalone containers
	Image   string
	State   string // running, exited, paused, restarting, created, dead, removing
	Status  string // human readable status from Docker, e.g. "Up 2 hours (healthy)"
	Ports   string

	WorkingDir  string   // compose project directory
	ConfigFiles []string // compose files, absolute paths
	Networks    []string
	Volumes     []string // named volumes
	HostPorts   []int    // published host ports
}

Container is the subset of container information the tree and UI need.

func (Container) DisplayName

func (c Container) DisplayName() string

DisplayName is the service name inside a compose project (the project is already shown on the parent row), otherwise the container name.

func (Container) Health

func (c Container) Health() Health

func (Container) HealthCheck

func (c Container) HealthCheck() string

HealthCheck is the healthcheck result reported in the status text: "healthy", "unhealthy", "starting", or "" when there is no healthcheck.

func (Container) Running

func (c Container) Running() bool

type Health

type Health int

Health is a coarse classification used for colouring.

const (
	Healthy Health = iota
	Degraded
	Failing
)

type Project

type Project struct {
	Name       string
	Containers []Container
}

Project is a named group of containers.

func Group

func Group(cs []Container) []Project

Group groups containers by compose project. Projects are sorted alphabetically with Standalone last; containers by display name.

func (Project) Health

func (p Project) Health() Health

Health is the worst health of the project's containers.

func (Project) Running

func (p Project) Running() int

type Row

type Row struct {
	Project   int
	Container int
}

Row is one visible line of the tree. Container is -1 for a project row.

func (Row) IsProject

func (r Row) IsProject() bool

type Tree

type Tree struct {
	// contains filtered or unexported fields
}

Tree is the navigable project/container tree.

func New

func New() *Tree

func (*Tree) Bottom

func (t *Tree) Bottom()

func (*Tree) Collapse

func (t *Tree) Collapse()

Collapse collapses the selected project, or moves to the parent project when a container is selected.

func (*Tree) Container

func (t *Tree) Container(r Row) *Container

func (*Tree) Cursor

func (t *Tree) Cursor() int

func (*Tree) Down

func (t *Tree) Down()

func (*Tree) Expand

func (t *Tree) Expand()

Expand expands the selected project. It is a no-op on container rows.

func (*Tree) Filter

func (t *Tree) Filter() string

func (*Tree) FirstContainer

func (t *Tree) FirstContainer()

FirstContainer moves the cursor to the first container row, if any.

func (*Tree) IsCollapsed

func (t *Tree) IsCollapsed(project string) bool

func (*Tree) Matching

func (t *Tree) Matching(r Row) int

Matching is the number of containers in the row's project that match the active filter.

func (*Tree) Project

func (t *Tree) Project(r Row) *Project

func (*Tree) Projects

func (t *Tree) Projects() []Project

func (*Tree) Rows

func (t *Tree) Rows() []Row

func (*Tree) Selected

func (t *Tree) Selected() (Row, bool)

Selected returns the row under the cursor.

func (*Tree) SelectedContainer

func (t *Tree) SelectedContainer() *Container

SelectedContainer returns the container under the cursor, or nil when the cursor is on a project row or the tree is empty.

func (*Tree) Set

func (t *Tree) Set(cs []Container)

Set replaces the containers while preserving the cursor and collapse state. If the selected container disappeared, the cursor moves to its neighbour in the same project, then to the project row, then to the nearest row.

func (*Tree) SetFilter

func (t *Tree) SetFilter(q string)

SetFilter shows only containers whose shown name, container name or project name contains q (case-insensitive). An empty q clears the filter.

func (*Tree) Toggle

func (t *Tree) Toggle()

Toggle flips the expand state of the selected project.

func (*Tree) Top

func (t *Tree) Top()

func (*Tree) Up

func (t *Tree) Up()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL