Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: CI

on:
push:
branches: [master]
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
tests:
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
php: ['8.2', '8.3', '8.4', '8.5']
name: PHP ${{ matrix.php }}
env:
TERM: xterm-256color
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none
- uses: ramsey/composer-install@v3
with:
dependency-versions: highest
- run: vendor/bin/phpunit --stop-on-error
- if: matrix.php == '8.5'
run: composer cs-dry-run
- if: matrix.php == '8.5'
run: composer static
32 changes: 0 additions & 32 deletions .github/workflows/static.yml

This file was deleted.

36 changes: 0 additions & 36 deletions .github/workflows/test.yml

This file was deleted.

11 changes: 1 addition & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,7 @@

<p align="center">
<a href="https://github.com/php-school/cli-menu/actions" title="Build Status" target="_blank">
<img src="https://img.shields.io/github/actions/workflow/status/php-school/cli-menu/test.yml?style=flat-square&label=Linux" />
</a>
<a href="https://ci.appveyor.com/project/mikeymike/cli-menu" title="Windows Build Status" target="_blank">
<img src="https://img.shields.io/appveyor/ci/mikeymike/cli-menu/master.svg?style=flat-square&label=Windows" />
</a>
<a href="https://codecov.io/github/php-school/cli-menu" title="Coverage Status" target="_blank">
<img src="https://img.shields.io/codecov/c/github/php-school/cli-menu.svg?style=flat-square" />
</a>
<a href="https://scrutinizer-ci.com/g/php-school/cli-menu/" title="Scrutinizer Code Quality" target="_blank">
<img src="https://img.shields.io/scrutinizer/g/php-school/cli-menu.svg?style=flat-square" />
<img src="https://img.shields.io/github/actions/workflow/status/php-school/cli-menu/ci.yml?branch=master&style=flat-square&label=CI" />
</a>
<a href="https://phpschool-team.slack.com/messages">
<img src="https://phpschool.herokuapp.com/badge.svg">
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"require": {
"php" : ">=8.2",
"beberlei/assert": "^2.4 | ^3",
"php-school/terminal": "^0.2.1",
"php-school/terminal": "^0.3",
"ext-posix": "*",
"ext-mbstring": "*"
},
Expand Down
19 changes: 14 additions & 5 deletions src/CliMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,17 +345,26 @@ protected function moveSelectionVertically(string $direction): void
} while (!$this->canSelect());
}

private function getSelectedMenuItem(): MenuItemInterface
{
if (null === $this->selectedItem) {
throw new \RuntimeException('No item is currently selected');
}

return $this->items[$this->selectedItem];
}

/**
* Move the selection in a given direction, left / right
*/
protected function moveSelectionHorizontally(string $direction): void
{
if (!$this->items[$this->selectedItem] instanceof SplitItem) {
if (!$this->getSelectedMenuItem() instanceof SplitItem) {
return;
}

/** @var SplitItem $item */
$item = $this->items[$this->selectedItem];
$item = $this->getSelectedMenuItem();
$itemKeys = array_keys($item->getItems());
$selectedItemIndex = $item->getSelectedItemIndex();

Expand Down Expand Up @@ -391,7 +400,7 @@ protected function moveSelectionHorizontally(string $direction): void
*/
private function canSelect(): bool
{
return $this->items[$this->selectedItem]->canSelect();
return $this->getSelectedMenuItem()->canSelect();
}

/**
Expand All @@ -404,7 +413,7 @@ public function getSelectedItem(): MenuItemInterface
throw new \RuntimeException('No selected item');
}

$item = $this->items[$this->selectedItem];
$item = $this->getSelectedMenuItem();
return $item instanceof SplitItem
? $item->getSelectedItem()
: $item;
Expand Down Expand Up @@ -441,7 +450,7 @@ public function getItemByIndex(int $index): MenuItemInterface

public function executeAsSelected(MenuItemInterface $item): void
{
$current = $this->items[$this->selectedItem];
$current = $this->getSelectedMenuItem();
$this->setSelectedItem($item);
$this->executeCurrentItem();
$this->setSelectedItem($current);
Expand Down
2 changes: 0 additions & 2 deletions test/MenuStyleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public function testMenuStyleCanBeInstantiatedByCliMenuBuilder(): void
self::assertTrue($reflectionMenu->hasProperty('style'));

$styleProperty = $reflectionMenu->getProperty('style');
$styleProperty->setAccessible(true);
$style = $styleProperty->getValue($menu);

self::assertSame(MenuStyle::class, get_class($style));
Expand Down Expand Up @@ -678,7 +677,6 @@ public function testDebugMode(): void
$style = $this->getMenuStyle(8, 40);

$prop = new \ReflectionProperty(MenuStyle::class, 'debugMode');
$prop->setAccessible(true);
$prop->setValue($style, true);

$style->setWidth(30);
Expand Down
Loading