44"""
55
66import asyncio
7- import os , sys , io , platform
7+ import os , sys , io
88import time , datetime
99import getopt , json , shlex , re
1010import logging
3232from meshcore import MeshCore , EventType , logger
3333
3434# Version
35- VERSION = "v1.2.12 "
35+ VERSION = "v1.2.13 "
3636
3737# default ble address is stored in a config file
3838MCCLI_CONFIG_DIR = str (Path .home ()) + "/.config/meshcore/"
7676ANSI_BYELLOW = "\033 [1;33m"
7777
7878#Unicode chars
79- # some possible symbols for prompts 🭬🬛🬗🭬🬛🬃🬗🭬🬛🬃🬗🬏🭀🭋🭨🮋
80- ARROW_TAIL = "🭨"
81- ARROW_HEAD = "🭬"
82-
83- if platform .system () == 'Windows' or platform .system () == 'Darwin' :
84- ARROW_TAIL = ""
85- ARROW_HEAD = " "
79+ # some possible symbols for prompts 🭬🬛🬗🭬🬛🬃🬗🭬🬛🬃🬗🬏🭀🭋🭨🮋
80+ ARROW_HEAD = ""
81+ SLASH_END = ""
82+ SLASH_START = ""
83+ INVERT_SLASH = False
8684
8785def escape_ansi (line ):
8886 ansi_escape = re .compile (r'(?:\x1B[@-_]|[\x80-\x9F])[0-?]*[ -/]*[@-~]' )
@@ -470,7 +468,7 @@ def make_completion_dict(contacts, pending={}, to=None, channels=None):
470468 "login" : contact_list ,
471469 "cmd" : contact_list ,
472470 "req_status" : contact_list ,
473- "req_bstatus" : contact_list ,
471+ "req_neighbours" : contact_list ,
474472 "logout" : contact_list ,
475473 "req_telemetry" : contact_list ,
476474 "req_binary" : contact_list ,
@@ -495,7 +493,6 @@ def make_completion_dict(contacts, pending={}, to=None, channels=None):
495493 "print_snr" : {"on" :None , "off" : None },
496494 "json_msgs" : {"on" :None , "off" : None },
497495 "color" : {"on" :None , "off" :None },
498- "print_name" : {"on" :None , "off" :None },
499496 "print_adverts" : {"on" :None , "off" :None },
500497 "json_log_rx" : {"on" :None , "off" :None },
501498 "channel_echoes" : {"on" :None , "off" :None },
@@ -525,7 +522,6 @@ def make_completion_dict(contacts, pending={}, to=None, channels=None):
525522 "print_snr" :None ,
526523 "json_msgs" :None ,
527524 "color" :None ,
528- "print_name" :None ,
529525 "print_adverts" :None ,
530526 "json_log_rx" :None ,
531527 "channel_echoes" :None ,
@@ -577,7 +573,6 @@ def make_completion_dict(contacts, pending={}, to=None, channels=None):
577573 "login" : None ,
578574 "logout" : None ,
579575 "req_status" : None ,
580- "req_bstatus" : None ,
581576 "req_neighbours" : None ,
582577 "cmd" : None ,
583578 "ver" : None ,
@@ -765,26 +760,32 @@ def _(event):
765760
766761 color = process_event_message .color
767762 classic = interactive_loop .classic or not color
768- print_name = interactive_loop .print_name
769763
770764 if classic :
771765 prompt = ""
772766 else :
773767 prompt = f"{ ANSI_INVERT } "
774768
775- if print_name or contact is None :
776- if color :
777- prompt = prompt + f" { ANSI_BGRAY } "
778- prompt = prompt + f" { mc . self_info [ 'name' ] } "
779- if contact is None : # display scope
780- if not scope is None :
781- prompt = prompt + f"| { scope } "
769+ prompt = prompt + f" { ANSI_BGRAY } "
770+ prompt = prompt + f" { mc . self_info [ 'name' ] } "
771+ if contact is None : # display scope
772+ if not scope is None :
773+ prompt = prompt + f"| { scope } "
774+
775+ if contact is None :
782776 if classic :
783- prompt = prompt + "> "
777+ prompt = prompt + ">"
784778 else :
785- prompt = prompt + f"{ ANSI_NORMAL } { ARROW_HEAD } { ANSI_INVERT } "
786-
787- if not contact is None :
779+ prompt = prompt + f"{ ANSI_NORMAL } { ARROW_HEAD } "
780+ else :
781+ if classic :
782+ prompt = prompt + "/"
783+ else :
784+ if INVERT_SLASH :
785+ prompt = prompt + f"{ ANSI_INVERT } "
786+ else :
787+ prompt = prompt + f"{ ANSI_NORMAL } "
788+ prompt = prompt + f"{ SLASH_START } "
788789 if not last_ack :
789790 prompt = prompt + f"{ ANSI_BRED } "
790791 if classic :
@@ -800,11 +801,9 @@ def _(event):
800801 else :
801802 prompt = prompt + f"{ ANSI_BBLUE } "
802803 if not classic :
804+ prompt = prompt + f"{ SLASH_END } "
803805 prompt = prompt + f"{ ANSI_INVERT } "
804806
805- if print_name and not classic :
806- prompt = prompt + f"{ ANSI_NORMAL } { ARROW_TAIL } { ANSI_INVERT } "
807-
808807 prompt = prompt + f"{ contact ['adv_name' ]} "
809808 if contact ["type" ] == 0 or contact ["out_path_len" ]== - 1 :
810809 if scope is None :
@@ -818,14 +817,15 @@ def _(event):
818817 prompt = prompt + "|" + contact ["out_path" ]
819818
820819 if classic :
821- prompt = prompt + f"{ ANSI_NORMAL } > "
820+ prompt = prompt + f"{ ANSI_NORMAL } >"
822821 else :
823822 prompt = prompt + f"{ ANSI_NORMAL } { ARROW_HEAD } "
824823
825824 prompt = prompt + f"{ ANSI_END } "
826825
827- if not color :
828- prompt = escape_ansi (prompt )
826+ prompt = prompt + " "
827+ if not color :
828+ prompt = escape_ansi (prompt )
829829
830830 session .app .ttimeoutlen = 0.2
831831 session .app .timeoutlen = 0.2
@@ -1037,7 +1037,6 @@ def _(event):
10371037 # Handle task cancellation from KeyboardInterrupt in asyncio.run()
10381038 print ("Exiting cli" )
10391039interactive_loop .classic = False
1040- interactive_loop .print_name = True
10411040
10421041async def process_contact_chat_line (mc , contact , line ):
10431042 if contact ["type" ] == 0 :
@@ -1085,7 +1084,6 @@ async def process_contact_chat_line(mc, contact, line):
10851084 line == "contact_info" or line == "ci" or \
10861085 line == "req_status" or line == "rs" or \
10871086 line == "req_neighbours" or line == "rn" or \
1088- line == "req_bstatus" or line == "rbs" or \
10891087 line == "req_telemetry" or line == "rt" or \
10901088 line == "req_acl" or \
10911089 line == "path" or \
@@ -1615,7 +1613,7 @@ async def print_disc_trace_to (mc, contact):
16151613
16161614async def next_cmd (mc , cmds , json_output = False ):
16171615 """ process next command """
1618- global ARROW_TAIL , ARROW_HEAD
1616+ global ARROW_HEAD , SLASH_START , SLASH_END , INVERT_SLASH
16191617 try :
16201618 argnum = 0
16211619
@@ -1741,18 +1739,18 @@ async def next_cmd(mc, cmds, json_output=False):
17411739 msg_ack .max_attempts = int (cmds [2 ])
17421740 case "flood_after" :
17431741 msg_ack .flood_after = int (cmds [2 ])
1744- case "print_name" :
1745- interactive_loop .print_name = (cmds [2 ] == "on" )
1746- if json_output :
1747- print (json .dumps ({"cmd" : cmds [1 ], "param" : cmds [2 ]}))
17481742 case "classic_prompt" :
17491743 interactive_loop .classic = (cmds [2 ] == "on" )
17501744 if json_output :
17511745 print (json .dumps ({"cmd" : cmds [1 ], "param" : cmds [2 ]}))
1752- case "arrow_tail" :
1753- ARROW_TAIL = cmds [2 ]
17541746 case "arrow_head" :
17551747 ARROW_HEAD = cmds [2 ]
1748+ case "slash_start" :
1749+ SLASH_START = cmds [2 ]
1750+ case "slash_end" :
1751+ SLASH_END = cmds [2 ]
1752+ case "invert_slash" :
1753+ INVERT_SLASH = cmds [2 ] == "on"
17561754 case "color" :
17571755 process_event_message .color = (cmds [2 ] == "on" )
17581756 if json_output :
@@ -1983,11 +1981,6 @@ async def next_cmd(mc, cmds, json_output=False):
19831981 print (json .dumps ({"flood_after" : msg_ack .flood_after }))
19841982 else :
19851983 print (f"flood_after: { msg_ack .flood_after } " )
1986- case "print_name" :
1987- if json_output :
1988- print (json .dumps ({"print_name" : interactive_loop .print_name }))
1989- else :
1990- print (f"{ 'on' if interactive_loop .print_name else 'off' } " )
19911984 case "classic_prompt" :
19921985 if json_output :
19931986 print (json .dumps ({"classic_prompt" : interactive_loop .classic }))
@@ -2362,7 +2355,7 @@ async def next_cmd(mc, cmds, json_output=False):
23622355 if classic :
23632356 print ("→" ,end = "" )
23642357 else :
2365- print (f"{ ANSI_NORMAL } { ARROW_HEAD } " ,end = "" )
2358+ print (f"{ ANSI_NORMAL } { ARROW_HEAD } " ,end = "" )
23662359 if color :
23672360 print (ANSI_END , end = "" )
23682361 if "hash" in t :
@@ -2428,46 +2421,6 @@ async def next_cmd(mc, cmds, json_output=False):
24282421 contact = mc .get_contact_by_name (cmds [1 ])
24292422 contact ["timeout" ] = float (cmds [2 ])
24302423
2431- case "req_status" | "rs" :
2432- argnum = 1
2433- await mc .ensure_contacts ()
2434- contact = mc .get_contact_by_name (cmds [1 ])
2435- res = await mc .commands .send_statusreq (contact )
2436- logger .debug (res )
2437- if res .type == EventType .ERROR :
2438- print (f"Error while requesting status: { res } " )
2439- else :
2440- timeout = res .payload ["suggested_timeout" ]/ 800 if not "timeout" in contact or contact ['timeout' ]== 0 else contact ["timeout" ]
2441- res = await mc .wait_for_event (EventType .STATUS_RESPONSE , timeout = timeout )
2442- logger .debug (res )
2443- if res is None :
2444- if json_output :
2445- print (json .dumps ({"error" : "Timeout waiting status" }))
2446- else :
2447- print ("Timeout waiting status" )
2448- else :
2449- print (json .dumps (res .payload , indent = 4 ))
2450-
2451- case "req_telemetry" | "rt" :
2452- argnum = 1
2453- await mc .ensure_contacts ()
2454- contact = mc .get_contact_by_name (cmds [1 ])
2455- res = await mc .commands .send_telemetry_req (contact )
2456- logger .debug (res )
2457- if res .type == EventType .ERROR :
2458- print (f"Error while requesting telemetry" )
2459- else :
2460- timeout = res .payload ["suggested_timeout" ]/ 800 if not "timeout" in contact or contact ['timeout' ]== 0 else contact ["timeout" ]
2461- res = await mc .wait_for_event (EventType .TELEMETRY_RESPONSE , timeout = timeout )
2462- logger .debug (res )
2463- if res is None :
2464- if json_output :
2465- print (json .dumps ({"error" : "Timeout waiting telemetry" }))
2466- else :
2467- print ("Timeout waiting telemetry" )
2468- else :
2469- print (json .dumps (res .payload , indent = 4 ))
2470-
24712424 case "disc_path" | "dp" :
24722425 argnum = 1
24732426 await mc .ensure_contacts ()
@@ -2553,7 +2506,7 @@ async def next_cmd(mc, cmds, json_output=False):
25532506
25542507 print (f" { name :16} { type :>4} SNR: { n ['SNR_in' ]:6,.2f} ->{ n ['SNR' ]:6,.2f} RSSI: ->{ n ['RSSI' ]:4} " )
25552508
2556- case "req_btelemetry " | "rbt " :
2509+ case "req_telemetry " | "rt " :
25572510 argnum = 1
25582511 await mc .ensure_contacts ()
25592512 contact = mc .get_contact_by_name (cmds [1 ])
@@ -2565,9 +2518,13 @@ async def next_cmd(mc, cmds, json_output=False):
25652518 else :
25662519 print ("Error getting data" )
25672520 else :
2568- print (json .dumps (res ))
2521+ print (json .dumps ({
2522+ "name" : contact ["adv_name" ],
2523+ "pubkey_pre" : contact ["public_key" ][0 :12 ],
2524+ "lpp" : res ,
2525+ }, indent = 4 ))
25692526
2570- case "req_bstatus " | "rbs " :
2527+ case "req_status " | "rs " :
25712528 argnum = 1
25722529 await mc .ensure_contacts ()
25732530 contact = mc .get_contact_by_name (cmds [1 ])
0 commit comments