add a commutator for color on cmdline and treat traces color off

This commit is contained in:
Florent 2025-11-09 10:52:27 +01:00
parent e7e1275ee5
commit fc3f522005

View file

@ -773,6 +773,7 @@ Line starting with \"$\" or \".\" will issue a meshcli command.
prompt = f"{ANSI_INVERT}" prompt = f"{ANSI_INVERT}"
if print_name or contact is None : if print_name or contact is None :
if color:
prompt = prompt + f"{ANSI_BGRAY}" prompt = prompt + f"{ANSI_BGRAY}"
prompt = prompt + f"{mc.self_info['name']}" prompt = prompt + f"{mc.self_info['name']}"
if contact is None: # display scope if contact is None: # display scope
@ -2340,7 +2341,8 @@ async def next_cmd(mc, cmds, json_output=False):
if json_output: if json_output:
print(json.dumps(ev.payload, indent=2)) print(json.dumps(ev.payload, indent=2))
else : else :
classic = interactive_loop.classic or not process_event_message.color color = process_event_message.color
classic = interactive_loop.classic or not color
print("]",end="") print("]",end="")
for t in ev.payload["path"]: for t in ev.payload["path"]:
if classic : if classic :
@ -2348,6 +2350,7 @@ async def next_cmd(mc, cmds, json_output=False):
else: else:
print(f" {ANSI_INVERT}", end="") print(f" {ANSI_INVERT}", end="")
snr = t['snr'] snr = t['snr']
if color:
if snr >= 10 : if snr >= 10 :
print(ANSI_BGREEN, end="") print(ANSI_BGREEN, end="")
elif snr <= 0: elif snr <= 0:
@ -2359,6 +2362,7 @@ async def next_cmd(mc, cmds, json_output=False):
print("",end="") print("",end="")
else : else :
print(f"{ANSI_NORMAL}{ARROW_HEAD}",end="") print(f"{ANSI_NORMAL}{ARROW_HEAD}",end="")
if color:
print(ANSI_END, end="") print(ANSI_END, end="")
if "hash" in t: if "hash" in t:
print(f"[{t['hash']}]",end="") print(f"[{t['hash']}]",end="")
@ -3143,6 +3147,7 @@ def usage () :
-D : debug -D : debug
-S : scan for devices and show a selector -S : scan for devices and show a selector
-l : list available ble/serial devices and exit -l : list available ble/serial devices and exit
-c <on/off> : disables most of color output if off
-T <timeout> : timeout for the ble scan (-S and -l) default 2s -T <timeout> : timeout for the ble scan (-S and -l) default 2s
-a <address> : specifies device address (can be a name) -a <address> : specifies device address (can be a name)
-d <name> : filter meshcore devices with name or address -d <name> : filter meshcore devices with name or address
@ -3210,9 +3215,12 @@ async def main(argv):
with open(MCCLI_ADDRESS, encoding="utf-8") as f : with open(MCCLI_ADDRESS, encoding="utf-8") as f :
address = f.readline().strip() address = f.readline().strip()
opts, args = getopt.getopt(argv, "a:d:s:ht:p:b:fjDhvSlT:P") opts, args = getopt.getopt(argv, "a:d:s:ht:p:b:fjDhvSlT:Pc:")
for opt, arg in opts : for opt, arg in opts :
match opt: match opt:
case "-c" :
if arg == "off":
process_event_message.color = False
case "-d" : # name specified on cmdline case "-d" : # name specified on cmdline
address = arg address = arg
case "-a" : # address specified on cmdline case "-a" : # address specified on cmdline