|
15 | 15 | use PhpTui\Tui\Text\Title;
|
16 | 16 | use PhpTui\Tui\Widget\Borders;
|
17 | 17 | use PhpTui\Tui\Widget\Direction;
|
| 18 | +use Swow\Coroutine; |
| 19 | +use Swow\Sync\WaitReference; |
18 | 20 |
|
19 | 21 | require 'vendor/autoload.php';
|
20 |
| -echo PHP_EOL; |
21 |
| -$display = DisplayBuilder::default()->build(); |
22 |
| -$total = 10; |
23 |
| -for ($done = 0; $done <= $total; ++$done) { |
24 |
| - // 重置光标位置 |
25 |
| - echo "\r\033[K"; |
26 |
| - $display->clear(); |
27 |
| - $display->draw( |
28 |
| - GridWidget::default() |
29 |
| - ->direction(Direction::Horizontal) |
30 |
| - ->constraints( |
31 |
| - Constraint::percentage(50), |
32 |
| - Constraint::percentage(50), |
33 |
| - ) |
34 |
| - ->widgets( |
35 |
| - BlockWidget::default()->borders(Borders::ALL)->titles(Title::fromString('Left')), |
36 |
| - GridWidget::default() |
37 |
| - ->direction(Direction::Vertical) |
38 |
| - ->constraints( |
39 |
| - Constraint::percentage(50), |
40 |
| - Constraint::percentage(50), |
41 |
| - ) |
42 |
| - ->widgets( |
43 |
| - BlockWidget::default()->borders(Borders::ALL)->titles(Title::fromString('Top Right'))->widget( |
44 |
| - \PhpTui\Tui\Extension\Core\Widget\ParagraphWidget::fromText( |
45 |
| - \PhpTui\Tui\Text\Text::parse( |
46 |
| - <<<EOT |
47 |
| - The <fg=green>{$done}</> is the totality of <options=bold>entities</>, |
48 |
| - the whole of reality, or everything that is.[1] The nature of the |
49 |
| - world has been <fg=red>conceptualized</> differently in different fields. Some |
50 |
| - conceptions see the world as unique while others talk of a |
51 |
| - plurality of <bg=green>worlds</>. |
52 |
| - EOT |
53 |
| - ) |
54 |
| - ) |
55 |
| - ), |
56 |
| - BlockWidget::default()->borders(Borders::ALL)->titles(Title::fromString('Bottom Right')), |
57 |
| - ) |
58 |
| - ) |
59 |
| - ); |
60 | 22 |
|
61 |
| - // 等待一段时间以模拟进程 |
62 |
| - \usleep(100000); |
63 |
| -} |
64 |
| -echo PHP_EOL; |
| 23 | + |
| 24 | +$socket = new \Swow\Socket(Swow\Socket::TYPE_TCP); |
| 25 | +$server = stream_socket_server('tls://127.0.0.1:9501', context: stream_context_create([ |
| 26 | + 'ssl' => [ |
| 27 | + 'alpn_protocols' => 'h2,http/1.1', |
| 28 | + 'local_cert' => __DIR__ . '/ssl/server.crt', |
| 29 | + 'local_pk' => __DIR__ . '/ssl/server.key', |
| 30 | + 'verify_peer' => false, |
| 31 | + 'verify_peer_name' => false, |
| 32 | + 'allow_self_signed' => true, |
| 33 | + ], |
| 34 | +])); |
| 35 | +$wr = new WaitReference(); |
| 36 | +Coroutine::run(static function () use ($server, $wr): void { |
| 37 | + $conn = stream_socket_accept($server); |
| 38 | + $payload = fread($conn, 1024); |
| 39 | + if (str_contains($payload, 'PRI * HTTP/2.0')) { |
| 40 | + echo "ALPN uses HTTP/2.0\n"; |
| 41 | + } else { |
| 42 | + echo "ALPN uses HTTP/1.1\n"; |
| 43 | + } |
| 44 | +}); |
| 45 | + |
| 46 | +$wr::wait($wr); |
| 47 | +//echo PHP_EOL; |
| 48 | +//$display = DisplayBuilder::default()->build(); |
| 49 | +//$total = 10; |
| 50 | +//for ($done = 0; $done <= $total; ++$done) { |
| 51 | +// // 重置光标位置 |
| 52 | +// echo "\r\033[K"; |
| 53 | +// $display->clear(); |
| 54 | +// $display->draw( |
| 55 | +// GridWidget::default() |
| 56 | +// ->direction(Direction::Horizontal) |
| 57 | +// ->constraints( |
| 58 | +// Constraint::percentage(50), |
| 59 | +// Constraint::percentage(50), |
| 60 | +// ) |
| 61 | +// ->widgets( |
| 62 | +// BlockWidget::default()->borders(Borders::ALL)->titles(Title::fromString('Left')), |
| 63 | +// GridWidget::default() |
| 64 | +// ->direction(Direction::Vertical) |
| 65 | +// ->constraints( |
| 66 | +// Constraint::percentage(50), |
| 67 | +// Constraint::percentage(50), |
| 68 | +// ) |
| 69 | +// ->widgets( |
| 70 | +// BlockWidget::default()->borders(Borders::ALL)->titles(Title::fromString('Top Right'))->widget( |
| 71 | +// \PhpTui\Tui\Extension\Core\Widget\ParagraphWidget::fromText( |
| 72 | +// \PhpTui\Tui\Text\Text::parse( |
| 73 | +// <<<EOT |
| 74 | +// The <fg=green>{$done}</> is the totality of <options=bold>entities</>, |
| 75 | +// the whole of reality, or everything that is.[1] The nature of the |
| 76 | +// world has been <fg=red>conceptualized</> differently in different fields. Some |
| 77 | +// conceptions see the world as unique while others talk of a |
| 78 | +// plurality of <bg=green>worlds</>. |
| 79 | +// EOT |
| 80 | +// ) |
| 81 | +// ) |
| 82 | +// ), |
| 83 | +// BlockWidget::default()->borders(Borders::ALL)->titles(Title::fromString('Bottom Right')), |
| 84 | +// ) |
| 85 | +// ) |
| 86 | +// ); |
| 87 | +// |
| 88 | +// // 等待一段时间以模拟进程 |
| 89 | +// \usleep(100000); |
| 90 | +//} |
| 91 | +//echo PHP_EOL; |
0 commit comments