Eren Yilmaz 6 năm trước cách đây
mục cha
commit
a16a733ff0
3 tập tin đã thay đổi với 22 bổ sung12 xóa
  1. 1 11
      client_controller.py
  2. 11 1
      run_client.py
  3. 10 0
      util.py

+ 1 - 11
client_controller.py

@@ -7,7 +7,7 @@ from connection import client_request
 from debug import debug
 from game import DEFAULT_ORDER_EXPIRY
 from run_client import allowed_commands, fake_loading_bar
-from util import my_tabulate
+from util import my_tabulate, yn_dialog
 
 exiting = False
 
@@ -196,16 +196,6 @@ def activate_key(key=''):
         print('Key activation failed with message:', response['error_message'])
 
 
-def yn_dialog(msg):
-    while True:
-        result = input(msg + ' [y/n]: ')
-        if result == 'y':
-            return True
-        if result == 'n':
-            return False
-        print('Type in \'y\' or \'n\'!')
-
-
 def buy(obj_name=None, amount=None, limit='', stop_loss='', expiry=None):
     if obj_name is None:  # TODO list some available objects
         obj_name = input('Name of object to buy: ')

+ 11 - 1
run_client.py

@@ -5,6 +5,7 @@ import time
 
 import client_controller
 from debug import debug
+from util import yn_dialog
 
 
 def fake_loading_bar(msg, duration=5.):
@@ -74,7 +75,14 @@ allowed_commands = ['help',
 
 
 def one_command():
-    cmd = input('*> ').strip()
+    try:
+        cmd = input('*> ').strip()
+    except KeyboardInterrupt:
+        if yn_dialog('Do you want to exit Orderer?'):
+            exit_client()
+            return
+        else:
+            return
     cmds = cmd.split(';')
     for cmd in cmds:
         cmd = cmd.split()
@@ -94,6 +102,8 @@ def one_command():
                 print('Invalid command syntax.')
             except ConnectionError:
                 print('There has been a problem connecting when to the server.')
+            except KeyboardInterrupt:
+                print('Interrupted')
             except Exception as _:
                 print('An unknown error occurred while executing a command.')
 

+ 10 - 0
util.py

@@ -50,3 +50,13 @@ def my_tabulate(data, **params):
         data = [(None for _ in params['headers'])]
     tabulate.MIN_PADDING = 0
     return tabulate.tabulate(data, **params)
+
+
+def yn_dialog(msg):
+    while True:
+        result = input(msg + ' [y/n]: ')
+        if result == 'y':
+            return True
+        if result == 'n':
+            return False
+        print('Type in \'y\' or \'n\'!')