From f796a5ae8147896edb0988d782b082ef9708f26e Mon Sep 17 00:00:00 2001 From: Aydin Hassan Date: Tue, 17 Dec 2019 23:01:00 +0100 Subject: [PATCH] Fix closing and reopening the menu --- composer.json | 2 +- examples/check-crazy.php | 26 ++++++++++++++++++++++++++ src/CliMenu.php | 2 ++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 examples/check-crazy.php diff --git a/composer.json b/composer.json index b07d3a74..46fd3448 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "require": { "php" : ">=7.1", "beberlei/assert": "^2.4 | ^3", - "php-school/terminal": "^0.2", + "php-school/terminal": "^0.2.1", "ext-posix": "*" }, "autoload" : { diff --git a/examples/check-crazy.php b/examples/check-crazy.php new file mode 100644 index 00000000..00638f4b --- /dev/null +++ b/examples/check-crazy.php @@ -0,0 +1,26 @@ +getSelectedItem()->getText(); +}; + +$menu = (new CliMenuBuilder) + ->setTitle('Select a Language') + ->addSplitItem(function (SplitItemBuilder $b) use ($itemCallable) { + $b->setGutter(5) + ->addCheckableItem('Rust', $itemCallable) + ->addCheckableItem('C++', $itemCallable) + ->addCheckableItem('Go', $itemCallable) + ->addCheckableItem('Java', $itemCallable) + ->addCheckableItem('C', $itemCallable) + ; + }) + ->build(); + +$menu->open(); diff --git a/src/CliMenu.php b/src/CliMenu.php index 56174747..5b7631ba 100644 --- a/src/CliMenu.php +++ b/src/CliMenu.php @@ -117,6 +117,8 @@ protected function configureTerminal() : void protected function tearDownTerminal() : void { $this->terminal->restoreOriginalConfiguration(); + $this->terminal->enableCanonicalMode(); + $this->terminal->enableEchoBack(); $this->terminal->enableCursor(); }