PHP Class PhpSchool\CliMenu\CliMenu

Author: Michael Woodward ([email protected])
Show file Open project: php-school/cli-menu Class Usage Examples

Protected Properties

Property Type Description
$items PhpSchool\CliMenu\MenuItem\MenuItemInterface[]
$open boolean
$parent CliMenu | null
$selectedItem integer
$style MenuStyle
$terminal PhpSchool\CliMenu\Terminal\TerminalInterface
$title string

Public Methods

Method Description
__construct ( string $title, array $items, PhpSchool\CliMenu\Terminal\TerminalInterface $terminal = null, MenuStyle $style = null )
addItem ( PhpSchool\CliMenu\MenuItem\MenuItemInterface $item ) Add a new Item to the listing
close ( ) Close the menu
closeThis ( )
confirm ( string $text ) : Confirm
flash ( string $text ) : Flash
getCurrentFrame ( )
getItems ( ) : PhpSchool\CliMenu\MenuItem\MenuItemInterface[]
getParent ( ) : CliMenu | null
getSelectedItem ( ) : PhpSchool\CliMenu\MenuItem\MenuItemInterface
getStyle ( ) : MenuStyle
getTerminal ( ) : PhpSchool\CliMenu\Terminal\TerminalInterface
isOpen ( ) : boolean
open ( )
redraw ( ) Redraw the menu
removeItem ( PhpSchool\CliMenu\MenuItem\MenuItemInterface $item )
setParent ( CliMenu $parent )

Protected Methods

Method Description
configureTerminal ( ) Configure the terminal to work with CliMenu
draw ( ) Draw the menu to STDOUT
drawMenuItem ( PhpSchool\CliMenu\MenuItem\MenuItemInterface $item, boolean | false $selected = false ) : array Draw a menu item
executeCurrentItem ( ) Execute the current item
moveSelection ( $direction ) Move the selection in a given direction, up / down
tearDownTerminal ( ) Revert changes made to the terminal

Private Methods

Method Description
assertTerminalIsValidTTY ( )
display ( ) Display menu and capture input
selectFirstItem ( ) Set the selected pointer to the first selectable item

Method Details

__construct() public method

public __construct ( string $title, array $items, PhpSchool\CliMenu\Terminal\TerminalInterface $terminal = null, MenuStyle $style = null )
$title string
$items array
$terminal PhpSchool\CliMenu\Terminal\TerminalInterface
$style MenuStyle

addItem() public method

Add a new Item to the listing
public addItem ( PhpSchool\CliMenu\MenuItem\MenuItemInterface $item )
$item PhpSchool\CliMenu\MenuItem\MenuItemInterface

close() public method

Close the menu
public close ( )

closeThis() public method

public closeThis ( )

configureTerminal() protected method

Configure the terminal to work with CliMenu
protected configureTerminal ( )

confirm() public method

public confirm ( string $text ) : Confirm
$text string
return PhpSchool\CliMenu\Dialogue\Confirm

draw() protected method

Draw the menu to STDOUT
protected draw ( )

drawMenuItem() protected method

Draw a menu item
protected drawMenuItem ( PhpSchool\CliMenu\MenuItem\MenuItemInterface $item, boolean | false $selected = false ) : array
$item PhpSchool\CliMenu\MenuItem\MenuItemInterface
$selected boolean | false
return array

executeCurrentItem() protected method

Execute the current item
protected executeCurrentItem ( )

flash() public method

public flash ( string $text ) : Flash
$text string
return PhpSchool\CliMenu\Dialogue\Flash

getCurrentFrame() public method

public getCurrentFrame ( )

getItems() public method

public getItems ( ) : PhpSchool\CliMenu\MenuItem\MenuItemInterface[]
return PhpSchool\CliMenu\MenuItem\MenuItemInterface[]

getParent() public method

public getParent ( ) : CliMenu | null
return CliMenu | null

getSelectedItem() public method

public getSelectedItem ( ) : PhpSchool\CliMenu\MenuItem\MenuItemInterface
return PhpSchool\CliMenu\MenuItem\MenuItemInterface

getStyle() public method

public getStyle ( ) : MenuStyle
return MenuStyle

getTerminal() public method

public getTerminal ( ) : PhpSchool\CliMenu\Terminal\TerminalInterface
return PhpSchool\CliMenu\Terminal\TerminalInterface

isOpen() public method

public isOpen ( ) : boolean
return boolean

moveSelection() protected method

Move the selection in a given direction, up / down
protected moveSelection ( $direction )
$direction

open() public method

public open ( )

redraw() public method

Redraw the menu
public redraw ( )

removeItem() public method

public removeItem ( PhpSchool\CliMenu\MenuItem\MenuItemInterface $item )
$item PhpSchool\CliMenu\MenuItem\MenuItemInterface

setParent() public method

public setParent ( CliMenu $parent )
$parent CliMenu

tearDownTerminal() protected method

Revert changes made to the terminal
protected tearDownTerminal ( )

Property Details

$items protected property

protected MenuItemInterface[],PhpSchool\CliMenu\MenuItem $items
return PhpSchool\CliMenu\MenuItem\MenuItemInterface[]

$open protected property

protected bool $open
return boolean

$parent protected property

protected CliMenu,PhpSchool\CliMenu|null $parent
return CliMenu | null

$selectedItem protected property

protected int $selectedItem
return integer

$style protected property

protected MenuStyle,PhpSchool\CliMenu $style
return MenuStyle

$terminal protected property

protected TerminalInterface,PhpSchool\CliMenu\Terminal $terminal
return PhpSchool\CliMenu\Terminal\TerminalInterface

$title protected property

protected string $title
return string