Skip to content

Terminal overflow and menu size #255

Open
@Renji-FR

Description

@Renji-FR

I encountered an issue when my menu is bigger than my terminal:

phpclishell.mp4

Is it possible to print the console line number only for the menu?

I know I use stty binary to retrieve my terminal size:

<?php
	namespace Core\Console;

    class Tools
    {
		/**
		 * @return false|array
		 */
		protected static function _getSize()
		{
			$sttyCommand = 'stty size';
			exec($sttyCommand, $outputs, $status);

			if($status === 0 && count($outputs) >= 1)
			{
				if(preg_match('#^(?<rows>[0-9]+) (?<columns>[0-9]+)$#i', $outputs[0], $matches)) {
					return $matches;
				}
			}

			return false;
		}

		/**
		 * @return false|int
		 */
		public static function getRows()
		{
			$consoleSize = static::_getSize();
			return ($consoleSize !== false) ? ($consoleSize['rows']) : (false);
		}

		/**
		 * @return false|int
		 */
		public static function getColumns()
		{
			$consoleSize = static::_getSize();
			return ($consoleSize !== false) ? ($consoleSize['columns']) : (false);
		}
    }

Thank you

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions