Initial patterm project
This commit is contained in:
73
internal/app/layout.go
Normal file
73
internal/app/layout.go
Normal file
@@ -0,0 +1,73 @@
|
||||
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
|
||||
l.mainCols = cols - sidebarCols
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
Reference in New Issue
Block a user