@@ -100,6 +100,9 @@ async def process_event_message(mc, ev, json_output, end="\n", above=False):
100100 disp = disp + f"{ ANSI_YELLOW } ({ path_str } ){ ANSI_END } : "
101101 disp = disp + f"{ data ['text' ]} "
102102
103+ if not process_event_message .color :
104+ disp = escape_ansi (disp )
105+
103106 if above :
104107 print_above (disp )
105108 else :
@@ -108,6 +111,10 @@ async def process_event_message(mc, ev, json_output, end="\n", above=False):
108111 elif (data ['type' ] == "CHAN" ) :
109112 path_str = f"{ ANSI_YELLOW } ({ path_str } ){ ANSI_END } "
110113 disp = f"{ ANSI_GREEN } ch{ data ['channel_idx' ]} { path_str } : { data ['text' ]} "
114+
115+ if not process_event_message .color :
116+ disp = escape_ansi (disp )
117+
111118 if above :
112119 print_above (disp )
113120 else :
@@ -116,6 +123,7 @@ async def process_event_message(mc, ev, json_output, end="\n", above=False):
116123 print (json .dumps (ev .payload ))
117124 return True
118125process_event_message .print_snr = False
126+ process_event_message .color = True
119127
120128async def handle_message (event ):
121129 """ Process incoming message events """
@@ -145,9 +153,10 @@ def make_completion_dict(contacts):
145153 "set" : {"pin" : None , "radio" : None , "tuning" : None , "tx" : None ,
146154 "name" : None , "lat" : None , "lon" : None , "coords" : None ,
147155 "print_snr" : {"on" :None , "off" : None },
148- "json_msgs" : {"on" :None , "off" : None }},
156+ "json_msgs" : {"on" :None , "off" : None },
157+ "color" : {"on" :None , "off" :None }},
149158 "get" : {"name" : None , "bat" : None , "coords" : None , "radio" : None ,
150- "tx" : None , "print_snr" : None , "json_msgs" :None },
159+ "tx" : None , "print_snr" : None , "json_msgs" :None , "color" : None },
151160 "reboot" : None ,
152161 "card" : None ,
153162 "login" : None ,
@@ -224,6 +233,10 @@ async def interactive_loop(mc, to=None) :
224233 if not last_ack :
225234 prompt = prompt + f"{ ANSI_RED } !"
226235 prompt = prompt + f"{ ANSI_BLUE } { contact ['adv_name' ]} >{ ANSI_END } "
236+
237+ if not process_event_message .color :
238+ prompt = escape_ansi (prompt )
239+
227240 line = await session .prompt_async (ANSI (prompt ), complete_while_typing = False )
228241
229242 if line == "" : # blank line
@@ -246,6 +259,7 @@ async def interactive_loop(mc, to=None) :
246259 line .startswith ("floodadv" ) or \
247260 line .startswith ("chan" ) or \
248261 line .startswith ("card" ) or \
262+ line .startswith ("lc" ) or \
249263 line == "infos" or line == "i" :
250264 args = shlex .split (line )
251265 await process_cmds (mc , args )
@@ -317,8 +331,12 @@ async def interactive_loop(mc, to=None) :
317331
318332 elif line == "list" : # list command from chat displays contacts on a line
319333 it = iter (mc .contacts .items ())
334+ first = True
320335 for c in it :
321- print (f", { c [1 ]['adv_name' ]} " , end = "" )
336+ if not first :
337+ print (", " , end = "" )
338+ first = False
339+ print (f"{ c [1 ]['adv_name' ]} " , end = "" )
322340 print ("" )
323341
324342 else :
@@ -444,6 +462,8 @@ async def next_cmd(mc, cmds, json_output=False):
444462 lon <lon> : longitude
445463 coords <lat,lon> : coordinates
446464 print_snr <on/off> : toggle snr display in messages""" )
465+ case "color" :
466+ process_event_message .color = (cmds [2 ] == "on" )
447467 case "print_snr" :
448468 process_event_message .print_snr = (cmds [2 ] == "on" )
449469 case "json_msgs" :
@@ -547,6 +567,11 @@ async def next_cmd(mc, cmds, json_output=False):
547567 print (json .dumps ({"json_msgs" : handle_message .json_output }))
548568 else :
549569 print (f"{ 'on' if handle_message .json_output else 'off' } " )
570+ case "color" :
571+ if json_output :
572+ print (json .dumps ({"color" : process_event_message .color }))
573+ else :
574+ print (f"{ 'on' if process_event_message .color else 'off' } " )
550575 case "print_snr" :
551576 if json_output :
552577 print (json .dumps ({"print_snr" : process_event_message .print_snr }))
@@ -1070,6 +1095,7 @@ async def main(argv):
10701095 port = int (arg )
10711096 case "-j" :
10721097 json_output = True
1098+ handle_message .json_output = True
10731099 case "-D" :
10741100 debug = True
10751101 case "-h" :
0 commit comments