Fix os.get_terminal_size() error.

pull/25/head
Bigbits 2019-04-24 18:52:41 +08:00
parent 82ad60b7d7
commit 927ae408ab
1 changed files with 14 additions and 3 deletions

View File

@ -376,6 +376,17 @@ def chunks(l, n):
yield l[i:i + n]
def get_terminal_size(fallback=(100, 24)):
for i in range(0,3):
try:
columns, rows = os.get_terminal_size(i)
except OSError:
continue
break
else: # set default if the loop completes which means all failed
columns, rows = fallback
return columns, rows
class MAIXLoader:
def change_baudrate(self, baudrate):
print(INFO_MSG,"Selected Baudrate: ", baudrate, BASH_TIPS['DEFAULT'])
@ -730,7 +741,7 @@ class MAIXLoader:
if self.recv_debug():
break
columns, lines = os.get_terminal_size()
columns, lines = get_terminal_size()
time_delta = time.time() - time_start
speed = ''
if (time_delta > 1):
@ -844,7 +855,7 @@ class MAIXLoader:
# 3.1 刷入一个dataframe
#print('[INFO]', 'Write firmware data piece')
self.dump_to_flash(chunk, address= n * 4096 + address_offset)
columns, lines = os.get_terminal_size()
columns, lines = get_terminal_size()
time_delta = time.time() - time_start
speed = ''
if (time_delta > 1):
@ -1096,4 +1107,4 @@ if __name__ == '__main__':
loader._port.close()
if(args.terminal == True):
open_terminal(True)
open_terminal(True)