Documentation
¶
Index ¶
- Constants
- Variables
- func ContainerStateFor(containers []DockerContainer, serviceName string) string
- func FormatMemUsage(memUsage, memPerc string) string
- func PageLabel(page Page) string
- func PageShortcut(page Page) string
- func ServiceRunning(containers []DockerContainer, serviceName string) bool
- func SumContainerMemory(containers []DockerContainer) (int64, int)
- type BackupsFocus
- type CheckableServiceItem
- type ComposeFileItem
- type DockerContainer
- type GroupListItem
- type ListItem
- type Page
- type ServiceListItem
- type StateTier
- type ThemeItem
Constants ¶
const UngroupedGroup = "ungrouped"
UngroupedGroup is the reserved group name cais shows for every service that carries no profiles: key. It is spelled the way a Compose profile would be, and rendered verbatim like any other group name, so the groups list needs no special case for it.
Reserved on both counts: the name cannot be given to a real group (see groupnamemodal), and the group is read-only in the UI - there is no profile tag behind it, and its membership is derived rather than chosen. Every one of those decisions is a comparison against this constant, which is why there is no "synthetic" flag on the list item.
Variables ¶
var PageLabels = map[Page]string{ PageHome: "Groups", PageServices: "Services", PageComposeFiles: "Files", }
PageLabels maps page IDs to their display labels in the main menu. Page IDs are preserved for all state comparisons; only the label changes.
The values are plain strings: a label is text on a tab, not an identity.
var PageTitles = []Page{ PageHome, PageServices, PageComposeFiles, PageBackups, }
PageTitles is the ordered list of page IDs used for navigation state.
Functions ¶
func ContainerStateFor ¶ added in v0.7.0
func ContainerStateFor(containers []DockerContainer, serviceName string) string
ContainerStateFor returns the state of the container the UI should describe for serviceName, or "" when docker has not reported one.
It reads through ContainerForService, so it describes the same container the row's image, uptime and ports came from rather than a different one.
func FormatMemUsage ¶
FormatMemUsage formats memory usage as "Usage (Percent)", e.g., "21.71MiB / 31.02GiB" + "0.07%" -> "21.71MiB (0.07%)". If percent is empty, returns just the usage part (before "/").
It takes docker's raw strings, and is the one copy: the service list row and the details panel's runtime table both render through it, so the two never drift apart. Applying it twice is not idempotent - the second pass finds no "/" to split on and appends the percent again - so call it at render time and keep the raw values in the fields.
func PageShortcut ¶
PageShortcut returns the letter of a page's alt+<letter> chord: the first letter of its display label, lowercased.
The chord is an alias. The digits are the primary page scheme, rendered on the tabs themselves; the chord stays for the terminals that send Option as Alt. It is still derived from the label rather than listed in a table, because a hand-maintained table drifts. Two labels may now share a first letter - the digits are unambiguous, and the alias simply resolves to the first matching page.
func ServiceRunning ¶ added in v0.7.0
func ServiceRunning(containers []DockerContainer, serviceName string) bool
ServiceRunning reports whether serviceName has at least one running container.
func SumContainerMemory ¶
func SumContainerMemory(containers []DockerContainer) (int64, int)
SumContainerMemory adds the used side of every container's MemUsage. Returns the total used bytes and how many containers reported one.
Types ¶
type BackupsFocus ¶ added in v0.7.0
type BackupsFocus int
BackupsFocus names which half of the Backups page the arrows are driving.
It lives here rather than in either panel because four packages have to agree on it: AppModel owns the value and tab moves it, cmds carries it to the panels, keys reads it to decide whether the footer says "navigate" or "scroll", and the two panels route their own keys by it.
The Backups page is the only page with focus. Home and Services gave theirs up because their two panels are two views of one selection (see docs/DESIGN.md); here the panels are a cursor over metadata and a scrolling file, which are genuinely two things to drive.
const ( // BackupsList is the zero value because the page opens on the list: it is // the panel with the cursor, and the preview has nothing in it until the // cursor picks a row. BackupsList BackupsFocus = iota BackupsPreview )
func (BackupsFocus) Toggled ¶ added in v0.7.0
func (f BackupsFocus) Toggled() BackupsFocus
Toggled is the other half. With exactly two stops, tab and shift+tab are the same move, so both call this.
type CheckableServiceItem ¶
CheckableServiceItem is a list.Item for the service-selection checklist shown when creating a group.
func (CheckableServiceItem) FilterValue ¶
func (s CheckableServiceItem) FilterValue() string
func (CheckableServiceItem) Title ¶
func (s CheckableServiceItem) Title() string
type ComposeFileItem ¶
ComposeFileItem is a list.Item for the file picker on the Files page. Active marks the file currently loaded, so the picker can say which one the user is already looking at.
func (ComposeFileItem) FilterValue ¶
func (s ComposeFileItem) FilterValue() string
func (ComposeFileItem) Title ¶
func (s ComposeFileItem) Title() string
type DockerContainer ¶
type DockerContainer struct {
Command string
CreatedAt string
// docker compose ps names this field "Health". Without the tag, the
// field never binds and the HEALTH column reads "-" for every
// container, healthy ones included.
HealthStatus string `json:"Health"`
ID string
Image string
Labels string
LocalVolumes string
Mounts string
Names string
Networks string
Platforms struct {
// contains filtered or unexported fields
}
Ports string
RunningFor string
Service string
Size string
State string
Status string
// Runtime stats from `docker stats --no-stream`. These are populated
// by GetContainerStats, not by docker compose ps.
MemPerc string // e.g. "0.07%"
MemUsage string // e.g. "21.71MiB / 31.02GiB"
NetIO string // e.g. "3.22MB / 4.7kB"
BlockIO string // e.g. "70.3MB / 43.7MB"
CPUPerc string // e.g. "0.00%"
PIDs string // e.g. "19"
}
func ContainerForService ¶ added in v0.7.0
func ContainerForService(containers []DockerContainer, serviceName string) (DockerContainer, bool)
ContainerForService returns a container belonging to serviceName.
It prefers a running one, so a caller rendering a single row's image, uptime or ports describes the live container rather than a stale one that happens to come first in docker's output. Falls back to the first container found, since a stopped service still has details worth showing.
type GroupListItem ¶
GroupListItem is one row in the groups list. It carries the group's name plus how many of its member services are running, so the row can render a status dot (green when fully running, amber half-circle when mixed).
func (GroupListItem) FilterValue ¶
func (s GroupListItem) FilterValue() string
func (GroupListItem) Title ¶
func (s GroupListItem) Title() string
type ListItem ¶
type ListItem struct {
ItemTitle, ItemDesc string
}
func (ListItem) Description ¶
func (ListItem) FilterValue ¶
type Page ¶ added in v0.7.0
type Page string
Page is a page's identity - the value every screen-scoped switch matches on.
It is a defined type rather than a bare string because five packages switch on it (AppModel routes keys and panels by it, cmds carries it, keys picks the footer's bindings from it, keybindingbar mirrors it, mainmenu renders the tabs from it) and every one of those switches falls through silently on a value it does not know. As a string that made a typo a page that quietly does nothing; as a type it is a compile error, and the constants below are the only spellings that exist.
The underlying string is still the page's ID and is still what the display label falls back to, so an unlisted page renders as its own name rather than as blank.
func PageForShortcut ¶
PageForShortcut returns the page a chord letter jumps to, or "" if the letter is not a page chord. When two labels share a first letter the first page wins - acceptable for an alias, since the digits are the primary scheme and are unambiguous.
type ServiceListItem ¶
type ServiceListItem struct {
Service types.ServiceConfig
// Status is docker's own container state for this service - running,
// restarting, paused, created, removing, exited or dead - or "stopped"
// when the service has no container, or "" for unknown (docker has not
// answered yet). Set by ServicesListModel when a GetRunningContainersMsg
// arrives, and read through apptypes.ClassifyContainerState rather than
// compared directly.
Status string
// MemUsage is the real-time memory usage from docker stats, exactly as
// docker reports it: "21.71MiB / 31.02GiB". Empty when stats are
// unavailable. Store it raw - FormatMemUsage is applied once, at render
// time, and formatting it on the way in instead would double-apply the
// percent suffix.
MemUsage string
// MemPerc is the memory usage percentage from docker stats, e.g. "0.07%"
MemPerc string
}
func (ServiceListItem) Description ¶
func (s ServiceListItem) Description(isActive bool) string
func (ServiceListItem) FilterValue ¶
func (s ServiceListItem) FilterValue() string
func (ServiceListItem) Title ¶
func (s ServiceListItem) Title() string
type StateTier ¶ added in v0.7.0
type StateTier int
StateTier is what the UI actually distinguishes about a container's state.
Docker reports seven states - created, restarting, running, removing, paused, exited and dead - and the app used to fold all of them into "running" or "stopped". That was survivable while the only question was "is it up", but it meant a container docker had given up on (dead) and one the user had deliberately stopped (exited) rendered identically, and a service mid-restart looked stopped rather than busy.
The tiers exist so the colour choice is made once. What a tier *means* is the point; which colour draws it is chrome's business.
const ( // TierUnknown is "docker has not answered yet", not a state docker // reports. Rendering it as stopped is a guess dressed up as a fact - // see serviceslist.Model.containersKnown. TierUnknown StateTier = iota // TierRunning is the one state that means the service is up. TierRunning // TierTransitional is on its way somewhere under its own power: // restarting will likely be running shortly, paused is deliberately // frozen. Both want attention without claiming a fault. TierTransitional // TierInert exists but is not doing anything, and nobody needs to act: // created has never been started, removing is on its way out because // somebody asked for it. TierInert // TierStopped is the ordinary, expected stop - exited, or no container // at all. It is by far the most common non-running state, which is why // it does not get the fault colour. TierStopped // TierFault is dead: docker could not remove the container and cannot // act on it. This is the only tier that means something is wrong. TierFault )
func ClassifyContainerState ¶ added in v0.7.0
ClassifyContainerState maps one of docker's container states to its tier.
The match is case-insensitive: docker's JSON reports lowercase, but `docker inspect` and some API paths capitalise, and a state that fell through to the default would silently render as an ordinary stop.
An unrecognised state is TierStopped rather than TierFault: a state docker adds later is far more likely to be benign than broken, and claiming a fault on a string we do not know is the worse failure.
type ThemeItem ¶
ThemeItem is a list.Item for the theme picker modal. Active marks the theme that was in effect when the modal opened, so the user can see which one they started from and Esc can restore it.