Commit 9c24dcb0 authored by ibuler's avatar ibuler

[Bugfix] 修复opt> 中输入删除的bug

parent 3387aa0b
...@@ -294,7 +294,7 @@ def get_logger(file_name): ...@@ -294,7 +294,7 @@ def get_logger(file_name):
return logging.getLogger('coco.'+file_name) return logging.getLogger('coco.'+file_name)
def net_input(client, prompt='Opt> ', sensitive=False, before=0, after=0, only_one_char=False): def net_input(client, prompt='Opt> ', sensitive=False, before=0, after=0):
"""实现了一个ssh input, 提示用户输入, 获取并返回 """实现了一个ssh input, 提示用户输入, 获取并返回
:return user input string :return user input string
...@@ -303,12 +303,8 @@ def net_input(client, prompt='Opt> ', sensitive=False, before=0, after=0, only_o ...@@ -303,12 +303,8 @@ def net_input(client, prompt='Opt> ', sensitive=False, before=0, after=0, only_o
parser = TtyIOParser() parser = TtyIOParser()
client.send(wrap_with_line_feed(prompt, before=before, after=after)) client.send(wrap_with_line_feed(prompt, before=before, after=after))
if only_one_char:
data = client.recv(1)
return data.decode()
while True: while True:
data = client.recv(10) data = client.recv(1)
if len(data) == 0: if len(data) == 0:
break break
# Client input backspace # Client input backspace
...@@ -336,18 +332,8 @@ def net_input(client, prompt='Opt> ', sensitive=False, before=0, after=0, only_o ...@@ -336,18 +332,8 @@ def net_input(client, prompt='Opt> ', sensitive=False, before=0, after=0, only_o
client.send(b'') client.send(b'')
continue continue
# handle shell expect
multi_char_with_enter = False
if len(data) > 1 and data[-1] in char.ENTER_CHAR_ORDER:
if sensitive:
client.send(len(data) * '*')
else:
client.send(data)
input_data.append(data[:-1])
multi_char_with_enter = True
# If user types ENTER we should get user input # If user types ENTER we should get user input
if data in char.ENTER_CHAR or multi_char_with_enter: if data in char.ENTER_CHAR:
client.send(wrap_with_line_feed(b'', after=2)) client.send(wrap_with_line_feed(b'', after=2))
option = parser.parse_input(input_data) option = parser.parse_input(input_data)
del input_data[:] del input_data[:]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment