fallbackDimensions returns width and height, falling back to COLUMNS/LINES environment variables or 80x24 defaults when dimensions are non-positive.
(width, height int)
| 125 | // fallbackDimensions returns width and height, falling back to COLUMNS/LINES |
| 126 | // environment variables or 80x24 defaults when dimensions are non-positive. |
| 127 | func (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. |