package domain import "strings" // Anchor specifies a position in a 3x3 grid. type Anchor uint8 const ( AnchorCenter Anchor = iota AnchorTopLeft AnchorTop AnchorTopRight AnchorLeft AnchorRight AnchorBottomLeft AnchorBottom AnchorBottomRight ) // Valid reports whether a is a defined anchor. func (a Anchor) Valid() bool { return a <= AnchorBottomRight } // String returns the canonical text representation of a. func (a Anchor) String() string { switch a { case AnchorCenter: return "center" case AnchorTopLeft: return "top-left" case AnchorTop: return "top" case AnchorTopRight: return "top-right" case AnchorLeft: return "left" case AnchorRight: return "right" case AnchorBottomLeft: return "bottom-left" case AnchorBottom: return "bottom" case AnchorBottomRight: return "bottom-right" default: return "unknown" } } // ParseAnchor parses a case-insensitive anchor name. func ParseAnchor(s string) (Anchor, bool) { switch strings.ToLower(strings.TrimSpace(s)) { case "center": return AnchorCenter, true case "top-left": return AnchorTopLeft, true case "top": return AnchorTop, true case "top-right": return AnchorTopRight, true case "left": return AnchorLeft, true case "right": return AnchorRight, true case "bottom-left": return AnchorBottomLeft, true case "bottom": return AnchorBottom, true case "bottom-right": return AnchorBottomRight, true default: return AnchorCenter, false } } // Size is a terminal dimension in columns and rows. type Size struct { Cols, Rows int } // Valid reports whether sz has strictly positive columns and rows. func (sz Size) Valid() bool { return sz.Cols > 0 && sz.Rows > 0 } // Geometry combines a terminal's required cell dimensions with optional pixel // dimensions reported by the controlling terminal. Zero pixel dimensions mean // the terminal did not report them; they must not be inferred from cells. type Geometry struct { Size PixelWidth, PixelHeight int } // Valid reports whether the cell dimensions can describe a terminal screen. func (g Geometry) Valid() bool { return g.Size.Valid() } // PixelsKnown reports whether both pixel dimensions are available. func (g Geometry) PixelsKnown() bool { return g.PixelWidth > 0 && g.PixelHeight > 0 } // NormalizePixels clears partial or negative pixel dimensions. Pixel geometry // is optional as a pair; retaining only one axis would give downstream PTYs and // terminal queries a geometry the controlling terminal never reported. func (g Geometry) NormalizePixels() Geometry { if !g.PixelsKnown() { g.PixelWidth = 0 g.PixelHeight = 0 } return g } // Rect is an axis-aligned rectangle in cell coordinates. type Rect struct { X, Y, Width, Height int } // SessionID uniquely identifies a session. type SessionID string // TabID identifies a tab by its session-local, user-facing ID. type TabID string // TabStableID identifies a tab independently of its mutable session position. type TabStableID string // PaneStableID identifies a pane independently of its layout-local PaneID. type PaneStableID string