/usr/share/phoronix-test-suite/pts-core/objects/pts_user_io.php is in phoronix-test-suite 4.8.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | <?php
/*
Phoronix Test Suite
URLs: http://www.phoronix.com, http://www.phoronix-test-suite.com/
Copyright (C) 2008 - 2012, Phoronix Media
Copyright (C) 2008 - 2012, Michael Larabel
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class pts_user_io
{
public static function read_user_input()
{
return trim(fgets(STDIN));
}
public static function prompt_user_input($question, $allow_null = false)
{
do
{
echo PHP_EOL . $question . ': ';
$answer = pts_user_io::read_user_input();
}
while(!$allow_null && empty($answer));
return $answer;
}
public static function display_interrupt_message($message)
{
if(!empty($message))
{
echo $message . PHP_EOL;
if((pts_c::$test_flags ^ pts_c::batch_mode) && (pts_c::$test_flags ^ pts_c::auto_mode))
{
echo PHP_EOL . 'Hit Any Key To Continue...' . PHP_EOL;
pts_user_io::read_user_input();
}
}
}
public static function display_text_list($list_items, $line_start = '- ')
{
$list = null;
foreach($list_items as &$item)
{
$list .= $line_start . $item . PHP_EOL;
}
return $list;
}
public static function display_text_table(&$table)
{
$column_widths = array();
$formatted_table = null;
for($r = 0; $r < count($table); $r++)
{
for($c = 0; $c < count($table[$r]); $c++)
{
if(!isset($column_widths[$c]) || isset($table[$r][$c][$column_widths[$c]]))
{
$column_widths[$c] = strlen($table[$r][$c]);
}
}
}
for($r = 0, $r_count = count($table); $r < $r_count; $r++)
{
for($c = 0, $rc_count = count($table[$r]); $c < $rc_count; $c++)
{
$formatted_table .= $table[$r][$c];
if(($c + 1) != $rc_count)
{
$formatted_table .= str_repeat(' ', (1 + $column_widths[$c] - strlen($table[$r][$c])));
}
}
if(($r + 1) != $r_count)
{
$formatted_table .= PHP_EOL;
}
}
return $formatted_table;
}
public static function prompt_bool_input($question, $default = true, $question_id = 'UNKNOWN')
{
// Prompt user for yes/no question
if((pts_c::$test_flags & pts_c::batch_mode))
{
switch($question_id)
{
default:
$auto_answer = 'true';
break;
}
$answer = pts_strings::string_bool($auto_answer);
}
else
{
$question .= ' (' . ($default == true ? 'Y/n' : 'y/N') . '): ';
do
{
pts_client::$display->generic_prompt($question);
$input = strtolower(pts_user_io::read_user_input());
}
while($input != 'y' && $input != 'n' && $input != '');
switch($input)
{
case 'y':
$answer = true;
break;
case 'n':
$answer = false;
break;
default:
$answer = $default;
break;
}
}
return $answer;
}
public static function prompt_text_menu($user_string, $options_r, $allow_multi_select = false, $return_index = false, $line_prefix = null)
{
$option_count = count($options_r);
if($option_count == 1)
{
return $return_index ? pts_arrays::last_element(array_keys($options_r)) : array_pop($options_r);
}
$select = array();
do
{
echo PHP_EOL;
$key_index = array();
foreach(array_keys($options_r) as $i => $key)
{
$key_index[($i + 1)] = $key;
echo $line_prefix . ($i + 1) . ': ' . str_repeat(' ', strlen($option_count) - strlen(($i + 1))) . $options_r[$key] . PHP_EOL;
}
echo $line_prefix . $user_string . ': ';
$select_choice = pts_user_io::read_user_input();
foreach(($allow_multi_select ? pts_strings::comma_explode($select_choice) : array($select_choice)) as $choice)
{
if(in_array($choice, $options_r))
{
array_push($select, array_search($choice, $options_r));
}
else if(isset($key_index[$choice]))
{
array_push($select, $key_index[$choice]);
}
}
}
while(!isset($select[0]));
if($return_index == false)
{
foreach($select as &$index)
{
$index = $options_r[$index];
}
}
return implode(',', $select);
}
}
?>
|