prompt improvements regarding scope

This commit is contained in:
Florent de Lamotte 2025-11-06 13:21:54 +01:00
parent c2f43bde62
commit 803e339c58
2 changed files with 41 additions and 4 deletions

View file

@ -4,7 +4,7 @@ build-backend = "hatchling.build"
[project]
name = "meshcore-cli"
version = "1.2.6"
version = "1.2.7"
authors = [
{ name="Florent de Lamotte", email="florent@frizoncorrea.fr" },
]
@ -17,7 +17,7 @@ classifiers = [
]
license = "MIT"
license-files = ["LICEN[CS]E*"]
dependencies = [ "meshcore >= 2.1.20", "prompt_toolkit >= 3.0.50", "requests >= 2.28.0", "pycryptodome" ]
dependencies = [ "meshcore >= 2.1.21", "prompt_toolkit >= 3.0.50", "requests >= 2.28.0", "pycryptodome" ]
[project.urls]
Homepage = "https://github.com/fdlamotte/meshcore-cli"

View file

@ -473,6 +473,7 @@ def make_completion_dict(contacts, pending={}, to=None, channels=None):
"remove_channel": None,
"apply_to": None,
"at": None,
"scope": None,
"set" : {
"name" : None,
"pin" : None,
@ -707,6 +708,14 @@ Line starting with \"$\" or \".\" will issue a meshcli command.
contact = to
prev_contact = None
res = await mc.commands.set_flood_scope("0")
if res is None or res.type == EventType.ERROR:
scope = None
prev_scope = None
else:
scope = "*"
prev_scope = "*"
await get_contacts(mc, anim=True)
await get_channels(mc, anim=True)
await subscribe_to_msgs(mc, above=True)
@ -758,6 +767,9 @@ Line starting with \"$\" or \".\" will issue a meshcli command.
if print_name or contact is None :
prompt = prompt + f"{ANSI_BGRAY}"
prompt = prompt + f"{mc.self_info['name']}"
if contact is None: # display scope
if not scope is None:
prompt = prompt + f"|{scope}"
if classic :
prompt = prompt + " > "
else :
@ -785,6 +797,17 @@ Line starting with \"$\" or \".\" will issue a meshcli command.
prompt = prompt + f"{ANSI_NORMAL}🭨{ANSI_INVERT}"
prompt = prompt + f"{contact['adv_name']}"
if contact["type"] == 0 or contact["out_path_len"]==-1:
if scope is None:
prompt = prompt + f"|*"
else:
prompt = prompt + f"|{scope}"
else: # display path to dest or 0 if 0 hop
if contact["out_path_len"] == 0:
prompt = prompt + f"|0"
else:
prompt = prompt + "|" + contact["out_path"]
if classic :
prompt = prompt + f"{ANSI_NORMAL} > "
else:
@ -823,6 +846,12 @@ Line starting with \"$\" or \".\" will issue a meshcli command.
except ValueError:
logger.error("Error parsing line {line[1:]}")
elif line.startswith("/scope") :
if not scope is None:
prev_scope = scope
newscope = line.split(" ", 1)[1]
scope = await set_scope(mc, newscope)
elif line.startswith("/") :
path = line.split(" ", 1)[0]
if path.count("/") == 1:
@ -1307,6 +1336,14 @@ msg_ack.max_attempts=3
msg_ack.flood_after=2
msg_ack.max_flood_attempts=1
async def set_scope (mc, scope) :
if scope == "None" or scope == "0" or scope == "clear" or scope == "":
scope = "*"
res = await mc.commands.set_flood_scope(scope)
if res is None or res.type == EventType.ERROR:
return None
return scope
async def get_channel (mc, chan) :
if not chan.isnumeric():
return await get_channel_by_name(mc, chan)
@ -2110,8 +2147,8 @@ async def next_cmd(mc, cmds, json_output=False):
case "scope":
argnum = 1
res = await mc.commands.set_flood_scope(cmds[1])
if res is None or res.type == EventType.ERROR:
res = await set_scope(mc, cmds[1])
if res is None:
print(f"Error while setting scope")
case "remove_channel":