summaryrefslogtreecommitdiffstats
path: root/ngxtop/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'ngxtop/utils.py')
-rw-r--r--ngxtop/utils.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/ngxtop/utils.py b/ngxtop/utils.py
new file mode 100644
index 0000000..ef61072
--- /dev/null
+++ b/ngxtop/utils.py
@@ -0,0 +1,19 @@
+import sys
+
+
+def choose_one(choices, prompt):
+ for idx, choice in enumerate(choices):
+ print('%d. %s' % (idx + 1, choice))
+ selected = None
+ while not selected or selected <= 0 or selected > len(choices):
+ selected = raw_input(prompt)
+ try:
+ selected = int(selected)
+ except ValueError:
+ selected = None
+ return choices[selected - 1]
+
+
+def error_exit(msg, status=1):
+ sys.stderr.write('Error: %s\n' % msg)
+ sys.exit(status) \ No newline at end of file