MCPcopy Create free account
hub / github.com/charmbracelet/bubbletea / fallbackDimensions

Method fallbackDimensions

tty.go:127–155  ·  view source on GitHub ↗

fallbackDimensions returns width and height, falling back to COLUMNS/LINES environment variables or 80x24 defaults when dimensions are non-positive.

(width, height int)

Source from the content-addressed store, hash-verified

125// fallbackDimensions returns width and height, falling back to COLUMNS/LINES
126// environment variables or 80x24 defaults when dimensions are non-positive.
127func (p *Program) fallbackDimensions(width, height int) (int, int) {
128 if width <= 0 {
129 var cols string
130 if p != nil && p.environ != nil {
131 cols = p.environ.Getenv("COLUMNS")
132 } else {
133 cols = os.Getenv("COLUMNS")
134 }
135 if c, err := strconv.Atoi(cols); err == nil && c > 0 {
136 width = c
137 } else {
138 width = defaultWidth
139 }
140 }
141 if height <= 0 {
142 var lines string
143 if p != nil && p.environ != nil {
144 lines = p.environ.Getenv("LINES")
145 } else {
146 lines = os.Getenv("LINES")
147 }
148 if l, err := strconv.Atoi(lines); err == nil && l > 0 {
149 height = l
150 } else {
151 height = defaultHeight
152 }
153 }
154 return width, height
155}
156
157// checkResize detects the current size of the output and informs the program
158// via a WindowSizeMsg.

Callers 3

checkResizeMethod · 0.95
RunMethod · 0.95
TestFallbackDimensionsFunction · 0.95

Calls 1

GetenvMethod · 0.80

Tested by 1

TestFallbackDimensionsFunction · 0.76