Handle terminal being resized
This commit is contained in:
		@@ -104,6 +104,11 @@ class Editor
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        while ($this->running) {
 | 
					        while ($this->running) {
 | 
				
			||||||
            [$w,$h] = $this->term->getSize();
 | 
					            [$w,$h] = $this->term->getSize();
 | 
				
			||||||
 | 
					            if ($this->term->resized) {
 | 
				
			||||||
 | 
					                $this->redrawEditor();
 | 
				
			||||||
 | 
					                $this->term->resized = false;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            usleep(10000);
 | 
				
			||||||
            $read = $this->term->readKey();
 | 
					            $read = $this->term->readKey();
 | 
				
			||||||
            switch ($read) {
 | 
					            switch ($read) {
 | 
				
			||||||
                case 'k{UP}':
 | 
					                case 'k{UP}':
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,6 +14,8 @@ class Terminal
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    private bool $active = false;
 | 
					    private bool $active = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public bool $resized = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function __construct()
 | 
					    public function __construct()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if (self::$init++ == 0) {
 | 
					        if (self::$init++ == 0) {
 | 
				
			||||||
@@ -43,7 +45,11 @@ class Terminal
 | 
				
			|||||||
        //ob_flush();
 | 
					        //ob_flush();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $this->measureTerminal();
 | 
					        $this->measureTerminal();
 | 
				
			||||||
        pcntl_signal(SIGWINCH, $this->measureTerminal(...));
 | 
					        pcntl_signal(SIGWINCH, function () {
 | 
				
			||||||
 | 
					            $this->resized = true;
 | 
				
			||||||
 | 
					            $this->measureTerminal();
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					        pcntl_async_signals(true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $this->active = true;
 | 
					        $this->active = true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user