Skip to content

Commit 803e339

Browse files
committed
prompt improvements regarding scope
1 parent c2f43bd commit 803e339

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "meshcore-cli"
7-
version = "1.2.6"
7+
version = "1.2.7"
88
authors = [
99
{ name="Florent de Lamotte", email="[email protected]" },
1010
]
@@ -17,7 +17,7 @@ classifiers = [
1717
]
1818
license = "MIT"
1919
license-files = ["LICEN[CS]E*"]
20-
dependencies = [ "meshcore >= 2.1.20", "prompt_toolkit >= 3.0.50", "requests >= 2.28.0", "pycryptodome" ]
20+
dependencies = [ "meshcore >= 2.1.21", "prompt_toolkit >= 3.0.50", "requests >= 2.28.0", "pycryptodome" ]
2121

2222
[project.urls]
2323
Homepage = "https://github.com/fdlamotte/meshcore-cli"

src/meshcore_cli/meshcore_cli.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ def make_completion_dict(contacts, pending={}, to=None, channels=None):
473473
"remove_channel": None,
474474
"apply_to": None,
475475
"at": None,
476+
"scope": None,
476477
"set" : {
477478
"name" : None,
478479
"pin" : None,
@@ -707,6 +708,14 @@ async def interactive_loop(mc, to=None) :
707708
contact = to
708709
prev_contact = None
709710

711+
res = await mc.commands.set_flood_scope("0")
712+
if res is None or res.type == EventType.ERROR:
713+
scope = None
714+
prev_scope = None
715+
else:
716+
scope = "*"
717+
prev_scope = "*"
718+
710719
await get_contacts(mc, anim=True)
711720
await get_channels(mc, anim=True)
712721
await subscribe_to_msgs(mc, above=True)
@@ -758,6 +767,9 @@ def _(event):
758767
if print_name or contact is None :
759768
prompt = prompt + f"{ANSI_BGRAY}"
760769
prompt = prompt + f"{mc.self_info['name']}"
770+
if contact is None: # display scope
771+
if not scope is None:
772+
prompt = prompt + f"|{scope}"
761773
if classic :
762774
prompt = prompt + " > "
763775
else :
@@ -785,6 +797,17 @@ def _(event):
785797
prompt = prompt + f"{ANSI_NORMAL}🭨{ANSI_INVERT}"
786798

787799
prompt = prompt + f"{contact['adv_name']}"
800+
if contact["type"] == 0 or contact["out_path_len"]==-1:
801+
if scope is None:
802+
prompt = prompt + f"|*"
803+
else:
804+
prompt = prompt + f"|{scope}"
805+
else: # display path to dest or 0 if 0 hop
806+
if contact["out_path_len"] == 0:
807+
prompt = prompt + f"|0"
808+
else:
809+
prompt = prompt + "|" + contact["out_path"]
810+
788811
if classic :
789812
prompt = prompt + f"{ANSI_NORMAL} > "
790813
else:
@@ -823,6 +846,12 @@ def _(event):
823846
except ValueError:
824847
logger.error("Error parsing line {line[1:]}")
825848

849+
elif line.startswith("/scope") :
850+
if not scope is None:
851+
prev_scope = scope
852+
newscope = line.split(" ", 1)[1]
853+
scope = await set_scope(mc, newscope)
854+
826855
elif line.startswith("/") :
827856
path = line.split(" ", 1)[0]
828857
if path.count("/") == 1:
@@ -1307,6 +1336,14 @@ async def msg_ack (mc, contact, msg) :
13071336
msg_ack.flood_after=2
13081337
msg_ack.max_flood_attempts=1
13091338

1339+
async def set_scope (mc, scope) :
1340+
if scope == "None" or scope == "0" or scope == "clear" or scope == "":
1341+
scope = "*"
1342+
res = await mc.commands.set_flood_scope(scope)
1343+
if res is None or res.type == EventType.ERROR:
1344+
return None
1345+
return scope
1346+
13101347
async def get_channel (mc, chan) :
13111348
if not chan.isnumeric():
13121349
return await get_channel_by_name(mc, chan)
@@ -2110,8 +2147,8 @@ async def next_cmd(mc, cmds, json_output=False):
21102147

21112148
case "scope":
21122149
argnum = 1
2113-
res = await mc.commands.set_flood_scope(cmds[1])
2114-
if res is None or res.type == EventType.ERROR:
2150+
res = await set_scope(mc, cmds[1])
2151+
if res is None:
21152152
print(f"Error while setting scope")
21162153

21172154
case "remove_channel":

0 commit comments

Comments
 (0)