fix multi-line messages ...

This commit is contained in:
Florent 2025-04-17 17:25:35 +02:00
parent 4b737a9d85
commit 3497bc5a19

View file

@ -72,7 +72,6 @@ Line starting with \"$\" or \".\" will issue a meshcli command.
elif line.startswith(".") or\ elif line.startswith(".") or\
line.startswith("set ") or\ line.startswith("set ") or\
line.startswith("get ") or\ line.startswith("get ") or\
line.startswith("public") or\
line.startswith("clock") or\ line.startswith("clock") or\
line.startswith("time") or\ line.startswith("time") or\
line.startswith("ver") or\ line.startswith("ver") or\
@ -84,6 +83,10 @@ Line starting with \"$\" or \".\" will issue a meshcli command.
args = shlex.split(line) args = shlex.split(line)
await process_cmds(mc, args) await process_cmds(mc, args)
elif line.startswith("public "):
args = ["public", line[7:]]
await process_cmds(mc, args)
elif line.startswith("to ") : # dest elif line.startswith("to ") : # dest
dest = line[3:] dest = line[3:]
nc = mc.get_contact_by_name(dest) nc = mc.get_contact_by_name(dest)
@ -129,9 +132,7 @@ Line starting with \"$\" or \".\" will issue a meshcli command.
exp_ack = result.payload["expected_ack"].hex() exp_ack = result.payload["expected_ack"].hex()
res = await mc.wait_for_event(EventType.ACK, attribute_filters={"code": exp_ack}, timeout=5) res = await mc.wait_for_event(EventType.ACK, attribute_filters={"code": exp_ack}, timeout=5)
if res is None : if res is None :
print ("#", end="") print ("!", end="")
else :
print ("~", end="")
except KeyboardInterrupt: except KeyboardInterrupt:
mc.stop() mc.stop()
@ -141,11 +142,16 @@ Line starting with \"$\" or \".\" will issue a meshcli command.
print("Exiting cli") print("Exiting cli")
def print_above(str): def print_above(str):
width = os.get_terminal_size().columns
lines = divmod(len(str), width)[0] + 1
print("\u001B[s", end="") # Save current cursor position print("\u001B[s", end="") # Save current cursor position
print("\u001B[A", end="") # Move cursor up one line print("\u001B[A", end="") # Move cursor up one line
print("\u001B[999D", end="") # Move cursor to beginning of line print("\u001B[999D", end="") # Move cursor to beginning of line
print("\u001B[S", end="") # Scroll up/pan window down 1 line for _ in range(lines):
print("\u001B[L", end="") # Insert new line print("\u001B[S", end="") # Scroll up/pan window down 1 line
print("\u001B[L", end="") # Insert new line
for _ in range(lines - 1):
print("\u001B[A", end="") # Move cursor up one line
print(str, end="") # Print output status msg print(str, end="") # Print output status msg
print("\u001B[u", end="", flush=True) # Jump back to saved cursor position print("\u001B[u", end="", flush=True) # Jump back to saved cursor position
@ -173,7 +179,7 @@ async def process_event_message(mc, ev, json_output, end="\n", above=False):
else : else :
path_str = str(data['path_len']) path_str = str(data['path_len'])
if above: if above:
print_above(f"{name}({path_str}): {data['text']}") print_above(f" {name}({path_str}): {data['text']}")
else: else:
print(f"{name}({path_str}): {data['text']}") print(f"{name}({path_str}): {data['text']}")
elif (data['type'] == "CHAN") : elif (data['type'] == "CHAN") :
@ -182,7 +188,7 @@ async def process_event_message(mc, ev, json_output, end="\n", above=False):
else : else :
path_str = str(data['path_len']) path_str = str(data['path_len'])
if above: if above:
print_above(f"ch{data['channel_idx']}({path_str}): {data['text']}") print_above(f" ch{data['channel_idx']}({path_str}): {data['text']}")
else: else:
print(f"ch{data['channel_idx']}({path_str}): {data['text']}") print(f"ch{data['channel_idx']}({path_str}): {data['text']}")
else: else: