2015-05-23 22:41:16 +00:00
|
|
|
<?php
|
2022-02-17 02:25:59 +00:00
|
|
|
|
2015-05-23 22:41:16 +00:00
|
|
|
/**
|
|
|
|
* @author Jim Wigginton <terrafrost@php.net>
|
|
|
|
* @copyright 2014 Jim Wigginton
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
|
|
|
*/
|
|
|
|
|
2022-02-23 02:48:51 +00:00
|
|
|
namespace phpseclib3\Tests\Unit\File;
|
|
|
|
|
2019-11-07 05:41:40 +00:00
|
|
|
use phpseclib3\File\ANSI;
|
2022-02-23 02:48:51 +00:00
|
|
|
use phpseclib3\Tests\PhpseclibTestCase;
|
2015-05-23 22:41:16 +00:00
|
|
|
|
2022-02-23 02:48:51 +00:00
|
|
|
class ANSITest extends PhpseclibTestCase
|
2015-05-23 22:41:16 +00:00
|
|
|
{
|
|
|
|
public function testCase1()
|
|
|
|
{
|
|
|
|
$str = "\x1B[07m"; // turn reverse video on
|
2022-02-17 02:25:59 +00:00
|
|
|
$str .= "aaaaaaaaaaaaaaaaaa";
|
|
|
|
$str .= "\x1B[10D"; // move cursor left 10 lines
|
|
|
|
$str .= "\x1B[m"; // reset everything
|
|
|
|
$str .= "bbb";
|
2015-05-23 22:41:16 +00:00
|
|
|
|
2015-05-23 23:23:40 +00:00
|
|
|
$ansi = new ANSI();
|
2015-05-23 22:41:16 +00:00
|
|
|
$ansi->appendString($str);
|
|
|
|
|
|
|
|
$expected = '<pre width="80" style="color: white; background: black">';
|
2022-02-17 02:25:59 +00:00
|
|
|
$expected .= '<span style="color: black"><span style="background: white">aaaaaaaa</span></span>';
|
|
|
|
$expected .= 'bbb';
|
|
|
|
$expected .= '<span style="color: black"><span style="background: white">aaaaaaa</span></span>';
|
|
|
|
$expected .= '</pre>';
|
2015-05-23 22:41:16 +00:00
|
|
|
|
|
|
|
$this->assertSame($ansi->getScreen(), $expected);
|
|
|
|
}
|
2017-07-30 16:24:58 +00:00
|
|
|
|
|
|
|
public function testCaseJ()
|
|
|
|
{
|
|
|
|
$str = "\x1B[H"; // Move cursor to upper left corner
|
2022-02-17 02:25:59 +00:00
|
|
|
$str .= "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
|
|
|
|
$str .= "\x1B[H"; // Move cursor to upper left corner
|
|
|
|
$str .= "\x1B[J"; // Clear screen from cursor down
|
2017-07-30 16:24:58 +00:00
|
|
|
|
|
|
|
$ansi = new ANSI();
|
|
|
|
$ansi->appendString($str);
|
|
|
|
|
|
|
|
$expected = '<pre width="80" style="color: white; background: black">';
|
2022-02-17 02:25:59 +00:00
|
|
|
$expected .= '</pre>';
|
2017-07-30 16:24:58 +00:00
|
|
|
|
|
|
|
$this->assertSame($ansi->getScreen(), $expected);
|
|
|
|
}
|
2017-08-09 03:04:59 +00:00
|
|
|
|
2017-08-09 01:47:19 +00:00
|
|
|
public function testLineOverflow()
|
|
|
|
{
|
|
|
|
$str = '';
|
|
|
|
foreach (range('a', 'y') as $char) {
|
2022-02-17 02:25:59 +00:00
|
|
|
$str .= "$char\r\n";
|
2017-08-09 01:47:19 +00:00
|
|
|
}
|
2022-02-17 02:25:59 +00:00
|
|
|
$str .= str_repeat('z', 100);
|
2017-08-09 01:47:19 +00:00
|
|
|
|
2017-08-09 02:53:37 +00:00
|
|
|
$ansi = new ANSI();
|
2017-08-09 01:47:19 +00:00
|
|
|
$ansi->appendString($str);
|
|
|
|
|
|
|
|
$screen = $ansi->getScreen();
|
|
|
|
|
|
|
|
$lines = explode("\r\n", $screen);
|
2017-12-07 20:08:19 +00:00
|
|
|
$this->assertCount(24, $lines);
|
2017-08-09 01:47:19 +00:00
|
|
|
$this->assertSame(str_repeat('z', 80), $lines[22]);
|
|
|
|
}
|
2017-12-07 20:08:19 +00:00
|
|
|
}
|