Page MenuHomePhabricator

D16927.id40748.diff
No OneTemporary

D16927.id40748.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -491,6 +491,7 @@
'phutil_console_get_terminal_width' => 'console/format.php',
'phutil_console_prompt' => 'console/format.php',
'phutil_console_require_tty' => 'console/format.php',
+ 'phutil_console_select' => 'console/format.php',
'phutil_console_wrap' => 'console/format.php',
'phutil_count' => 'internationalization/pht.php',
'phutil_date_format' => 'utils/viewutils.php',
diff --git a/src/console/format.php b/src/console/format.php
--- a/src/console/format.php
+++ b/src/console/format.php
@@ -24,6 +24,20 @@
}
}
+function phutil_console_select($prompt, $min, $max) {
+ $select_options = '['.$min.' - '.$max.']';
+ do {
+ $response = phutil_console_prompt($prompt.' '.$select_options);
+ $selection = trim($response);
+
+ if (preg_match('/^\d+\z/', $selection)) {
+ $selection = (int)$selection;
+ if ($selection >= $min && $selection <= $max) {
+ return $selection;
+ }
+ }
+ } while (true);
+}
function phutil_console_prompt($prompt, $history = '') {
echo "\n\n";

File Metadata

Mime Type
text/plain
Expires
Sun, Mar 16, 3:10 AM (6 d, 16 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7705413
Default Alt Text
D16927.id40748.diff (1 KB)

Event Timeline