@@ -81,7 +81,7 @@ async def process_event_message(mc, ev, json_output, end="\n", above=False):
8181 else :
8282 path_str = str (data ['path_len' ])
8383
84- disp = f" { ANSI_GREEN } { name } "
84+ disp = f"{ ANSI_GREEN } { name } "
8585 if 'signature' in data :
8686 sender = mc .get_contact_by_key_prefix (data ['signature' ])
8787 disp = disp + f"/{ sender ['adv_name' ]} "
@@ -99,7 +99,7 @@ async def process_event_message(mc, ev, json_output, end="\n", above=False):
9999 path_str = f"{ ANSI_YELLOW } ({ data ['path_len' ]} ){ ANSI_END } "
100100
101101 if above :
102- print_above (f" { ANSI_GREEN } ch{ data ['channel_idx' ]} ({ path_str } ): { data ['text' ]} " )
102+ print_above (f"{ ANSI_GREEN } ch{ data ['channel_idx' ]} ({ path_str } ): { data ['text' ]} " )
103103 else :
104104 print (f"ch{ data ['channel_idx' ]} ({ path_str } ): { data ['text' ]} " )
105105 else :
@@ -108,7 +108,12 @@ async def process_event_message(mc, ev, json_output, end="\n", above=False):
108108
109109async def handle_message (event ):
110110 """ Process incoming message events """
111- await process_event_message (MC , event , False , above = True )
111+ await process_event_message (handle_message .mc , event ,
112+ above = handle_message .above , json_output = handle_message .json_output )
113+ handle_message .json_output = False
114+ handle_message .mc = None
115+ handle_message .above = True
116+
112117
113118def make_completion_dict (contacts ):
114119 contact_list = {}
@@ -935,7 +940,7 @@ async def process_cmds (mc, args, json_output=False) :
935940 while cmds and len (cmds ) > 0 :
936941 if not first and json_output :
937942 print ("," )
938- cmds = await next_cmd (MC , cmds , json_output )
943+ cmds = await next_cmd (mc , cmds , json_output )
939944 first = False
940945 if json_output :
941946 print ("]" )
@@ -1003,7 +1008,6 @@ def usage () :
10031008
10041009async def main (argv ):
10051010 """ Do the job """
1006- global MC
10071011 json_output = JSON
10081012 debug = False
10091013 address = ADDRESS
@@ -1065,10 +1069,11 @@ async def main(argv):
10651069 with open (MCCLI_ADDRESS , "w" , encoding = "utf-8" ) as f :
10661070 f .write (address )
10671071
1068- MC = MeshCore (con , debug = debug )
1069- await MC .connect ()
1072+ mc = MeshCore (con , debug = debug )
1073+ await mc .connect ()
1074+ handle_message .mc = mc # connect meshcore to handle_message
10701075
1071- res = await MC .commands .send_device_query ()
1076+ res = await mc .commands .send_device_query ()
10721077 if res .type == EventType .ERROR :
10731078 logger .error (f"Error while querying device: { res } " )
10741079 return
@@ -1077,14 +1082,14 @@ async def main(argv):
10771082 logger .setLevel (logging .ERROR )
10781083 else :
10791084 if res .payload ["fw ver" ] > 2 :
1080- logger .info (f"Connected to { MC .self_info ['name' ]} running on a { res .payload ['ver' ]} fw." )
1085+ logger .info (f"Connected to { mc .self_info ['name' ]} running on a { res .payload ['ver' ]} fw." )
10811086 else :
1082- logger .info (f"Connected to { MC .self_info ['name' ]} ." )
1087+ logger .info (f"Connected to { mc .self_info ['name' ]} ." )
10831088
10841089 if len (args ) == 0 : # no args, run in chat mode
1085- await process_cmds (MC , ["chat" ], json_output )
1090+ await process_cmds (mc , ["chat" ], json_output )
10861091 else :
1087- await process_cmds (MC , args , json_output )
1092+ await process_cmds (mc , args , json_output )
10881093
10891094def cli ():
10901095 try :
0 commit comments