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

Method fallbackDimensions

tty.go:240–268  ·  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

238// fallbackDimensions returns width and height, falling back to COLUMNS/LINES
239// environment variables or 80x24 defaults when dimensions are non-positive.
240func (p *Program) fallbackDimensions(width, height int) (int, int) {
241 if width <= 0 {
242 var cols string
243 if p != nil && p.environ != nil {
244 cols = p.environ.Getenv("COLUMNS")
245 } else {
246 cols = os.Getenv("COLUMNS")
247 }
248 if c, err := strconv.Atoi(cols); err == nil && c > 0 {
249 width = c
250 } else {
251 width = defaultWidth
252 }
253 }
254 if height <= 0 {
255 var lines string
256 if p != nil && p.environ != nil {
257 lines = p.environ.Getenv("LINES")
258 } else {
259 lines = os.Getenv("LINES")
260 }
261 if l, err := strconv.Atoi(lines); err == nil && l > 0 {
262 height = l
263 } else {
264 height = defaultHeight
265 }
266 }
267 return width, height
268}
269
270// checkResize detects the current size of the output and informs the program
271// 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