Coding standards
Security in ResourceSpace
Developer reference
Database
User api session functions
Geolocation functions
Storage test functions
Cli functions
Lang translation functions

cli_terminal_size()

Description

Read the size of the output terminal.

Parameters

ColumnTypeDefaultDescription
array { :

Return

array{rows: int, columns: int} Terminal dimensions with defaults when unavailable.

Location

include/cli_functions.php lines 127 to 145

Definition

 
function cli_terminal_size(): array
{
    
$columns = (int) (getenv('COLUMNS') ?: 80);
    
$rows = (int) (getenv('LINES') ?: 24);
    if (
cli_is_interactive() && DIRECTORY_SEPARATOR === '/' && function_exists('proc_open')) {
        
// Read the output terminal's size without running a shell.
        
$process = proc_open(['stty', 'size'], [STDOUT, ['pipe', 'w'], ['pipe', 'w']], $pipes);
        if (
is_resource($process)) {
            
$size = stream_get_contents($pipes[1]);
            
fclose($pipes[1]);
            
fclose($pipes[2]);
            if (
proc_close($process) === 0 && preg_match('/^(\d+)\s+(\d+)$/', trim((string) $size), $match)) {
                
$rows = (int) $match[1] ?: $rows;
                
$columns = (int) $match[2] ?: $columns;
            }
        }
    }
    return [
'rows' => $rows, 'columns' => $columns];
}

This article was last updated 27th November 2026 18:35 Europe/London time based on the source file dated 27th November 2026 17:15 Europe/London time.