-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
125 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
/** | ||
* Menu Task | ||
* | ||
* @package Oni | ||
* @author Scar Wu | ||
* @copyright Copyright (c) Scar Wu (https://scar.tw) | ||
* @link https://github.com/scarwu/Oni | ||
*/ | ||
|
||
namespace CLIApp\Task; | ||
|
||
use Oni\CLI\Task; | ||
|
||
class MenuTask extends Task | ||
{ | ||
public function run() | ||
{ | ||
$count = $this->io->ask('Item counts of menu? [10] ', function ($value) { | ||
return true === (bool) preg_match('/^\d+$/', $value) || '' === $value; | ||
}); | ||
|
||
if ('' !== $count) { | ||
$count = (int) $count; | ||
} else { | ||
$count = 10; | ||
} | ||
|
||
if (0 === $count) { | ||
$count = 10; | ||
} | ||
|
||
$lines = $this->io->ask('Display lines of menu? [3] ', function ($value) { | ||
return true === (bool) preg_match('/^\d+$/', $value) || '' === $value; | ||
}); | ||
|
||
if ('' !== $lines) { | ||
$lines = (int) $lines; | ||
} else { | ||
$lines = 3; | ||
} | ||
|
||
if (0 === $lines) { | ||
$lines = 3; | ||
} | ||
|
||
if ($lines > $count) { | ||
$lines = $count; | ||
} | ||
|
||
$list = []; | ||
|
||
for ($index = 0; $index < $count; $index++) { | ||
$list[] = sprintf('[%3d]', $index) . ' ' . md5($index); | ||
} | ||
|
||
$this->io->writeln("Select Index"); | ||
|
||
$index = $this->io->menuSelect($list, $lines); | ||
|
||
$this->io->log("You selected index is {$index}!"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters