<commit_before><?php

namespace org\octris\core\octsh\app {
    use \org\octris\core\app as app;
    use \org\octris\core\validate as validate;
    use \org\octris\core\provider as provider;
    
    /**
     * Implements command line shell.
     *
     * @octdoc      c:app/shell
     * @copyright   copyright (c) 2011 by <NAME>
     * @author      <NAME> <<EMAIL>>
     */
    class shell extends \org\octris\core\app\cli\page
    /**/
    {
        /**
         * The entry points to which the current page should allow requests to have to be defined with this
         * property.
         *
         * @octdoc  v:shell/$next_page
         * @var     array
         */
        protected $next_pages = array(
            'quit'      => '\org\octris\core\octsh\app\quit',
            'help'      => '\org\octris\core\octsh\app\help',
            'clear'     => '\org\octris\core\octsh\app\clear',
            'install'   => '\org\octris\core\octsh\app\install',
            'use'       => '\org\octris\core\octsh\app\useproject',
        );
        /**/

        /**
         * Constructor.
         *
         * @octdoc  m:shell/__construct
         */
        public function __construct()
        /**/
        {
            parent::__construct();
            
            $registry = \org\octris\core\registry::getInstance();
            
            if (!isset($registry->commands)) {
                // make commands and command classes available through registry
                $commands = $this->next_pages;
                ksort($commands);
                
                $registry->set(
                    'commands', 
                    $commands,
                    \org\octris\core\registry::T_SHARED | \org\octris\core\registry::T_READONLY
                );
            }
        }

        /**
         * Prepare page.
         *
         * @octdoc  m:shell/prepare
         * @param   \org\octris\core\app\page       $last_page      Instance of last called page.
         * @param   string                          $action         Action that led to current page.
         * @return  mixed                                           Returns either page to redirect to or null.
         */
        public function prepare(\org\octris\core\app\page $last_page, $action)
        /**/
        {
        }

        /**
         * Render page.
         *
         * @octdoc  m:entry/render
         * @param   string                          $action         Action that led to current page.
         */
        public function dialog($action)
        /**/
        {
            static $line = 0;
            
            // get shell input
            $input = '';
            
            do {
                if (posix_isatty(STDIN)) {
                    // octsh is called from a tty
                    $line = 1;
                    
                    $readline = \org\octris\core\app\cli\readline::getInstance('/tmp/octsh.txt');
                    $state    = app::getInstance()->getState();
            
                    $prompt   = $state['project']->value . ':octsh> ';

                    do {
                        $input = trim($readline->readline($prompt));
                    } while ($input == '');

                    $args = explode(' ', $return);
                    $cmd  = array_shift($args);
                } else {
                    // octsh is called from a pipe
                    ++$line;
                    
                    if (($input = fgets(STDIN))) {
                        $input = trim($input);
                    } else {
                        $input = 'quit';<commit_msg>- moved to app controller<commit_after><?php

namespace org\octris\core\octsh\app {
    use \org\octris\core\app as app;
    use \org\octris\core\validate as validate;
    use \org\octris\core\provider as provider;
    
    /**
     * Implements command line shell.
     *
     * @octdoc      c:app/shell
     * @copyright   copyright (c) 2011 by <NAME>
     * @author      <NAME> <<EMAIL>>
     */
    class shell extends \org\octris\core\app\cli\page
    /**/
    {
        /**
         * The entry points to which the current page should allow requests to have to be defined with this
         * property.
         *
         * @octdoc  v:shell/$next_page
         * @var     array
         */
        protected $next_pages = array(
            'quit'      => '\org\octris\core\octsh\app\quit',
            'help'      => '\org\octris\core\octsh\app\help',
            'clear'     => '\org\octris\core\octsh\app\clear',
            'install'   => '\org\octris\core\octsh\app\install',
            'use'       => '\org\octris\core\octsh\app\useproject',
        );
        /**/

        /**
         * Constructor.
         *
         * @octdoc  m:shell/__construct
         */
        public function __construct()
        /**/
        {
            parent::__construct();
            
            $registry = \org\octris\core\registry::getInstance();
            
            if (!isset($registry->commands)) {
                // make commands and command classes available through registry
                $commands = $this->next_pages;
                ksort($commands);
                
                $registry->set(
                    'commands', 
                    $commands,
                    \org\octris\core\registry::T_SHARED | \org\octris\core\registry::T_READONLY
                );
            }
        }

        /**
         * Prepare page.
         *
         * @octdoc  m:shell/prepare
         * @param   \org\octris\core\app\page       $last_page      Instance of last called page.
         * @param   string                          $action         Action that led to current page.
         * @return  mixed                                           Returns either page to redirect to or null.
         */
        public function prepare(\org\octris\core\app\page $last_page, $action)
        /**/
        {
        }

        /**
         * Render page.
         *
         * @octdoc  m:entry/render
         * @param   string                          $action         Action that led to current page.
         * @return  array                                           New request data.
         */
        public function dialog($action)
        /**/
        {
            static $line = 0;
            
            // get shell input
            $input = '';
            
            do {
                if (posix_isatty(STDIN)) {
                    // octsh is called from a tty
                    $line = 1;
                    
                    $readline = \org\octris\core\app\cli\readline::getInstance('/tmp/octsh.txt');
                    $state    = app::getInstance()->getState();
                    $prompt   = $state['project'] . ':octsh> ';

                    do {
                        $input = trim($readline->readline($prompt));
                    } while ($input == '');

                    $args = explode(' ', $return);
                    $cmd  = array_shift($args);
                } else {
                    // octsh is called from a pipe
                    ++$line;
                    
                    if (($input = fgets(STDIN))) {
                        $input = trim($input);
                    } else {
                        $input = 'quit';
{'fraction_non_alphanumeric': 0.11774281063483451, 'fraction_numerical': 0.0016277807921866521, 'mean_word_length': 1.030570090884054, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '949100', 'n_tokens_mistral': 1976, 'n_tokens_neox': 1884, 'n_words': 408}