* Return cached value (if set) or $COLUMNS environment variable (if * set and positive) or ioctl(1, TIOCGWINSZ).ws_col (if positive), * and default to 80 if all else fails. */
| 201 | * and default to 80 if all else fails. |
| 202 | */ |
| 203 | int term_columns(void) |
| 204 | { |
| 205 | static int term_columns_at_startup; |
| 206 | |
| 207 | char *col_string; |
| 208 | int n_cols; |
| 209 | |
| 210 | if (term_columns_at_startup) |
| 211 | return term_columns_at_startup; |
| 212 | |
| 213 | term_columns_at_startup = 80; |
| 214 | term_columns_guessed = 1; |
| 215 | |
| 216 | col_string = getenv("COLUMNS"); |
| 217 | if (col_string && (n_cols = atoi(col_string)) > 0) { |
| 218 | term_columns_at_startup = n_cols; |
| 219 | term_columns_guessed = 0; |
| 220 | } |
| 221 | #ifdef TIOCGWINSZ |
| 222 | else { |
| 223 | struct winsize ws; |
| 224 | if (!ioctl(1, TIOCGWINSZ, &ws) && ws.ws_col) { |
| 225 | term_columns_at_startup = ws.ws_col; |
| 226 | term_columns_guessed = 0; |
| 227 | } |
| 228 | } |
| 229 | #endif |
| 230 | |
| 231 | return term_columns_at_startup; |
| 232 | } |
| 233 | |
| 234 | /* |
| 235 | * Clear the entire line, leave cursor in first column. |
no outgoing calls
no test coverage detected