Index: trunk/phase3/maintenance/eval.php |
— | — | @@ -39,8 +39,24 @@ |
40 | 40 | } |
41 | 41 | } |
42 | 42 | |
| 43 | +if ( function_exists( 'readline_add_history' ) |
| 44 | + && function_exists( 'posix_isatty' ) && posix_isatty( 0 /*STDIN*/ ) ) |
| 45 | +{ |
| 46 | + $useReadline = true; |
| 47 | +} else { |
| 48 | + $useReadline = false; |
| 49 | +} |
43 | 50 | |
| 51 | +if ( $useReadline ) { |
| 52 | + $historyFile = "{$_ENV['HOME']}/.mweval_history"; |
| 53 | + readline_read_history( $historyFile ); |
| 54 | +} |
| 55 | + |
44 | 56 | while ( ( $line = readconsole( '> ' ) ) !== false ) { |
| 57 | + if ( $useReadline ) { |
| 58 | + readline_add_history( $line ); |
| 59 | + readline_write_history( $historyFile ); |
| 60 | + } |
45 | 61 | $val = eval( $line . ";" ); |
46 | 62 | if( is_null( $val ) ) { |
47 | 63 | echo "\n"; |
— | — | @@ -49,9 +65,6 @@ |
50 | 66 | } else { |
51 | 67 | var_dump( $val ); |
52 | 68 | } |
53 | | - if ( function_exists( "readline_add_history" ) ) { |
54 | | - readline_add_history( $line ); |
55 | | - } |
56 | 69 | } |
57 | 70 | |
58 | 71 | print "\n"; |