idf_monitor: Exit with CTRL+X in menu

Currently, the only way of exiting the idf_monitor program is to hit the CTRL+] button, if your keyboard doesn't have that key unless you hit another modifier key, it's not super trivial to exit.

This change adds the option to exit with CTRL+T (for menu) then hitting X (or CTRL+X) for exiting.

Closes https://github.com/espressif/esp-idf/pull/4167
Closes https://github.com/espressif/esp-idf/issues/4129
This commit is contained in:
Per-Olov Jernberg 2019-10-06 15:03:23 +02:00 committed by Roland Dobai
parent fe83420144
commit 0afad4c7a7

View file

@ -64,6 +64,7 @@ CTRL_R = '\x12'
CTRL_T = '\x14' CTRL_T = '\x14'
CTRL_Y = '\x19' CTRL_Y = '\x19'
CTRL_P = '\x10' CTRL_P = '\x10'
CTRL_X = '\x18'
CTRL_RBRACKET = '\x1d' # Ctrl+] CTRL_RBRACKET = '\x1d' # Ctrl+]
# ANSI terminal codes (if changed, regular expressions in LineMatcher need to be udpated) # ANSI terminal codes (if changed, regular expressions in LineMatcher need to be udpated)
@ -477,6 +478,9 @@ class Monitor(object):
self.serial.setRTS(False) # EN=HIGH, chip out of reset self.serial.setRTS(False) # EN=HIGH, chip out of reset
time.sleep(0.45) # timeouts taken from esptool.py, includes esp32r0 workaround. defaults: 0.05 time.sleep(0.45) # timeouts taken from esptool.py, includes esp32r0 workaround. defaults: 0.05
self.serial.setDTR(False) # IO0=HIGH, done self.serial.setDTR(False) # IO0=HIGH, done
elif c in [CTRL_X, 'x', 'X']: # Exiting from within the menu
self.console_reader.stop()
self.serial_reader.stop()
else: else:
red_print('--- unknown menu character {} --'.format(key_description(c))) red_print('--- unknown menu character {} --'.format(key_description(c)))
@ -495,6 +499,7 @@ class Monitor(object):
--- {appmake:7} Build & flash app only --- {appmake:7} Build & flash app only
--- {output:7} Toggle output display --- {output:7} Toggle output display
--- {pause:7} Reset target into bootloader to pause app via RTS line --- {pause:7} Reset target into bootloader to pause app via RTS line
--- {menuexit:7} Exit program
""".format(version=__version__, """.format(version=__version__,
exit=key_description(self.exit_key), exit=key_description(self.exit_key),
menu=key_description(self.menu_key), menu=key_description(self.menu_key),
@ -502,7 +507,8 @@ class Monitor(object):
makecmd=key_description(CTRL_F), makecmd=key_description(CTRL_F),
appmake=key_description(CTRL_A), appmake=key_description(CTRL_A),
output=key_description(CTRL_Y), output=key_description(CTRL_Y),
pause=key_description(CTRL_P) ) pause=key_description(CTRL_P),
menuexit=key_description(CTRL_X) + ' (or X)')
def __enter__(self): def __enter__(self):
""" Use 'with self' to temporarily disable monitoring behaviour """ """ Use 'with self' to temporarily disable monitoring behaviour """