<?php
    
/**
    * o------------------------------------------------------------------------------o
    * | This package is licensed under the Phpguru license 2008. A quick summary is  |
    * | that the code is free to use for non-commercial purposes. For commercial     |
    * | purposes of any kind there is a small license fee to pay. You can read more  |
    * | at:                                                                          |
    * |                  http://www.phpguru.org/static/license.html                  |
    * o------------------------------------------------------------------------------o
    *
    * © Copyright 2008 Richard Heyes
    */

    
class Console_Menu
    
{
        private static 
$items;
        
        
/**
        * Shows the menu
        */
        
public function Display($title$items null)
        {
            if (!empty(
$items)) {
                
self::$items $items;
            }
            
            
$fp fopen('php://stdin''r');

            do {
                echo 
chr(033), "c";
                echo 
$title "\n" str_repeat('='strlen($title)). "\n\n";
                
                foreach (
self::$items as $k => $i) {
                    echo ++
$k ") {$i['text']}\n";
                }
                
                echo 
"\n";

                
$input trim(fgets($fp1024));

                
// Check the input is numeric
                
if (!is_numeric($input) OR empty(self::$items[$input 1])) {
                    echo 
chr(033), "cEnter a number from 1 - " count(self::$items) . " [Enter]";
                    
fgets($fp1024);
                    continue;
                }
                
                
// Does the specified function exist?
                
if (!function_exists(self::$items[$input 1]['func'])) {
                    echo 
chr(033), "cThe specified function doesn't exist! [Enter]";
                    
fgets($fp1024);
                    continue;
                }
                
                
call_user_func(self::$items[$input 1]['func']);

            } while (
true);
        }
    }
?>