package app // terminalLayout is the single source of truth for host chrome and the // child PTY viewport. type terminalLayout struct { hostCols uint16 hostRows uint16 mainLeft uint16 mainTop uint16 mainCols uint16 mainRows uint16 sidebarVisible bool sidebarLeft uint16 sidebarWidth uint16 statusRow uint16 } func newTerminalLayout(cols, rows uint16) terminalLayout { if cols == 0 { cols = 1 } if rows == 0 { rows = 1 } l := terminalLayout{ hostCols: cols, hostRows: rows, mainLeft: 1, mainTop: tabBarRows + 1, mainCols: cols, mainRows: 1, statusRow: rows, } if int(cols) > sidebarCols+10 { l.sidebarVisible = true l.sidebarWidth = sidebarCols l.sidebarLeft = cols - sidebarCols + 1 // The sidebar's left border lives one column to the left of // sidebarLeft. The viewport must stop one column short of that // border or child output (and clearViewport ECH) would erase // it whenever the cursor reached the right margin. l.mainCols = cols - sidebarCols - 1 } reservedRows := tabBarRows + statusRows if int(rows) > reservedRows { l.mainRows = rows - uint16(reservedRows) } return l } func (l terminalLayout) childCols() uint16 { if l.mainCols == 0 { return 1 } return l.mainCols } func (l terminalLayout) childRows() uint16 { if l.mainRows == 0 { return 1 } return l.mainRows } func ptyRows(hostRows uint16) uint16 { return newTerminalLayout(1, hostRows).childRows() } func ptyCols(hostCols uint16) uint16 { return newTerminalLayout(hostCols, 1).childCols() }